Class: HTCC::Thermostat
- Inherits:
-
Object
- Object
- HTCC::Thermostat
- Defined in:
- lib/htcc/thermostat.rb
Defined Under Namespace
Classes: FanError, HoldError, SystemError, TemperatureError
Constant Summary collapse
- SYSTEM_MODES =
i[emergency_heat heat off cool auto].freeze
- FAN_MODES =
i[auto on circulate schedule].freeze
- HOLD_TYPES =
i[none temporary permanent].freeze
- EQUIPMENT_OUTPUT_STATUS =
i[off heating cooling fan_running].freeze
- HOLD_TIMES =
[ '00:00', '00:15', '00:30', '00:45', '01:00', '01:15', '01:30', '01:45', '02:00', '02:15', '02:30', '02:45', '03:00', '03:15', '03:30', '03:45', '04:00', '04:15', '04:30', '04:45', '05:00', '05:15', '05:30', '05:45', '06:00', '06:15', '06:30', '06:45', '07:00', '07:15', '07:30', '07:45', '08:00', '08:15', '08:30', '08:45', '09:00', '09:15', '09:30', '09:45', '10:00', '10:15', '10:30', '10:45', '11:00', '11:15', '11:30', '11:45', '12:00', '12:15', '12:30', '12:45', '13:00', '13:15', '13:30', '13:45', '14:00', '14:15', '14:30', '14:45', '15:00', '15:15', '15:30', '15:45', '16:00', '16:15', '16:30', '16:45', '17:00', '17:15', '17:30', '17:45', '18:00', '18:15', '18:30', '18:45', '19:00', '19:15', '19:30', '19:45', '20:00', '20:15', '20:30', '20:45', '21:00', '21:15', '21:30', '21:45', '22:00', '22:15', '22:30', '22:45', '23:00', '23:15', '23:30', '23:45' ].freeze
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
Instance Method Summary collapse
- #connected? ⇒ Boolean
-
#cool_setpoint ⇒ Object
Cooling temperature setting.
- #cool_setpoint=(temp) ⇒ Object
- #cool_setpoint_range ⇒ Object
-
#current_temperature ⇒ Object
Current ambient temperature.
- #fan_mode ⇒ Object
- #fan_mode=(mode) ⇒ Object
- #fan_modes ⇒ Object
- #fan_running? ⇒ Boolean
- #has_fan? ⇒ Boolean
-
#heat_setpoint ⇒ Object
Heating temperature setting.
- #heat_setpoint=(temp) ⇒ Object
- #heat_setpoint_range ⇒ Object
- #hold ⇒ Object
- #hold=(mode) ⇒ Object
- #hold_until ⇒ Object
- #hold_until=(time) ⇒ Object
- #id ⇒ Object
-
#initialize(info, client) ⇒ Thermostat
constructor
A new instance of Thermostat.
- #mac_address ⇒ Object
- #name ⇒ Object
- #no_refresh(&block) ⇒ Object
- #output_status ⇒ Object
- #resume_schedule ⇒ Object
- #Scheduler ⇒ Object
- #Settings ⇒ Object
- #status(refresh = false) ⇒ Object
- #system_mode ⇒ Object
- #system_mode=(mode) ⇒ Object
- #system_modes ⇒ Object
- #temperature_unit ⇒ Object
Constructor Details
#initialize(info, client) ⇒ Thermostat
Returns a new instance of Thermostat.
38 39 40 41 42 43 |
# File 'lib/htcc/thermostat.rb', line 38 def initialize(info, client) @info = info @client = client @refresh = true @status = {} end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
36 37 38 |
# File 'lib/htcc/thermostat.rb', line 36 def info @info end |
Instance Method Details
#connected? ⇒ Boolean
65 66 67 68 |
# File 'lib/htcc/thermostat.rb', line 65 def connected? get_status @status['deviceLive'] && !@status['communicationLost'] end |
#cool_setpoint ⇒ Object
Cooling temperature setting
123 124 125 126 |
# File 'lib/htcc/thermostat.rb', line 123 def cool_setpoint get_status @status['latestData']['uiData']['CoolSetpoint'] end |
#cool_setpoint=(temp) ⇒ Object
128 129 130 131 132 |
# File 'lib/htcc/thermostat.rb', line 128 def cool_setpoint=(temp) raise_min_setpoint(min_cool_setpoint, temp) if temp < min_cool_setpoint raise_max_setpoint(max_cool_setpoint, temp) if temp > max_cool_setpoint change_setting(cool_setpoint: temp, hold: :temporary) end |
#cool_setpoint_range ⇒ Object
134 135 136 |
# File 'lib/htcc/thermostat.rb', line 134 def cool_setpoint_range (min_cool_setpoint..max_cool_setpoint) end |
#current_temperature ⇒ Object
Current ambient temperature
112 113 114 115 |
# File 'lib/htcc/thermostat.rb', line 112 def current_temperature get_status @status['latestData']['uiData']['DispTemperature'] end |
#fan_mode ⇒ Object
99 100 101 102 |
# File 'lib/htcc/thermostat.rb', line 99 def fan_mode get_status FAN_MODES[@status['latestData']['fanData']['fanMode']] end |
#fan_mode=(mode) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/htcc/thermostat.rb', line 104 def fan_mode=(mode) unless fan_modes.index(mode) raise FanError.new("Unknown mode: #{mode.inspect}. Allowed modes: #{fan_modes.inspect}") end change_setting(fan_mode: mode) end |
#fan_modes ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/htcc/thermostat.rb', line 205 def fan_modes return @fan_modes if @fan_modes get_status if @status.empty? allowed_modes = [ @status['latestData']['fanData']['fanModeAutoAllowed'], @status['latestData']['fanData']['fanModeOnAllowed'], @status['latestData']['fanData']['fanModeCirculateAllowed'], @status['latestData']['fanData']['fanModeFollowScheduleAllowed'] ] @fan_modes = FAN_MODES.select.with_index { |_, i| allowed_modes[i] } end |
#fan_running? ⇒ Boolean
94 95 96 97 |
# File 'lib/htcc/thermostat.rb', line 94 def fan_running? get_status @status['latestData']['fanData']['fanIsRunning'] end |
#has_fan? ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/htcc/thermostat.rb', line 87 def has_fan? return @has_fan unless @has_fan.nil? get_status if @status.empty? @has_fan = @status['latestData']['hasFan'] end |
#heat_setpoint ⇒ Object
Heating temperature setting
139 140 141 142 |
# File 'lib/htcc/thermostat.rb', line 139 def heat_setpoint get_status @status['latestData']['uiData']['HeatSetpoint'] end |
#heat_setpoint=(temp) ⇒ Object
144 145 146 147 148 |
# File 'lib/htcc/thermostat.rb', line 144 def heat_setpoint=(temp) raise_min_setpoint(min_heat_setpoint, temp) if temp < min_heat_setpoint raise_max_setpoint(max_heat_setpoint, temp) if temp > max_heat_setpoint change_setting(heat_setpoint: temp, hold: :temporary) end |
#heat_setpoint_range ⇒ Object
150 151 152 |
# File 'lib/htcc/thermostat.rb', line 150 def heat_setpoint_range (min_heat_setpoint..max_heat_setpoint) end |
#hold ⇒ Object
158 159 160 161 |
# File 'lib/htcc/thermostat.rb', line 158 def hold get_status HOLD_TYPES[@status['latestData']['uiData']['StatusHeat']] # Both statuses return the same value end |
#hold=(mode) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/htcc/thermostat.rb', line 163 def hold=(mode) unless HOLD_TYPES.index(mode) raise HoldError.new("Unknown mode: #{mode.inspect}. Allowed modes: #{HOLD_TYPES.inspect}") end change_setting(hold: mode) end |
#hold_until ⇒ Object
170 171 172 173 |
# File 'lib/htcc/thermostat.rb', line 170 def hold_until get_status HOLD_TIMES[@status['latestData']['uiData']['HeatNextPeriod']] # Both periods return the same value end |
#hold_until=(time) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'lib/htcc/thermostat.rb', line 175 def hold_until=(time) unless HOLD_TIMES.index(time) raise HoldError.new( "Unknown hold time: #{time.inspect}. Valid times are from 00:00 - 23:45 in 15 minute intervals." ) end change_setting(hold_until: time, hold: :temporary) end |
#id ⇒ Object
53 54 55 |
# File 'lib/htcc/thermostat.rb', line 53 def id @info['DeviceID'] end |
#mac_address ⇒ Object
57 58 59 |
# File 'lib/htcc/thermostat.rb', line 57 def mac_address @info['MacID'] end |
#name ⇒ Object
61 62 63 |
# File 'lib/htcc/thermostat.rb', line 61 def name @info['Name'] end |
#no_refresh(&block) ⇒ Object
218 219 220 221 222 223 |
# File 'lib/htcc/thermostat.rb', line 218 def no_refresh(&block) @refresh = false result = yield @refresh = true result end |
#output_status ⇒ Object
184 185 186 187 188 189 |
# File 'lib/htcc/thermostat.rb', line 184 def output_status get_status status = @status['latestData']['uiData']['EquipmentOutputStatus'] status = no_refresh { fan_running? ? 3 : status } if status.zero? EQUIPMENT_OUTPUT_STATUS[@status['latestData']['uiData']['EquipmentOutputStatus']] end |
#resume_schedule ⇒ Object
154 155 156 |
# File 'lib/htcc/thermostat.rb', line 154 def resume_schedule change_setting(hold: :none) end |
#Scheduler ⇒ Object
45 46 47 |
# File 'lib/htcc/thermostat.rb', line 45 def Scheduler @scheduler ||= Scheduler.new(id, @client) end |
#Settings ⇒ Object
49 50 51 |
# File 'lib/htcc/thermostat.rb', line 49 def Settings @settings ||= Settings.new(id, @client) end |
#status(refresh = false) ⇒ Object
70 71 72 73 |
# File 'lib/htcc/thermostat.rb', line 70 def status(refresh = false) get_status if @status.empty? || refresh @status end |
#system_mode ⇒ Object
75 76 77 78 |
# File 'lib/htcc/thermostat.rb', line 75 def system_mode get_status SYSTEM_MODES[@status['latestData']['uiData']['SystemSwitchPosition']] end |
#system_mode=(mode) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/htcc/thermostat.rb', line 80 def system_mode=(mode) unless system_modes.index(mode) raise SystemError.new("Unknown mode: #{mode.inspect}. Allowed modes: #{system_modes.inspect}") end change_setting(system_mode: mode) end |
#system_modes ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/htcc/thermostat.rb', line 191 def system_modes return @system_modes if @system_modes get_status if @status.empty? allowed_modes = [ @status['latestData']['uiData']['SwitchEmergencyHeatAllowed'], @status['latestData']['uiData']['SwitchHeatAllowed'], @status['latestData']['uiData']['SwitchOffAllowed'], @status['latestData']['uiData']['SwitchCoolAllowed'], @status['latestData']['uiData']['SwitchAutoAllowed'], ] @system_modes = SYSTEM_MODES.select.with_index { |_, i| allowed_modes[i] } end |
#temperature_unit ⇒ Object
117 118 119 120 |
# File 'lib/htcc/thermostat.rb', line 117 def temperature_unit get_status @status['latestData']['uiData']['DisplayUnits'] end |