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.



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

#colorObject

Returns the value of attribute color.



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

def color
  @color
end

#color_modeObject

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

Raises:

  • (ArgumentError)


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_whiteObject



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