Class: Tradfri::Service

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

Constant Summary collapse

SERVICE_TYPE =
'_coap'
TRANSPORT_PROTOCOL =
'_udp'
INTERNET_PROTOCOL =
DNSSD::Service::IPv4
REGISTRATION_TYPE =
[SERVICE_TYPE, TRANSPORT_PROTOCOL].join('.')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



4
5
6
# File 'lib/tradfri/service.rb', line 4

def host
  @host
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/tradfri/service.rb', line 4

def name
  @name
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



4
5
6
# File 'lib/tradfri/service.rb', line 4

def port
  @port
end

Class Method Details

.discoverObject



15
16
17
18
19
20
# File 'lib/tradfri/service.rb', line 15

def self.discover
  browse(REGISTRATION_TYPE).map do |reply|
    host, port = resolve(reply, INTERNET_PROTOCOL)
    Service.new(reply.name, host, port)
  end
end

Instance Method Details

#mac_addressObject



10
11
12
13
# File 'lib/tradfri/service.rb', line 10

def mac_address
  name.slice %r{(?:\h{2}-){5}\h{2}} ||
    raise("couldn’t find MAC address in “#{name}")
end