Class: TuyaCloud::Device::Light

Inherits:
Switchable show all
Defined in:
lib/tuya_cloud/device.rb

Direct Known Subclasses

ColorLight

Instance Attribute Summary collapse

Attributes inherited from Switchable

#online, #state

Attributes inherited from Control

#auth_context, #id

Instance Method Summary collapse

Methods inherited from Switchable

#toggle, #turn_off, #turn_on

Methods inherited from Control

#process_request

Constructor Details

#initialize(json, auth_context) ⇒ Light

Returns a new instance of Light.



76
77
78
79
# File 'lib/tuya_cloud/device.rb', line 76

def initialize(json, auth_context)
  super(json, auth_context)
  self.brightness = json['data']['brightness'].to_i
end

Instance Attribute Details

#brightnessObject

Returns the value of attribute brightness.



74
75
76
# File 'lib/tuya_cloud/device.rb', line 74

def brightness
  @brightness
end

Instance Method Details

#set_brightness(value) ⇒ Object

Raises:

  • (ArgumentError)


81
82
83
84
85
86
87
88
# File 'lib/tuya_cloud/device.rb', line 81

def set_brightness(value)
  raise ArgumentError unless value.is_a?(Integer)
  raise ArgumentError if value.negative? || value > 255

  self.state = true
  process_request('brightnessSet', payload: { value: value })
  self.brightness = value
end