Class: AtreaControl::Duplex::Unit
- Inherits:
-
Object
- Object
- AtreaControl::Duplex::Unit
- Includes:
- Logger
- Defined in:
- lib/atrea_control/duplex/unit.rb
Overview
Communication with RD5 unit (read/write)
Instance Attribute Summary collapse
-
#current_mode ⇒ Object
readonly
Returns the value of attribute current_mode.
-
#current_power ⇒ Object
readonly
Returns the value of attribute current_power.
-
#input_temperature ⇒ Object
readonly
Returns the value of attribute input_temperature.
-
#outdoor_temperature ⇒ Object
readonly
Returns the value of attribute outdoor_temperature.
-
#preheat_temperature ⇒ Object
readonly
Returns the value of attribute preheat_temperature.
-
#preheating ⇒ Boolean
readonly
Preheating air is ON ?.
- #timestamp ⇒ Object
- #user_ctrl ⇒ UserCtrl readonly
Instance Method Summary collapse
- #as_json(_options = nil) ⇒ Object
-
#initialize(user_id:, unit_id:, sid:, user_ctrl: nil) ⇒ Unit
constructor
A new instance of Unit.
- #mode ⇒ Object
- #mode=(value) ⇒ Object
- #name ⇒ Object
- #parsed ⇒ Object
- #power ⇒ Object
- #power=(value) ⇒ Object
- #preheating? ⇒ Boolean
-
#refresh! ⇒ Hash
Expire cached data and fetch them again.
- #to_json ⇒ Object
-
#valid? ⇒ Boolean
Data are valid if timestamp within 15.minutes.
- #values ⇒ Object
Methods included from Logger
Constructor Details
#initialize(user_id:, unit_id:, sid:, user_ctrl: nil) ⇒ Unit
Returns a new instance of Unit.
21 22 23 24 25 26 |
# File 'lib/atrea_control/duplex/unit.rb', line 21 def initialize(user_id:, unit_id:, sid:, user_ctrl: nil) @user_id = user_id @unit_id = unit_id @sid = sid @user_ctrl = user_ctrl || UserCtrl.new(user_id: user_id, unit_id: unit_id, sid: sid) end |
Instance Attribute Details
#current_mode ⇒ Object (readonly)
Returns the value of attribute current_mode.
9 10 11 |
# File 'lib/atrea_control/duplex/unit.rb', line 9 def current_mode @current_mode end |
#current_power ⇒ Object (readonly)
Returns the value of attribute current_power.
9 10 11 |
# File 'lib/atrea_control/duplex/unit.rb', line 9 def current_power @current_power end |
#input_temperature ⇒ Object (readonly)
Returns the value of attribute input_temperature.
9 10 11 |
# File 'lib/atrea_control/duplex/unit.rb', line 9 def input_temperature @input_temperature end |
#outdoor_temperature ⇒ Object (readonly)
Returns the value of attribute outdoor_temperature.
9 10 11 |
# File 'lib/atrea_control/duplex/unit.rb', line 9 def outdoor_temperature @outdoor_temperature end |
#preheat_temperature ⇒ Object (readonly)
Returns the value of attribute preheat_temperature.
9 10 11 |
# File 'lib/atrea_control/duplex/unit.rb', line 9 def preheat_temperature @preheat_temperature end |
#preheating ⇒ Boolean (readonly)
Returns preheating air is ON ?.
11 12 13 |
# File 'lib/atrea_control/duplex/unit.rb', line 11 def preheating @preheating end |
#timestamp ⇒ Object
40 41 42 |
# File 'lib/atrea_control/duplex/unit.rb', line 40 def @timestamp ||= values[:timestamp] end |
#user_ctrl ⇒ UserCtrl (readonly)
13 14 15 |
# File 'lib/atrea_control/duplex/unit.rb', line 13 def user_ctrl @user_ctrl end |
Instance Method Details
#as_json(_options = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/atrea_control/duplex/unit.rb', line 75 def as_json( = nil) { current_mode: current_mode, current_power: current_power, outdoor_temperature: outdoor_temperature, preheat_temperature: preheat_temperature, input_temperature: input_temperature, preheating: preheating, timestamp: , } end |
#mode ⇒ Object
32 33 34 |
# File 'lib/atrea_control/duplex/unit.rb', line 32 def mode current_mode || values[:current_mode] end |
#mode=(value) ⇒ Object
49 50 51 52 53 |
# File 'lib/atrea_control/duplex/unit.rb', line 49 def mode=(value) v = [parser.input(@user_ctrl.sensors["mode_input"], value.to_s)] v << parser.input(@user_ctrl.sensors["mode_switch"], "2") write(*v) end |
#name ⇒ Object
28 29 30 |
# File 'lib/atrea_control/duplex/unit.rb', line 28 def name @user_ctrl.name end |
#parsed ⇒ Object
62 63 64 |
# File 'lib/atrea_control/duplex/unit.rb', line 62 def parsed @parsed ||= parser.values(read.body) end |
#power ⇒ Object
36 37 38 |
# File 'lib/atrea_control/duplex/unit.rb', line 36 def power current_power || values[:current_power] end |
#power=(value) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/atrea_control/duplex/unit.rb', line 55 def power=(value) v = [parser.input(@user_ctrl.sensors["power_input"], value.to_s)] # overtake schedule control v << "H1070000002" if value.to_i.positive? write(*v) end |
#preheating? ⇒ Boolean
44 45 46 |
# File 'lib/atrea_control/duplex/unit.rb', line 44 def preheating? preheating || values[:preheating] end |
#refresh! ⇒ Hash
Expire cached data and fetch them again
93 94 95 96 |
# File 'lib/atrea_control/duplex/unit.rb', line 93 def refresh! remove_instance_variable(:@parsed) if defined?(@parsed) values end |
#to_json ⇒ Object
87 88 89 |
# File 'lib/atrea_control/duplex/unit.rb', line 87 def to_json(*) values.to_json(*) end |
#valid? ⇒ Boolean
Data are valid if timestamp within 15.minutes
99 100 101 102 103 |
# File 'lib/atrea_control/duplex/unit.rb', line 99 def valid? return false unless > (Time.now - (15 * 60.0)) end |
#values ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/atrea_control/duplex/unit.rb', line 66 def values parsed.each do |name, value| instance_variable_set :"@#{name}", value end raise AtreaControl::SessionExpired unless valid? as_json end |