Class: Tradfri::Gateway
- Inherits:
-
Struct
- Object
- Struct
- Tradfri::Gateway
- Defined in:
- lib/tradfri/gateway.rb
Constant Summary collapse
- SCHEME =
'coaps'
- DISCOVERY_PATH =
'/.well-known/core'
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#host ⇒ Object
Returns the value of attribute host.
-
#key ⇒ Object
Returns the value of attribute key.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
5 6 7 |
# File 'lib/tradfri/gateway.rb', line 5 def client @client end |
#host ⇒ Object
Returns the value of attribute host
5 6 7 |
# File 'lib/tradfri/gateway.rb', line 5 def host @host end |
#key ⇒ Object
Returns the value of attribute key
5 6 7 |
# File 'lib/tradfri/gateway.rb', line 5 def key @key end |
#port ⇒ Object
Returns the value of attribute port
5 6 7 |
# File 'lib/tradfri/gateway.rb', line 5 def port @port end |
Instance Method Details
#bulbs ⇒ Object
17 18 19 |
# File 'lib/tradfri/gateway.rb', line 17 def bulbs devices.select(&:bulb?) end |
#devices ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/tradfri/gateway.rb', line 9 def devices client.get(key, discovery_uri).split(','). map { |link| %r{\A</(?<uri>[^>]+)>}.match(link) }. compact. map { |match| discovery_uri.merge(match[:uri]) }. map { |uri| Device.new(self, uri) } end |
#get(uri) ⇒ Object
21 22 23 |
# File 'lib/tradfri/gateway.rb', line 21 def get(uri) client.get key, uri end |
#put(uri, payload) ⇒ Object
25 26 27 |
# File 'lib/tradfri/gateway.rb', line 25 def put(uri, payload) client.put key, uri, payload end |