Class: Hue::Light

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from EditableState

#off!, #on!, #on?, #set_xy

Methods included from TranslateKeys

#translate_keys, #unpack_hash

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

#alertObject

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

#bridgeObject (readonly)

Bridge the light is associated with



15
16
17
# File 'lib/hue/light.rb', line 15

def bridge
  @bridge
end

#brightnessObject

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_modeObject (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_temperatureObject

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

#effectObject

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

#hueObject

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

#idObject (readonly)

Unique identification number.



12
13
14
# File 'lib/hue/light.rb', line 12

def id
  @id
end

#modelObject (readonly)

The hardware model of the light.



79
80
81
# File 'lib/hue/light.rb', line 79

def model
  @model
end

#nameObject

A unique, editable name given to the light.



18
19
20
# File 'lib/hue/light.rb', line 18

def name
  @name
end

#point_symbolObject (readonly)

Reserved for future functionality.



85
86
87
# File 'lib/hue/light.rb', line 85

def point_symbol
  @point_symbol
end

#saturationObject

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_versionObject (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

#typeObject (readonly)

A fixed name describing the type of light.



76
77
78
# File 'lib/hue/light.rb', line 76

def type
  @type
end

#xObject (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

#yObject (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.

Returns:

  • (Boolean)


117
118
119
# File 'lib/hue/light.rb', line 117

def reachable?
  @state['reachable']
end

#refreshObject

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

Parameters:

  • transition (defaults to: nil)

    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.



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