Class: TuyaCloud::Device::ColorLight

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

Defined Under Namespace

Classes: ColorSetting

Instance Attribute Summary collapse

Attributes inherited from Light

#brightness

Attributes inherited from Switchable

#online, #state

Attributes inherited from Control

#auth_context, #id

Instance Method Summary collapse

Methods inherited from Light

#set_brightness

Methods inherited from Switchable

#toggle, #turn_off, #turn_on

Methods inherited from Control

#process_request

Constructor Details

#initialize(json, auth_context) ⇒ ColorLight

Returns a new instance of ColorLight.



94
95
96
97
98
# File 'lib/tuya_cloud/device.rb', line 94

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

#colorObject

Returns the value of attribute color.



91
92
93
# File 'lib/tuya_cloud/device.rb', line 91

def color
  @color
end

#color_modeObject

Returns the value of attribute color_mode.



91
92
93
# File 'lib/tuya_cloud/device.rb', line 91

def color_mode
  @color_mode
end

Instance Method Details

#set_color(red, green, blue) ⇒ Object

Raises:

  • (ArgumentError)


109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/tuya_cloud/device.rb', line 109

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.color_mode = 'colour'
  color.from_rgb(red, green, blue)
  process_request('colorSet', payload: { color: color.to_h })
  color.to_h
end

#set_whiteObject



100
101
102
103
104
105
106
107
# File 'lib/tuya_cloud/device.rb', line 100

def set_white
  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