Module: Legion::Extensions::Esphome::Runners::Sensors
- Includes:
- Helpers::Lex
- Defined in:
- lib/legion/extensions/esphome/runners/sensors.rb
Class Method Summary collapse
-
.process(value:, **payload) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity.
Class Method Details
.process(value:, **payload) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/esphome/runners/sensors.rb', line 6 def self.process(value:, **payload) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity items = payload[:routing_key].split('.') subtype = if items[2].include?('fan') 'fan' elsif items[2].include?('voltage') 'voltage' elsif items[2].include?('temp') 'temperature' elsif items[2].include?('humidity') 'humidity' elsif items[2].include?('wifi_signal') 'wifi_signal' elsif items[2].include?('uptime') 'uptime' elsif items[2].include?('pressure') 'pressure' elsif items[2].include?('pulse') 'pulse' elsif items[2].include?('meter') 'meter' elsif items[2].include?('brightness') 'brightness' elsif items[2].include?('illuminance') || items[2].include?('lx') || items[2].include?('bright') 'illuminance' elsif items[2].include?('current') 'current' end if subtype.nil? log.warn("Subtype was not found for esphome item subtype: #{items[2]}") subtype = items[2] elsif subtype == 'temperature' value = ((value.to_i * 9 / 5) + 32).round(3) if settings[:convert_c_to_f] end { value: value, name: items[0], type: items[2], sub_type: subtype, item: items[3], timestamp_in_ms: payload[:timestamp_in_ms] } end |