Class: AtreaControl::Duplex::UserCtrl

Inherits:
Object
  • Object
show all
Defined in:
lib/atrea_control/duplex/user_ctrl.rb

Overview

Parse ‘userCtrl.xml`

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id:, unit_id:, sid:) ⇒ UserCtrl

Returns a new instance of UserCtrl.

Parameters:

  • user_id (String, Integer)
  • unit_id (String, Integer)
  • sid (String, Integer)


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

def initialize(user_id:, unit_id:, sid:)
  @user_id = user_id
  @unit_id = unit_id
  @sid = sid
end

Class Method Details

.data(user_id:, unit_id:, sid:) ⇒ Object

Parameters:

  • user_id (String, Integer)
  • unit_id (String, Integer)
  • sid (String, Integer)


10
11
12
13
14
15
16
17
18
# File 'lib/atrea_control/duplex/user_ctrl.rb', line 10

def self.data(user_id:, unit_id:, sid:)
  user_ctrl = new(user_id: user_id, unit_id: unit_id, sid: sid)
  {
    name: user_ctrl.name,
    sensors: user_ctrl.sensors,
    modes: user_ctrl.modes,
    user_modes: user_ctrl.user_modes,
  }
end

Instance Method Details

#modesHash

Generic modes

Returns:

  • (Hash)


78
79
80
81
82
83
84
85
86
87
# File 'lib/atrea_control/duplex/user_ctrl.rb', line 78

def modes
  return @modes if @modes

  @modes = {}
  user_ctrl.xpath("//op[@id='Mode']/i").each do |mode|
    m = translate_mode(mode)
    @modes[m[:id]] = m[:value]
  end
  @modes
end

#nameString

User-defined name of home (RD5 unit)

Returns:

  • (String)


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

def name
  @name ||= user_texts["UnitName"]
end

#requestObject

Request to RD5



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

def request
  @request ||= Request.new(user_id: @user_id, unit_id: @unit_id, sid: @sid)
end

#sensorsObject

Gather ID of sensors based on userCtrl config file



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/atrea_control/duplex/user_ctrl.rb', line 47

def sensors
  return @sensors if @sensors

  power = user_ctrl.xpath("//body/content/i[@title='$currentPower']")
  mode = user_ctrl.xpath("//body/content/i[@title='$currentMode']")
  outdoor_temp = user_ctrl.xpath("//body/content/i[@title='$outdoorTemp']")

  switch_mode = mode.xpath("displayval").text[/values\.(\w+)/, 1]

  power_input = power.xpath("onchange").text[/getUrlPar\('(\w+)',val\)/, 1]
  m = mode.xpath("onchange").text.match(/getUrlPar\('(\w+)',val\).*getUrlPar\(.(\w+).,2\)/)

  preheat_temperature = user_ctrl.xpath("//body/content/i[@title='$requiredTemp']")

  input_temp = user_ctrl.xpath("//body/content/i[@title='$inletTemp']") # "I10200"
  input_temperature = input_temp.xpath("displayval").text[/val=values\.(\w\d+);/, 1]
  @sensors = {
    "outdoor_temperature" => outdoor_temp.attribute("id").value, # "I10208"
    "preheat_temperature" => preheat_temperature.attribute("id").value, # "H10706"
    "input_temperature" => input_temperature,
    "current_power" => power.attribute("id").value, # "H10704"
    "current_mode" => mode.attribute("id").value, # "H10705"
    "current_mode_switch" => switch_mode, # "H10712"
    "power_input" => power_input, # "H10708"
    "mode_input" => m[1], # "H10709"
    "mode_switch" => m[2], # "H10701"
  }
end

#user_ctrlObject

Get and parse XML with user/unit configuration source



35
36
37
38
# File 'lib/atrea_control/duplex/user_ctrl.rb', line 35

def user_ctrl
  response = request.call(_t: "lang/userCtrl.xml")
  Nokogiri::XML response.body
end

#user_modesHash

Modes by inputs - switches - named by user custom texts

Returns:

  • (Hash)


91
92
93
94
95
96
97
98
99
100
# File 'lib/atrea_control/duplex/user_ctrl.rb', line 91

def user_modes
  return @user_modes if @user_modes

  @user_modes = {}
  user_ctrl.xpath("//op[@id='ModeText']/i").each do |mode|
    m = translate_mode(mode)
    @user_modes[m[:id]] = m[:value]
  end
  @user_modes
end