Class: TuyaCloud::Device::Switchable
- Defined in:
- lib/tuya_cloud/device.rb
Instance Attribute Summary collapse
-
#online ⇒ Object
Returns the value of attribute online.
-
#state ⇒ Object
Returns the value of attribute state.
Attributes inherited from Control
Instance Method Summary collapse
-
#initialize(json, auth_context) ⇒ Switchable
constructor
A new instance of Switchable.
- #toggle ⇒ Object
- #turn_off ⇒ Object
- #turn_on ⇒ Object
Methods inherited from Control
Constructor Details
#initialize(json, auth_context) ⇒ Switchable
Returns a new instance of Switchable.
51 52 53 54 55 |
# File 'lib/tuya_cloud/device.rb', line 51 def initialize(json, auth_context) super(json, auth_context) self.online = json['data']['online'].to_s == 'true' self.state = json['data']['state'].to_s == 'true' end |
Instance Attribute Details
#online ⇒ Object
Returns the value of attribute online.
48 49 50 |
# File 'lib/tuya_cloud/device.rb', line 48 def online @online end |
#state ⇒ Object
Returns the value of attribute state.
48 49 50 |
# File 'lib/tuya_cloud/device.rb', line 48 def state @state end |
Instance Method Details
#toggle ⇒ Object
57 58 59 60 |
# File 'lib/tuya_cloud/device.rb', line 57 def toggle process_request('turnOnOff', payload: { value: state ? 0 : 1 }) self.state = !state end |
#turn_off ⇒ Object
62 63 64 65 |
# File 'lib/tuya_cloud/device.rb', line 62 def turn_off process_request('turnOnOff', payload: { value: 0 }) self.state = false end |
#turn_on ⇒ Object
67 68 69 70 |
# File 'lib/tuya_cloud/device.rb', line 67 def turn_on process_request('turnOnOff', payload: { value: 1 }) self.state = true end |