Class: BulbState
- Inherits:
-
Object
- Object
- BulbState
- Defined in:
- lib/lights/bulbstate.rb
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
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ BulbState
Returns a new instance of BulbState.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lights/bulbstate.rb', line 44 def initialize( data = {} ) data = {} if data == nil @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"] @reachable = data["reachable"] set_transition_time data["transitiontime"] @data = data end |
Instance Attribute Details
#alert ⇒ Object
Returns the value of attribute alert.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def alert @alert end |
#bri ⇒ Object
Returns the value of attribute bri.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def bri @bri end |
#color_mode ⇒ Object
Returns the value of attribute color_mode.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def color_mode @color_mode end |
#ct ⇒ Object
Returns the value of attribute ct.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def ct @ct end |
#effect ⇒ Object
Returns the value of attribute effect.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def effect @effect end |
#hue ⇒ Object
Returns the value of attribute hue.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def hue @hue end |
#on ⇒ Object
Returns the value of attribute on.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def on @on end |
#reachable ⇒ Object (readonly)
Returns the value of attribute reachable.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def reachable @reachable end |
#sat ⇒ Object
Returns the value of attribute sat.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def sat @sat end |
#transition_time ⇒ Object
Returns the value of attribute transition_time.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def transition_time @transition_time end |
#xy ⇒ Object
Returns the value of attribute xy.
41 42 43 |
# File 'lib/lights/bulbstate.rb', line 41 def xy @xy end |
Instance Method Details
#data ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/lights/bulbstate.rb', line 172 def data data = @data data["on"] = @on if (@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 if @reachable data["transitiontime"] = @transition_time if @transition_time data end |
#set_alert(value) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/lights/bulbstate.rb', line 72 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
102 103 104 105 106 107 108 |
# File 'lib/lights/bulbstate.rb', line 102 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
61 62 63 64 65 66 67 68 69 |
# File 'lib/lights/bulbstate.rb', line 61 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
111 112 113 114 115 116 117 118 119 |
# File 'lib/lights/bulbstate.rb', line 111 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
83 84 85 86 87 88 89 |
# File 'lib/lights/bulbstate.rb', line 83 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
133 134 135 136 137 138 139 140 141 |
# File 'lib/lights/bulbstate.rb', line 133 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
92 93 94 95 96 97 98 99 |
# File 'lib/lights/bulbstate.rb', line 92 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
122 123 124 125 126 127 128 129 130 |
# File 'lib/lights/bulbstate.rb', line 122 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
144 145 146 147 148 149 150 151 152 |
# File 'lib/lights/bulbstate.rb', line 144 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
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/lights/bulbstate.rb', line 155 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 |
#to_json(options = {}) ⇒ Object
188 189 190 |
# File 'lib/lights/bulbstate.rb', line 188 def to_json(={}) data.to_json end |