Class: Hue::Light
- Inherits:
-
Object
- Object
- Hue::Light
- Includes:
- EditableState, TranslateKeys
- Defined in:
- lib/hue/light.rb
Constant Summary collapse
- HUE_RANGE =
0..65535
- SATURATION_RANGE =
0..255
- BRIGHTNESS_RANGE =
0..255
- COLOR_TEMPERATURE_RANGE =
153..500
Instance Attribute Summary collapse
-
#alert ⇒ Object
The alert effect, which is a temporary change to the bulb’s state.
-
#bridge ⇒ Object
readonly
Bridge the light is associated with.
-
#brightness ⇒ Object
Brightness of the light.
-
#color_mode ⇒ Object
readonly
Indicates the color mode in which the light is working, this is the last command type it received.
-
#color_temperature ⇒ Object
The Mired Color temperature of the light.
-
#effect ⇒ Object
The dynamic effect of the light, can either be ‘none` or `colorloop`.
-
#hue ⇒ Object
Hue of the light.
-
#id ⇒ Object
readonly
Unique identification number.
-
#model ⇒ Object
readonly
The hardware model of the light.
-
#name ⇒ Object
A unique, editable name given to the light.
-
#point_symbol ⇒ Object
readonly
Reserved for future functionality.
-
#saturation ⇒ Object
Saturation of the light.
-
#software_version ⇒ Object
readonly
An identifier for the software version running on the light.
-
#type ⇒ Object
readonly
A fixed name describing the type of light.
-
#x ⇒ Object
readonly
The x coordinate of a color in CIE color space.
-
#y ⇒ Object
readonly
The y coordinate of a color in CIE color space.
Instance Method Summary collapse
-
#initialize(client, bridge, id, hash) ⇒ Light
constructor
A new instance of Light.
-
#reachable? ⇒ Boolean
Indicates if a light can be reached by the bridge.
-
#refresh ⇒ Object
Refresh the state of the lamp.
- #set_state(attributes, transition = nil) ⇒ Object
Methods included from EditableState
Methods included from TranslateKeys
Constructor Details
#initialize(client, bridge, id, hash) ⇒ Light
Returns a new instance of Light.
87 88 89 90 91 92 |
# File 'lib/hue/light.rb', line 87 def initialize(client, bridge, id, hash) @client = client @bridge = bridge @id = id unpack(hash) end |
Instance Attribute Details
#alert ⇒ Object
The alert effect, which is a temporary change to the bulb’s state. This can take one of the following values:
-
‘none` – The light is not performing an alert effect.
-
‘select` – The light is performing one breathe cycle.
-
‘lselect` – The light is performing breathe cycles for 30 seconds
or until an "alert": "none" command is received.
Note that in version 1.0 this contains the last alert sent to the light and not its current state. This will be changed to contain the current state in an upcoming patch.
61 62 63 |
# File 'lib/hue/light.rb', line 61 def alert @alert end |
#bridge ⇒ Object (readonly)
Bridge the light is associated with
15 16 17 |
# File 'lib/hue/light.rb', line 15 def bridge @bridge end |
#brightness ⇒ Object
Brightness of the light. This is a scale from the minimum brightness the light is capable of, 0, to the maximum capable brightness, 255. Note a brightness of 0 is not off.
31 32 33 |
# File 'lib/hue/light.rb', line 31 def brightness @brightness end |
#color_mode ⇒ Object (readonly)
Indicates the color mode in which the light is working, this is the last command type it received. Values are ‘hs` for Hue and Saturation, `xy` for XY and `ct` for Color Temperature. This parameter is only present when the light supports at least one of the values.
73 74 75 |
# File 'lib/hue/light.rb', line 73 def color_mode @color_mode end |
#color_temperature ⇒ Object
The Mired Color temperature of the light. 2012 connected lights are capable of 153 (6500K) to 500 (2000K).
47 48 49 |
# File 'lib/hue/light.rb', line 47 def color_temperature @color_temperature end |
#effect ⇒ Object
The dynamic effect of the light, can either be ‘none` or `colorloop`. If set to colorloop, the light will cycle through all hues using the current brightness and saturation settings.
66 67 68 |
# File 'lib/hue/light.rb', line 66 def effect @effect end |
#hue ⇒ Object
Hue of the light. This is a wrapping value between 0 and 65535. Both 0 and 65535 are red, 25500 is green and 46920 is blue.
22 23 24 |
# File 'lib/hue/light.rb', line 22 def hue @hue end |
#id ⇒ Object (readonly)
Unique identification number.
12 13 14 |
# File 'lib/hue/light.rb', line 12 def id @id end |
#model ⇒ Object (readonly)
The hardware model of the light.
79 80 81 |
# File 'lib/hue/light.rb', line 79 def model @model end |
#name ⇒ Object
A unique, editable name given to the light.
18 19 20 |
# File 'lib/hue/light.rb', line 18 def name @name end |
#point_symbol ⇒ Object (readonly)
Reserved for future functionality.
85 86 87 |
# File 'lib/hue/light.rb', line 85 def point_symbol @point_symbol end |
#saturation ⇒ Object
Saturation of the light. 255 is the most saturated (colored) and 0 is the least saturated (white).
26 27 28 |
# File 'lib/hue/light.rb', line 26 def saturation @saturation end |
#software_version ⇒ Object (readonly)
An identifier for the software version running on the light.
82 83 84 |
# File 'lib/hue/light.rb', line 82 def software_version @software_version end |
#type ⇒ Object (readonly)
A fixed name describing the type of light.
76 77 78 |
# File 'lib/hue/light.rb', line 76 def type @type end |
#x ⇒ Object (readonly)
The x coordinate of a color in CIE color space. Between 0 and 1.
36 37 38 |
# File 'lib/hue/light.rb', line 36 def x @x end |
#y ⇒ Object (readonly)
The y coordinate of a color in CIE color space. Between 0 and 1.
41 42 43 |
# File 'lib/hue/light.rb', line 41 def y @y end |
Instance Method Details
#reachable? ⇒ Boolean
Indicates if a light can be reached by the bridge. Currently always returns true, functionality will be added in a future patch.
117 118 119 |
# File 'lib/hue/light.rb', line 117 def reachable? @state['reachable'] end |
#refresh ⇒ Object
Refresh the state of the lamp
138 139 140 141 |
# File 'lib/hue/light.rb', line 138 def refresh json = JSON(Net::HTTP.get(URI.parse(base_url))) unpack(json) end |
#set_state(attributes, transition = nil) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/hue/light.rb', line 125 def set_state(attributes, transition = nil) body = translate_keys(attributes, STATE_KEYS_MAP) # Add transition body.merge!({:transitiontime => transition}) if transition uri = URI.parse("#{base_url}/state") http = Net::HTTP.new(uri.host) response = http.request_put(uri.path, JSON.dump(body)) JSON(response.body) end |