Class: BulbState
Direct Known Subclasses
Defined Under Namespace
Modules: Alert, ColorMode, Effect, Hue
Constant Summary collapse
- MAX_CT =
500
- MIN_CT =
153
- MAX_BRI =
255
- MIN_BRI =
0
- MAX_SAT =
255
- MIN_SAT =
0
- MAX_HUE =
65535
- MIN_HUE =
0
- MIN_TRANSITION_TIME =
0
- MAX_XY =
1.0
- MIN_XY =
0.0
Instance Attribute Summary collapse
-
#alert ⇒ Object
Returns the value of attribute alert.
-
#bri ⇒ Object
Returns the value of attribute bri.
-
#color_mode ⇒ Object
Returns the value of attribute color_mode.
-
#ct ⇒ Object
Returns the value of attribute ct.
-
#effect ⇒ Object
Returns the value of attribute effect.
-
#hue ⇒ Object
Returns the value of attribute hue.
-
#on ⇒ Object
Returns the value of attribute on.
-
#reachable ⇒ Object
readonly
Returns the value of attribute reachable.
-
#sat ⇒ Object
Returns the value of attribute sat.
-
#transition_time ⇒ Object
Returns the value of attribute transition_time.
-
#xy ⇒ Object
Returns the value of attribute xy.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(data = {}) ⇒ BulbState
constructor
A new instance of BulbState.
- #set_alert(value) ⇒ Object
- #set_bri(value) ⇒ Object
- #set_color_mode(value) ⇒ Object
- #set_ct(value) ⇒ Object
- #set_effect(value) ⇒ Object
- #set_hue(value) ⇒ Object
- #set_on(value) ⇒ Object
- #set_sat(value) ⇒ Object
- #set_transition_time(value) ⇒ Object
- #set_xy(value) ⇒ Object
Methods inherited from HObject
Constructor Details
#initialize(data = {}) ⇒ BulbState
Returns a new instance of BulbState.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lights/bulbstate.rb', line 46 def initialize( data = {} ) data = {} if data == nil @reachable = data["reachable"] # bridge returns invaild values for state variables when reachable is false unless @reachable == false @on = data["on"] set_bri data["bri"] set_hue data["hue"] set_sat data["sat"] set_xy data["xy"] set_ct data["ct"] set_alert data["alert"] set_effect data["effect"] set_color_mode data["colormode"] set_transition_time data["transitiontime"] end end |
Instance Attribute Details
#alert ⇒ Object
Returns the value of attribute alert.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def alert @alert end |
#bri ⇒ Object
Returns the value of attribute bri.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def bri @bri end |
#color_mode ⇒ Object
Returns the value of attribute color_mode.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def color_mode @color_mode end |
#ct ⇒ Object
Returns the value of attribute ct.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def ct @ct end |
#effect ⇒ Object
Returns the value of attribute effect.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def effect @effect end |
#hue ⇒ Object
Returns the value of attribute hue.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def hue @hue end |
#on ⇒ Object
Returns the value of attribute on.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def on @on end |
#reachable ⇒ Object (readonly)
Returns the value of attribute reachable.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def reachable @reachable end |
#sat ⇒ Object
Returns the value of attribute sat.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def sat @sat end |
#transition_time ⇒ Object
Returns the value of attribute transition_time.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def transition_time @transition_time end |
#xy ⇒ Object
Returns the value of attribute xy.
43 44 45 |
# File 'lib/lights/bulbstate.rb', line 43 def xy @xy end |
Instance Method Details
#data ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/lights/bulbstate.rb', line 177 def data data = {} data["on"] = @on unless @on.nil? data["bri"] = @bri if @bri data["hue"] = @hue if @hue data["sat"] = @sat if @sat data["xy"] = @xy if @xy data["ct"] = @ct if @ct data["alert"] = @alert if @alert data["effect"] = @effect if @effect data["colormode"] = @color_mode if @color_mode data["reachable"] = @reachable unless @reachable.nil? data["transitiontime"] = @transition_time if @transition_time data end |
#set_alert(value) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/lights/bulbstate.rb', line 77 def set_alert(value) if value.nil? || value == Alert::NONE \ || value == Alert::SELECT \ || value == Alert::LSELECT @alert = value else raise BulbStateValueTypeException, "Alert value has incorrect type. Requires 'none', 'select', or 'lselect'. Was #{value.inspect}" end end |
#set_bri(value) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/lights/bulbstate.rb', line 107 def set_bri(value) if value.nil? || value.between?(MIN_BRI,MAX_BRI) @bri = value else raise BulbStateValueOutOfRangeException, "Brightness value out of range. Must be [#{MIN_BRI},#{MAX_BRI}]. Was #{value.inspect}" end end |
#set_color_mode(value) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/lights/bulbstate.rb', line 66 def set_color_mode(value) if value.nil? || value == ColorMode::XY \ || value == ColorMode::HS \ || value == ColorMode::CT @color_mode = value else raise BulbStateValueTypeException, "Color mode value has incorrect type. Requires 'hs', 'xy', or 'ct'. Was #{value.inspect}" end end |
#set_ct(value) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/lights/bulbstate.rb', line 116 def set_ct(value) if !value.nil? && (!value.is_a? Integer) raise BulbStateValueTypeException, "Color temperature value has incorrect type. Requires integer, got #{value.class}" elsif value.nil? || value.between?(MIN_CT,MAX_CT) @ct = value else raise BulbStateValueOutOfRangeException, "Color temperature value out of range. Must be [#{MIN_CT},#{MAX_CT}]. Was #{value.inspect}" end end |
#set_effect(value) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/lights/bulbstate.rb', line 88 def set_effect(value) if value.nil? || value == Effect::NONE || value == Effect::COLORLOOP @effect = value else raise BulbStateValueTypeException, "Effect value has incorrect type. Requires 'none' or 'colorloop'. Was #{value.inspect}" end end |
#set_hue(value) ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/lights/bulbstate.rb', line 138 def set_hue(value) if !value.nil? && (!value.is_a? Integer) raise BulbStateValueTypeException, "Hue value has incorrect type. Requires integer, got #{value.class}" elsif value.nil? || value.between?(MIN_HUE,MAX_HUE) @hue = value else raise BulbStateValueOutOfRangeException, "Hue value out of range. Must be [#{MIN_HUE},#{MAX_HUE}]. Was #{value.inspect}" end end |
#set_on(value) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/lights/bulbstate.rb', line 97 def set_on(value) # Tests if value is boolean if !!value == value @on = value else raise BulbStateValueTypeException, "On value has incorrect type. Requires boolean, got #{value.class}. Was #{value.inspect}" end end |
#set_sat(value) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/lights/bulbstate.rb', line 127 def set_sat(value) if !value.nil? && (!value.is_a? Integer) raise BulbStateValueTypeException, "Saturation value has incorrect type. Requires integer, got #{value.class}" elsif value.nil? || value.between?(MIN_SAT,MAX_SAT) @sat = value else raise BulbStateValueOutOfRangeException, "Saturation alue out of range. Must be [#{MIN_SAT},#{MAX_SAT}]. Was #{value.inspect}" end end |
#set_transition_time(value) ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/lights/bulbstate.rb', line 149 def set_transition_time(value) if !value.nil? && (!value.is_a? Numeric) raise BulbStateValueTypeException, "Transition time value has incorrect type. Requires decimal, got #{value.class}" elsif value.nil? || value >= MIN_TRANSITION_TIME @transition_time = value else raise BulbStateValueOutOfRangeException, "Transition time value out of range. Must be > #{MIN_TRANSITION_TIME}. Was #{value.inspect}" end end |
#set_xy(value) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/lights/bulbstate.rb', line 160 def set_xy(value) if !value.nil? && (!value.is_a? Array) raise BulbStateValueTypeException, "XY value has incorrect type. Requires array, got #{value.class}" elsif value.nil? return elsif value.length == 2 && value[0].is_a?(Numeric) \ && value[1].is_a?(Numeric) && value[0].to_f >= MIN_XY \ && value[0].to_f <= MAX_XY && value[1].to_f >= MIN_XY \ && value[1].to_f <= MAX_XY @xy = [] @xy[0] = value[0].to_f @xy[1] = value[1].to_f else raise BulbStateValueOutOfRangeException, "XY value out of range. Must be [#{MIN_XY},#{MAX_XY}]. Was #{value.inspect}" end end |