Class: Hue::SSDP

Inherits:
Object
  • Object
show all
Defined in:
lib/alexa_hue/hue_switch.rb

Constant Summary collapse

MULTICAST_ADDR =

SSDP multicast IPv4 address

'239.255.255.250'.freeze
MULTICAST_PORT =

SSDP UDP port

1900.freeze
DEFAULT_SERVICE_TYPE =

Listen for all devices

'ssdp:all'.freeze
DEFAULT_TIMEOUT =

Timeout in 2 seconds

2.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SSDP

Returns a new instance of SSDP.

Parameters:

  • service_type (String)

    the identifier of the device you’re trying to find

  • timeout (Fixnum)

    timeout in seconds



467
468
469
470
471
472
# File 'lib/alexa_hue/hue_switch.rb', line 467

def initialize(options = {})
  @service_type = options[:service_type]
  @timeout = (options[:timeout] || DEFAULT_TIMEOUT)
  @first = options[:first]
  initialize_socket
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



463
464
465
# File 'lib/alexa_hue/hue_switch.rb', line 463

def first
  @first
end

#service_typeObject (readonly)

Returns the value of attribute service_type.



461
462
463
# File 'lib/alexa_hue/hue_switch.rb', line 461

def service_type
  @service_type
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



462
463
464
# File 'lib/alexa_hue/hue_switch.rb', line 462

def timeout
  @timeout
end

Instance Method Details

#devicesObject

Look for devices on the network



475
476
477
478
# File 'lib/alexa_hue/hue_switch.rb', line 475

def devices
  @socket.send(search_message, 0, MULTICAST_ADDR, MULTICAST_PORT)
  listen_for_responses(first)
end