Class: AtreaControl::SensorParser
- Inherits:
-
Object
- Object
- AtreaControl::SensorParser
- Includes:
- Logger
- Defined in:
- lib/atrea_control/sensor_parser.rb
Overview
Call RD5 unit ang get current sensors values
parse it and return Hash
Instance Method Summary collapse
- #format_data(values) ⇒ Hash
-
#initialize(user_ctrl) ⇒ SensorParser
constructor
A new instance of SensorParser.
- #input(sensor, value) ⇒ Object
- #parse(xml) ⇒ Object
- #values(xml) ⇒ Object
Methods included from Logger
Constructor Details
#initialize(user_ctrl) ⇒ SensorParser
Returns a new instance of SensorParser.
12 13 14 |
# File 'lib/atrea_control/sensor_parser.rb', line 12 def initialize(user_ctrl) @user_ctrl = user_ctrl end |
Instance Method Details
#format_data(values) ⇒ Hash
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/atrea_control/sensor_parser.rb', line 53 def format_data(values) { "current_mode" => parse_current_mode(values), "current_power" => values["current_power"].to_f, "outdoor_temperature" => values["outdoor_temperature"].to_f / 10.0, "preheat_temperature" => values["preheat_temperature"].to_f / 10.0, "input_temperature" => values["input_temperature"].to_f / 10.0, "preheating" => values["preheating"], "timestamp" => DateTime.parse(values["timestamp"]), "valid_for" => Time.now, } end |
#input(sensor, value) ⇒ Object
20 21 22 |
# File 'lib/atrea_control/sensor_parser.rb', line 20 def input(sensor, value) sensor + value.to_s.rjust(5, "0") end |
#parse(xml) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/atrea_control/sensor_parser.rb', line 31 def parse(xml) xml = Nokogiri::XML xml parsed = @user_ctrl.sensors.transform_values do |id| # node = xml.xpath("//O[@I=\"#{id}\"]/@V").last node = xml.xpath("//O[@I=\"#{id}\"]").last # logger.debug node.to_s value = node.attribute("V").value.to_i value -= 65_536 if value > 32_767 # value -= 0 if "offset" # value = value / coef if "coef" value end preheating = %w[C10200 C10202 C10215 C10217].any? do |i| xml.xpath("//O[@I=\"#{i}\"]/@V").last&.value == "1" end parsed["timestamp"] = xml.xpath("//RD5WEB").attribute("t").to_s parsed["preheating"] = preheating parsed end |
#values(xml) ⇒ Object
16 17 18 |
# File 'lib/atrea_control/sensor_parser.rb', line 16 def values(xml) format_data(parse(xml)) end |