class Hue::Light

Constants

BRIGHTNESS_RANGE
COLOR_TEMPERATURE_RANGE
HUE_RANGE
KEYS_MAP
SATURATION_RANGE
STATE_KEYS_MAP

Attributes

alert[R]

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[R]

Bridge the light is associated with

brightness[R]

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.

color_mode[R]

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.

color_temperature[R]

The Mired Color temperature of the light. 2012 connected lights are capable of 153 (6500K) to 500 (2000K).

@see en.wikipedia.org/wiki/Mired

effect[R]

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[R]

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.

id[R]

Unique identification number.

model[R]

The hardware model of the light.

name[RW]

A unique, editable name given to the light.

point_symbol[R]

Reserved for future functionality.

saturation[R]

Saturation of the light. 255 is the most saturated (colored) and 0 is the least saturated (white).

software_version[R]

An identifier for the software version running on the light.

type[R]

A fixed name describing the type of light.

x[R]

The x coordinate of a color in CIE color space. Between 0 and 1.

@see developers.meethue.com/coreconcepts.html#color_gets_more_complicated

y[R]

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

new(client, bridge, id, hash) click to toggle source
# 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

name=(new_name) click to toggle source
# 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
reachable?() click to toggle source

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() click to toggle source

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
set_state(attributes, transition = nil) click to toggle source

@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

base_url() click to toggle source
# File lib/hue/light.rb, line 173
def base_url
  "http://#{@bridge.ip}/api/#{@client.username}/lights/#{id}"
end
unpack(hash) click to toggle source
# 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