class TuyaCloud::Device::ColorLight

Attributes

color[RW]
color_mode[RW]

Public Class Methods

new(json, auth_context) click to toggle source
Calls superclass method TuyaCloud::Device::Light::new
# 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

Public Instance Methods

set_color(red, green, blue) click to toggle source
# 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() click to toggle source
# 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