Class: TuyaCloud::Device::ColorLight::ColorSetting
- Inherits:
-
Object
- Object
- TuyaCloud::Device::ColorLight::ColorSetting
- Defined in:
- lib/tuya_cloud/device.rb
Instance Attribute Summary collapse
-
#brightness ⇒ Object
Returns the value of attribute brightness.
-
#hue ⇒ Object
Returns the value of attribute hue.
-
#saturation ⇒ Object
Returns the value of attribute saturation.
Instance Method Summary collapse
- #from_rgb(r, g, b) ⇒ Object
-
#initialize(json) ⇒ ColorSetting
constructor
A new instance of ColorSetting.
- #to_h ⇒ Object
Constructor Details
#initialize(json) ⇒ ColorSetting
Returns a new instance of ColorSetting.
128 129 130 131 132 |
# File 'lib/tuya_cloud/device.rb', line 128 def initialize(json) self.saturation = json['saturation'] self.brightness = json['brightness'] self.hue = json['hue'] end |
Instance Attribute Details
#brightness ⇒ Object
Returns the value of attribute brightness.
124 125 126 |
# File 'lib/tuya_cloud/device.rb', line 124 def brightness @brightness end |
#hue ⇒ Object
Returns the value of attribute hue.
124 125 126 |
# File 'lib/tuya_cloud/device.rb', line 124 def hue @hue end |
#saturation ⇒ Object
Returns the value of attribute saturation.
124 125 126 |
# File 'lib/tuya_cloud/device.rb', line 124 def saturation @saturation end |
Instance Method Details
#from_rgb(r, g, b) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/tuya_cloud/device.rb', line 134 def from_rgb(r, g, b) r /= 255.0 g /= 255.0 b /= 255.0 max = [r, g, b].max min = [r, g, b].min delta = max - min v = max * 255 s = 0.0 s = delta / max * 255 if max != 0.0 if s == 0.0 h = 0.0 else if r == max h = (g - b) / delta elsif g == max h = 2 + (b - r) / delta elsif b == max h = 4 + (r - g) / delta end h *= 60.0 h += 360.0 if h.negative? end self.hue = h.round self.saturation = s.round self.brightness = v.round end |
#to_h ⇒ Object
162 163 164 165 166 |
# File 'lib/tuya_cloud/device.rb', line 162 def to_h { hue: hue, saturation: saturation, brightness: brightness } end |