Class: Fritzbox::Smarthome::Switch

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

Instance Attribute Summary collapse

Attributes inherited from Actor

#ain, #group_members, #id, #manufacturer, #name, #present, #type

Class Method Summary collapse

Methods inherited from Actor

all

Methods inherited from Resource

get

Instance Attribute Details

#powermeter_energyObject

Returns the value of attribute powermeter_energy.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def powermeter_energy
  @powermeter_energy
end

#powermeter_powerObject

Returns the value of attribute powermeter_power.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def powermeter_power
  @powermeter_power
end

#powermeter_voltageObject

Returns the value of attribute powermeter_voltage.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def powermeter_voltage
  @powermeter_voltage
end

#simpleonoff_stateObject

Returns the value of attribute simpleonoff_state.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def simpleonoff_state
  @simpleonoff_state
end

#switch_devicelockObject

Returns the value of attribute switch_devicelock.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def switch_devicelock
  @switch_devicelock
end

#switch_lockObject

Returns the value of attribute switch_lock.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def switch_lock
  @switch_lock
end

#switch_modeObject

Returns the value of attribute switch_mode.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def switch_mode
  @switch_mode
end

#switch_stateObject

Returns the value of attribute switch_state.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def switch_state
  @switch_state
end

#temperature_celsiusObject

Returns the value of attribute temperature_celsius.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def temperature_celsius
  @temperature_celsius
end

#temperature_offsetObject

Returns the value of attribute temperature_offset.



5
6
7
# File 'lib/fritzbox/smarthome/switch.rb', line 5

def temperature_offset
  @temperature_offset
end

Class Method Details

.match?(data) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.new_from_api(data) ⇒ Object



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

def new_from_api(data)
  instance = super
  instance.assign_attributes(
    switch_state:        data.dig('switch', 'state').to_i,
    switch_mode:         data.dig('switch', 'mode').to_s,
    switch_lock:         data.dig('switch', 'lock').to_i,
    switch_devicelock:   data.dig('switch', 'devicelock').to_i,
    simpleonoff_state:   data.dig('simpleonoff', 'state').to_i,
    powermeter_voltage:  data.dig('powermeter', 'voltage').to_i,
    powermeter_power:    data.dig('powermeter', 'power').to_i,
    powermeter_energy:   data.dig('powermeter', 'energy').to_i,
    temperature_celsius: data.dig('temperature', 'celsius').to_i,
    temperature_offset:  data.dig('temperature', 'offset').to_i
  )
  instance
end