Module: Fritzbox::Smarthome::Properties::SimpleOnOff
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/fritzbox/smarthome/properties/simple_on_off.rb
Overview
Defines a common interface/behaviour for actors with the “simpleonoff” state. The including class is expected to have an ‘ain` attribute defined.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#toggle! ⇒ false, Integer
Makes a request to the Fritzbox and set the current instance’s active state.
Instance Method Details
#active? ⇒ Boolean
24 25 26 |
# File 'lib/fritzbox/smarthome/properties/simple_on_off.rb', line 24 def active? simpleonoff_state == 1 end |
#toggle! ⇒ false, Integer
Makes a request to the Fritzbox and set the current instance’s active state.
The instance state is kept in memory and not checked with the Fritzbox state. It is possible that the device is switched on/off through other means.
43 44 45 46 47 48 49 |
# File 'lib/fritzbox/smarthome/properties/simple_on_off.rb', line 43 def toggle! raise ArgumentError, "Attribute `ain` is missing on #{inspect}" unless respond_to?(:ain) value = active? ? 0 : 1 response = Fritzbox::Smarthome::Resource.get(command: 'setsimpleonoff', ain: ain, onoff: value) response.ok? && self.simpleonoff_state = value end |