Class: TuyaCloud::Device::ColorLight
- Inherits:
-
Light
- Object
- Control
- Switchable
- Light
- TuyaCloud::Device::ColorLight
- Defined in:
- lib/tuya_cloud/device.rb
Defined Under Namespace
Classes: ColorSetting
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#color_mode ⇒ Object
Returns the value of attribute color_mode.
Attributes inherited from Light
Attributes inherited from Switchable
Attributes inherited from Control
Instance Method Summary collapse
-
#initialize(json, auth_context) ⇒ ColorLight
constructor
A new instance of ColorLight.
- #set_color(red, green, blue) ⇒ Object
- #set_white ⇒ Object
Methods inherited from Light
Methods inherited from Switchable
Methods inherited from Control
Constructor Details
#initialize(json, auth_context) ⇒ ColorLight
Returns a new instance of ColorLight.
95 96 97 98 99 |
# File 'lib/tuya_cloud/device.rb', line 95 def initialize(json, auth_context) super(json, auth_context) self.color_mode = json['data']['color_mode'] self.color = ColorSetting.new(json['data']['color']) end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
92 93 94 |
# File 'lib/tuya_cloud/device.rb', line 92 def color @color end |
#color_mode ⇒ Object
Returns the value of attribute color_mode.
92 93 94 |
# File 'lib/tuya_cloud/device.rb', line 92 def color_mode @color_mode end |
Instance Method Details
#set_color(red, green, blue) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/tuya_cloud/device.rb', line 111 def set_color(red, green, blue) raise ArgumentError unless red.is_a?(Integer) && green.is_a?(Integer) && blue.is_a?(Integer) raise ArgumentError if (red.negative? || red > 255) || (green.negative? || green > 255) || (blue.negative? || blue > 255) self.state = true self.color_mode = 'colour' color.from_rgb(red, green, blue) process_request('colorSet', payload: { color: color.to_h }) color.to_h end |
#set_white ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/tuya_cloud/device.rb', line 101 def set_white self.state = true self.color_mode = 'white' color.hue = 0 color.saturation = 0 color.brightness = 100 process_request('colorSet', payload: { color: color.to_h }) color.to_h end |