Class: HackyHAL::DeviceResolvers::SSDP

Inherits:
Base
  • Object
show all
Defined in:
lib/hacky_hal/device_resolvers/ssdp.rb

Instance Attribute Summary

Attributes included from Options

#options

Instance Method Summary collapse

Methods included from Options

#[]

Constructor Details

#initialize(options) ⇒ SSDP

Returns a new instance of SSDP.



14
15
16
17
# File 'lib/hacky_hal/device_resolvers/ssdp.rb', line 14

def initialize(options)
  super(DEFAULT_OPTIONS.merge(options))
  ensure_option(:usn)
end

Instance Method Details

#uriObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hacky_hal/device_resolvers/ssdp.rb', line 19

def uri
  @uri ||= (
    old_upnp_log_value = UPnP.log?
    UPnP.log = false

    device = UPnP::SSDP.search(options[:search]).find do |device|
      device[:usn] == options[:usn]
    end

    UPnP.log = old_upnp_log_value

    raise SsdpUnresolvedDevice unless device
    URI.parse(device[:location])
  )
end