Class: Sinatra::Hue::Device

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

Overview

The Device and SSDP classes are basically lifted from Sam Soffes’ great GitHub repo: github.com/soffes/discover.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Device



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/alexa_hue/hue_switch.rb', line 426

def initialize(info)
  headers = {}
  info[0].split("\r\n").each do |line|
    matches = line.match(/^([\w\-]+):(?:\s)*(.*)$/)
    next unless matches
    headers[matches[1].upcase] = matches[2]
  end

  @description_url = headers['LOCATION']
  @server = headers['SERVER']
  @service_type = headers['ST']
  @usn = headers['USN']

  info = info[1]
  @port = info[1]
  @ip = info[2]
end

Instance Attribute Details

#description_urlObject (readonly)

Returns the value of attribute description_url.



410
411
412
# File 'lib/alexa_hue/hue_switch.rb', line 410

def description_url
  @description_url
end

#hardware_versionObject (readonly)

Returns the value of attribute hardware_version.



424
425
426
# File 'lib/alexa_hue/hue_switch.rb', line 424

def hardware_version
  @hardware_version
end

#ipObject (readonly)

Returns the value of attribute ip.



408
409
410
# File 'lib/alexa_hue/hue_switch.rb', line 408

def ip
  @ip
end

#manufacturerObject (readonly)

Returns the value of attribute manufacturer.



416
417
418
# File 'lib/alexa_hue/hue_switch.rb', line 416

def manufacturer
  @manufacturer
end

#manufacturer_urlObject (readonly)

Returns the value of attribute manufacturer_url.



417
418
419
# File 'lib/alexa_hue/hue_switch.rb', line 417

def manufacturer_url
  @manufacturer_url
end

#model_descriptionObject (readonly)

Returns the value of attribute model_description.



420
421
422
# File 'lib/alexa_hue/hue_switch.rb', line 420

def model_description
  @model_description
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



418
419
420
# File 'lib/alexa_hue/hue_switch.rb', line 418

def model_name
  @model_name
end

#model_numberObject (readonly)

Returns the value of attribute model_number.



419
420
421
# File 'lib/alexa_hue/hue_switch.rb', line 419

def model_number
  @model_number
end

#model_urlObject (readonly)

Returns the value of attribute model_url.



421
422
423
# File 'lib/alexa_hue/hue_switch.rb', line 421

def model_url
  @model_url
end

#nameObject (readonly)

Returns the value of attribute name.



415
416
417
# File 'lib/alexa_hue/hue_switch.rb', line 415

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



409
410
411
# File 'lib/alexa_hue/hue_switch.rb', line 409

def port
  @port
end

#serial_numberObject (readonly)

Returns the value of attribute serial_number.



422
423
424
# File 'lib/alexa_hue/hue_switch.rb', line 422

def serial_number
  @serial_number
end

#serverObject (readonly)

Returns the value of attribute server.



411
412
413
# File 'lib/alexa_hue/hue_switch.rb', line 411

def server
  @server
end

#service_typeObject (readonly)

Returns the value of attribute service_type.



412
413
414
# File 'lib/alexa_hue/hue_switch.rb', line 412

def service_type
  @service_type
end

#software_versionObject (readonly)

Returns the value of attribute software_version.



423
424
425
# File 'lib/alexa_hue/hue_switch.rb', line 423

def software_version
  @software_version
end

#url_baseObject (readonly)

Returns the value of attribute url_base.



414
415
416
# File 'lib/alexa_hue/hue_switch.rb', line 414

def url_base
  @url_base
end

#usnObject (readonly)

Returns the value of attribute usn.



413
414
415
# File 'lib/alexa_hue/hue_switch.rb', line 413

def usn
  @usn
end

Instance Method Details

#get_responseObject



444
445
446
# File 'lib/alexa_hue/hue_switch.rb', line 444

def get_response
  Net::HTTP.get_response(URI.parse(description_url)).body
end