class Fritzbox::Smarthome::Heater

Attributes

battery[RW]
batterylow[RW]
hkr_next_change_period[RW]
hkr_next_change_temp[RW]
hkr_temp_is[RW]
hkr_temp_set[RW]

Public Class Methods

match?(data) click to toggle source
# File lib/fritzbox/smarthome/heater.rb, line 14
def match?(data)
  data.key?('hkr')
end
new_from_api(data) click to toggle source
# File lib/fritzbox/smarthome/heater.rb, line 18
def new_from_api(data)
  instance = super
  instance.assign_attributes(
    battery:                data.dig('battery').to_i,
    batterylow:             data.dig('batterylow').to_i,
    hkr_temp_is:            data.dig('hkr', 'tist').to_i * 0.5,
    hkr_temp_set:           data.dig('hkr', 'tsoll').to_i * 0.5,
    hkr_next_change_period: Time.at(data.dig('hkr', 'nextchange', 'endperiod').to_i),
    hkr_next_change_temp:   data.dig('hkr', 'nextchange', 'tchange').to_i * 0.5
  )
  instance
end

Public Instance Methods

update_hkr_temp_set(value) click to toggle source
# File lib/fritzbox/smarthome/heater.rb, line 32
def update_hkr_temp_set(value)
  raise ArgumentError unless value.is_a? BigDecimal
  value = (value / 0.5).to_i
  response = self.class.get(command: 'sethkrtsoll', ain: ain, param: value)
  raise 'Could not set temperature' unless response.body == "#{value}\n"
  true
end