Class: Tradfri::Device
- Inherits:
-
Struct
- Object
- Struct
- Tradfri::Device
- Defined in:
- lib/tradfri/device.rb
Constant Summary collapse
- LIGHT_CONTROL =
3311
- ON_OFF =
5850
- OFF =
0
- ON =
1
- DIMMER =
5851
- DIMMER_MIN =
0
- DIMMER_MAX =
255
- COLOUR =
5706
- COLOUR_COLD =
'f5faf6'
- COLOUR_NORMAL =
'f1e0b5'
- COLOUR_WARM =
'efd275'
- NAME =
I don’t know if/where these are officially documented
9001
- BULBS =
TODO discover this
15001
Instance Attribute Summary collapse
-
#gateway ⇒ Object
Returns the value of attribute gateway.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #bulb? ⇒ Boolean
- #cold ⇒ Object
- #dim(brightness) ⇒ Object
- #info ⇒ Object
- #name ⇒ Object
- #normal ⇒ Object
- #off ⇒ Object
- #on ⇒ Object
- #warm ⇒ Object
Instance Attribute Details
#gateway ⇒ Object
Returns the value of attribute gateway
4 5 6 |
# File 'lib/tradfri/device.rb', line 4 def gateway @gateway end |
#uri ⇒ Object
Returns the value of attribute uri
4 5 6 |
# File 'lib/tradfri/device.rb', line 4 def uri @uri end |
Instance Method Details
#bulb? ⇒ Boolean
23 24 25 |
# File 'lib/tradfri/device.rb', line 23 def bulb? info.has_key? LIGHT_CONTROL.to_s end |
#cold ⇒ Object
61 62 63 |
# File 'lib/tradfri/device.rb', line 61 def cold change COLOUR => COLOUR_COLD end |
#dim(brightness) ⇒ Object
57 58 59 |
# File 'lib/tradfri/device.rb', line 57 def dim(brightness) change DIMMER => DIMMER_MIN + (brightness * (DIMMER_MAX - DIMMER_MIN)).round end |
#info ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tradfri/device.rb', line 31 def info data = gateway.get(uri) result = begin JSON.parse(data) rescue JSON::ParserError {} end case result when Hash result else {} end end |
#name ⇒ Object
27 28 29 |
# File 'lib/tradfri/device.rb', line 27 def name info[NAME.to_s] end |
#normal ⇒ Object
65 66 67 |
# File 'lib/tradfri/device.rb', line 65 def normal change COLOUR => COLOUR_NORMAL end |
#warm ⇒ Object
69 70 71 |
# File 'lib/tradfri/device.rb', line 69 def warm change COLOUR => COLOUR_WARM end |