Class: Tradfri::Gateway

Inherits:
Struct
  • Object
show all
Defined in:
lib/tradfri/gateway.rb

Constant Summary collapse

SCHEME =
'coaps'
DISCOVERY_PATH =
'/.well-known/core'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



5
6
7
# File 'lib/tradfri/gateway.rb', line 5

def client
  @client
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



5
6
7
# File 'lib/tradfri/gateway.rb', line 5

def host
  @host
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



5
6
7
# File 'lib/tradfri/gateway.rb', line 5

def key
  @key
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



5
6
7
# File 'lib/tradfri/gateway.rb', line 5

def port
  @port
end

Instance Method Details

#bulbsObject



17
18
19
# File 'lib/tradfri/gateway.rb', line 17

def bulbs
  devices.select(&:bulb?)
end

#devicesObject



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