Class: AtreaControl::Duplex::Unit

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/atrea_control/duplex/unit.rb

Overview

Communication with RD5 unit (read/write)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initialize(user_id:, unit_id:, sid:, user_ctrl: nil) ⇒ Unit

Returns a new instance of Unit.

Parameters:



23
24
25
26
27
28
# File 'lib/atrea_control/duplex/unit.rb', line 23

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_modeObject (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_powerObject (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_temperatureObject (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_temperatureObject (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_temperatureObject (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

#preheatingBoolean (readonly)

Returns preheating air is ON ?.

Returns:

  • (Boolean)

    preheating air is ON ?



11
12
13
# File 'lib/atrea_control/duplex/unit.rb', line 11

def preheating
  @preheating
end

#timestampObject



42
43
44
# File 'lib/atrea_control/duplex/unit.rb', line 42

def timestamp
  @timestamp ||= values[:timestamp]
end

#user_ctrlUserCtrl (readonly)

Returns:



15
16
17
# File 'lib/atrea_control/duplex/unit.rb', line 15

def user_ctrl
  @user_ctrl
end

#valid_forDateTime (readonly)

Returns store time of last update.

Returns:

  • (DateTime)

    store time of last update



13
14
15
# File 'lib/atrea_control/duplex/unit.rb', line 13

def valid_for
  @valid_for
end

Instance Method Details

#as_json(_options = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/atrea_control/duplex/unit.rb', line 75

def as_json(_options = nil)
  {
    current_mode: current_mode,
    current_power: current_power,
    outdoor_temperature: outdoor_temperature,
    preheat_temperature: preheat_temperature,
    input_temperature: input_temperature,
    preheating: preheating,
    valid_for: valid_for,
    timestamp: timestamp,
  }
end

#modeObject



34
35
36
# File 'lib/atrea_control/duplex/unit.rb', line 34

def mode
  current_mode || values[:current_mode]
end

#mode=(value) ⇒ Object

Parameters:

  • value (String)

    0 - power-off; 1 - automat



51
52
53
54
55
# File 'lib/atrea_control/duplex/unit.rb', line 51

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

#nameObject



30
31
32
# File 'lib/atrea_control/duplex/unit.rb', line 30

def name
  @user_ctrl.name
end

#paramsObject

Note:

its changed in time ?

Additional “parameters” for each sensors



94
95
96
97
# File 'lib/atrea_control/duplex/unit.rb', line 94

def params
  response = request.call(_t: "user/params.xml")
  Nokogiri::XML response.body
end

#parsedObject



64
65
66
# File 'lib/atrea_control/duplex/unit.rb', line 64

def parsed
  @parsed ||= parser.values(read.body)
end

#powerObject



38
39
40
# File 'lib/atrea_control/duplex/unit.rb', line 38

def power
  current_power || values[:current_power]
end

#power=(value) ⇒ Object



57
58
59
60
61
62
# File 'lib/atrea_control/duplex/unit.rb', line 57

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

Returns:

  • (Boolean)


46
47
48
# File 'lib/atrea_control/duplex/unit.rb', line 46

def preheating?
  preheating || values[:preheating]
end

#to_jsonObject



88
89
90
# File 'lib/atrea_control/duplex/unit.rb', line 88

def to_json(*)
  values.to_json(*)
end

#valuesObject



68
69
70
71
72
73
# File 'lib/atrea_control/duplex/unit.rb', line 68

def values
  parsed.each do |name, value|
    instance_variable_set :"@#{name}", value
  end
  as_json
end