Class: TuyaCloud::Device::Switchable

Inherits:
Control
  • Object
show all
Defined in:
lib/tuya_cloud/device.rb

Direct Known Subclasses

Light, Switch

Instance Attribute Summary collapse

Attributes inherited from Control

#auth_context, #id

Instance Method Summary collapse

Methods inherited from Control

#process_request

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

#onlineObject

Returns the value of attribute online.



48
49
50
# File 'lib/tuya_cloud/device.rb', line 48

def online
  @online
end

#stateObject

Returns the value of attribute state.



48
49
50
# File 'lib/tuya_cloud/device.rb', line 48

def state
  @state
end

Instance Method Details

#toggleObject



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_offObject



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_onObject



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