Class: PhilipsHue::Light
- Inherits:
-
Object
- Object
- PhilipsHue::Light
- Includes:
- Helpers
- Defined in:
- lib/philips_hue/light.rb
Instance Attribute Summary collapse
-
#light_id ⇒ Object
readonly
provide getter methods for these variables.
-
#name ⇒ Object
readonly
provide getter methods for these variables.
Instance Method Summary collapse
-
#alert ⇒ Object
‘select’ will flash the lamp once ‘lselect’ will flash the lamp repeatedly ‘none’ is the default state.
-
#alert=(value) ⇒ Object
set the alert state.
-
#bri ⇒ Object
(also: #brightness)
returns the current brightness value can be 0-254 (and 0 is NOT off).
-
#bri=(value) ⇒ Object
(also: #brightness=)
sets the current brightness value.
-
#colormode ⇒ Object
(also: #mode)
returns the current colormode.
-
#ct ⇒ Object
(also: #temperature, #color_temperature)
returns the current color temperature (white only) in mireds: 154 is the coolest, 500 is the warmest c.p.
-
#ct=(value) ⇒ Object
(also: #temperature=, #color_temperature=)
sets the current color temperature.
-
#effect ⇒ Object
TODO: figure out what this does (and if I can change it).
-
#hue ⇒ Object
returns the current hue value used in tandem with “sat” to set the color the ‘hue’ parameter has the range 0-65535 so represents approximately 182.04*degrees.
-
#hue=(value) ⇒ Object
sets the current hue value.
-
#initialize(light_name, light_id, api_endpoint, key) ⇒ Light
constructor
A new instance of Light.
-
#off! ⇒ Object
turn off the light.
-
#on! ⇒ Object
turn on the light.
-
#on? ⇒ Boolean
determine if the light is on or off.
-
#reachable? ⇒ Boolean
whether or not the lamp can be seen by the hub.
-
#sat ⇒ Object
(also: #saturation)
returns the current saturation value used in tandem with “hue” to set the color can be 0-254.
-
#sat=(value) ⇒ Object
(also: #saturation=)
sets the current saturation value.
-
#set(options) ⇒ Object
change the state of a light note that colormode will automagically update.
-
#state ⇒ Object
current state of the light.
-
#status ⇒ Object
query full status for single light.
-
#to_s ⇒ Object
pretty-print the light’s status.
-
#xy ⇒ Object
returns the current xy value the color is expressed as an array of co-ordinates in CIE 1931 space.
-
#xy=(value) ⇒ Object
sets the current xy value TODO: consider x() and y() setters/getters.
Methods included from Helpers
#blink, #blip, #blue, #flash, #green, #red, #yellow
Constructor Details
#initialize(light_name, light_id, api_endpoint, key) ⇒ Light
Returns a new instance of Light.
6 7 8 9 10 11 |
# File 'lib/philips_hue/light.rb', line 6 def initialize(light_name, light_id, api_endpoint, key) @name = light_name @light_id = light_id @key = key @api_endpoint = api_endpoint end |
Instance Attribute Details
#light_id ⇒ Object (readonly)
provide getter methods for these variables
14 15 16 |
# File 'lib/philips_hue/light.rb', line 14 def light_id @light_id end |
#name ⇒ Object (readonly)
provide getter methods for these variables
14 15 16 |
# File 'lib/philips_hue/light.rb', line 14 def name @name end |
Instance Method Details
#alert ⇒ Object
‘select’ will flash the lamp once ‘lselect’ will flash the lamp repeatedly ‘none’ is the default state
122 123 124 |
# File 'lib/philips_hue/light.rb', line 122 def alert state["alert"] end |
#alert=(value) ⇒ Object
set the alert state
127 128 129 |
# File 'lib/philips_hue/light.rb', line 127 def alert=(value) set(:alert => value) end |
#bri ⇒ Object Also known as: brightness
returns the current brightness value can be 0-254 (and 0 is NOT off)
57 58 59 |
# File 'lib/philips_hue/light.rb', line 57 def bri state["bri"] end |
#bri=(value) ⇒ Object Also known as: brightness=
sets the current brightness value
62 63 64 |
# File 'lib/philips_hue/light.rb', line 62 def bri=(value) set(:bri => value) end |
#colormode ⇒ Object Also known as: mode
returns the current colormode
67 68 69 |
# File 'lib/philips_hue/light.rb', line 67 def colormode state["colormode"] end |
#ct ⇒ Object Also known as: temperature, color_temperature
returns the current color temperature (white only) in mireds: 154 is the coolest, 500 is the warmest c.p. en.wikipedia.org/wiki/Mired
98 99 100 |
# File 'lib/philips_hue/light.rb', line 98 def ct state["ct"] end |
#ct=(value) ⇒ Object Also known as: temperature=, color_temperature=
sets the current color temperature
103 104 105 |
# File 'lib/philips_hue/light.rb', line 103 def ct=(value) set(:ct => value) end |
#effect ⇒ Object
TODO: figure out what this does (and if I can change it)
132 133 134 |
# File 'lib/philips_hue/light.rb', line 132 def effect state["effect"] end |
#hue ⇒ Object
returns the current hue value used in tandem with “sat” to set the color the ‘hue’ parameter has the range 0-65535 so represents approximately 182.04*degrees
74 75 76 |
# File 'lib/philips_hue/light.rb', line 74 def hue state["hue"] end |
#hue=(value) ⇒ Object
sets the current hue value
79 80 81 |
# File 'lib/philips_hue/light.rb', line 79 def hue=(value) set(:hue => value) end |
#off! ⇒ Object
turn off the light
46 47 48 |
# File 'lib/philips_hue/light.rb', line 46 def off! set(:on => false) end |
#on! ⇒ Object
turn on the light
41 42 43 |
# File 'lib/philips_hue/light.rb', line 41 def on! set(:on => true) end |
#on? ⇒ Boolean
determine if the light is on or off
36 37 38 |
# File 'lib/philips_hue/light.rb', line 36 def on? state["on"] end |
#reachable? ⇒ Boolean
whether or not the lamp can be seen by the hub
51 52 53 |
# File 'lib/philips_hue/light.rb', line 51 def reachable? state["reachable"] end |
#sat ⇒ Object Also known as: saturation
returns the current saturation value used in tandem with “hue” to set the color can be 0-254
86 87 88 |
# File 'lib/philips_hue/light.rb', line 86 def sat state["sat"] end |
#sat=(value) ⇒ Object Also known as: saturation=
sets the current saturation value
91 92 93 |
# File 'lib/philips_hue/light.rb', line 91 def sat=(value) set(:sat => value) end |
#set(options) ⇒ Object
change the state of a light note that colormode will automagically update
24 25 26 27 28 |
# File 'lib/philips_hue/light.rb', line 24 def set() json_body = .to_json request_uri = "#{@api_endpoint}/#{@key}/lights/#{@light_id}/state" HTTParty.put(request_uri, :body => json_body) end |
#state ⇒ Object
current state of the light
31 32 33 |
# File 'lib/philips_hue/light.rb', line 31 def state status["state"] end |
#status ⇒ Object
query full status for single light
17 18 19 20 |
# File 'lib/philips_hue/light.rb', line 17 def status request_uri = "#{@api_endpoint}/#{@key}/lights/#{@light_id}" HTTParty.get(request_uri) end |
#to_s ⇒ Object
pretty-print the light’s status
148 149 150 151 152 153 |
# File 'lib/philips_hue/light.rb', line 148 def to_s pretty_name = @name.to_s.split(/_/).map(&:capitalize).join(" ") on_or_off = on? ? "on" : "off" reachable = reachable? ? "reachable" : "unreachable" "#{pretty_name} is #{on_or_off} and #{reachable}" end |
#xy ⇒ Object
returns the current xy value the color is expressed as an array of co-ordinates in CIE 1931 space
109 110 111 |
# File 'lib/philips_hue/light.rb', line 109 def xy state["xy"] end |
#xy=(value) ⇒ Object
sets the current xy value TODO: consider x() and y() setters/getters
115 116 117 |
# File 'lib/philips_hue/light.rb', line 115 def xy=(value) set(:xy => value) end |