Class: Fritzbox::Smarthome::Switch

Inherits:
Actor show all
Includes:
Properties::SimpleOnOff
Defined in:
lib/fritzbox/smarthome/switch.rb

Constant Summary

Constants inherited from Actor

Actor::ResourceNotFound

Constants inherited from Resource

Resource::AuthenticationError

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Properties::SimpleOnOff

#active?, #toggle!

Methods inherited from Actor

all, find_by!, new_from_api, #reload

Methods inherited from Resource

get, parse

Class Method Details

.match?(data) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/fritzbox/smarthome/switch.rb', line 17

def match?(data)
  data.key?('switch')
end

Instance Method Details

#assign_from_api(data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fritzbox/smarthome/switch.rb', line 22

def assign_from_api(data)
  super(data)

  assign_attributes(
    switch_state:        data.dig('switch', 'state'),
    switch_mode:         data.dig('switch', 'mode'),
    switch_lock:         data.dig('switch', 'lock'),
    switch_devicelock:   data.dig('switch', 'devicelock'),
    powermeter_voltage:  data.dig('powermeter', 'voltage'),
    powermeter_power:    data.dig('powermeter', 'power'),
    powermeter_energy:   data.dig('powermeter', 'energy'),
    temperature_celsius: data.dig('temperature', 'celsius'),
    temperature_offset:  data.dig('temperature', 'offset')
  )
end