class Hue::Light
Constants
- BRIGHTNESS_RANGE
- COLOR_TEMPERATURE_RANGE
- HUE_RANGE
- KEYS_MAP
- SATURATION_RANGE
- STATE_KEYS_MAP
Attributes
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.
@see developers.meethue.com/coreconcepts.html#some_extra_fun_stuff
Bridge
the light is associated with
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.
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.
The Mired Color temperature of the light. 2012 connected lights are capable of 153 (6500K) to 500 (2000K).
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.
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.
Unique identification number.
The hardware model of the light.
A unique, editable name given to the light.
Reserved for future functionality.
Saturation of the light. 255 is the most saturated (colored) and 0 is the least saturated (white).
An identifier for the software version running on the light.
A fixed name describing the type of light.
The x coordinate of a color in CIE color space. Between 0 and 1.
@see developers.meethue.com/coreconcepts.html#color_gets_more_complicated
The y coordinate of a color in CIE color space. Between 0 and 1.
@see developers.meethue.com/coreconcepts.html#color_gets_more_complicated
Public Class Methods
# File lib/hue/light.rb, line 87 def initialize(client, bridge, id, hash) @client = client @bridge = bridge @id = id unpack(hash) end
Public Instance Methods
# File lib/hue/light.rb, line 94 def name=(new_name) unless (1..32).include?(new_name.length) raise InvalidValueForParameter, 'name must be between 1 and 32 characters.' end body = { :name => new_name } uri = URI.parse(base_url) http = Net::HTTP.new(uri.host) response = http.request_put(uri.path, JSON.dump(body)) response = JSON(response.body).first if response['success'] @name = new_name # else # TODO: Error end end
Indicates if a light can be reached by the bridge. Currently always returns true, functionality will be added in a future patch.
# File lib/hue/light.rb, line 117 def reachable? @state['reachable'] end
Refresh the state of the lamp
# File lib/hue/light.rb, line 138 def refresh json = JSON(Net::HTTP.get(URI.parse(base_url))) unpack(json) end
@param transition The duration of the transition from the light’s current
state to the new state. This is given as a multiple of 100ms and defaults to 4 (400ms). For example, setting transistiontime:10 will make the transition last 1 second.
# 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
Private Instance Methods
# File lib/hue/light.rb, line 173 def base_url "http://#{@bridge.ip}/api/#{@client.username}/lights/#{id}" end
# File lib/hue/light.rb, line 167 def unpack(hash) unpack_hash(hash, KEYS_MAP) unpack_hash(@state, STATE_KEYS_MAP) @x, @y = @state['xy'] end