Class: SparkleMotion::Hue::SSDP
- Inherits:
-
Object
- Object
- SparkleMotion::Hue::SSDP
- Defined in:
- lib/sparkle_motion/hue/ssdp.rb
Overview
Helpers for SSDP discovery of bridges.
Instance Method Summary collapse
- #scan ⇒ Object
- #ssdp_extract(resp) ⇒ Object
-
#ssdp_response?(resp) ⇒ Boolean
Ensure we’re only getting responses from a Philips Hue bridge.
-
#usn_to_id(usn) ⇒ Object
TODO: With all the hassle around ID and the fact that I’m essentially TODO: coercing it down to just MAC address.…
Instance Method Details
#scan ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/sparkle_motion/hue/ssdp.rb', line 8 def scan raw = Frisky::SSDP .search("IpBridge") .select { |resp| ssdp_response?(resp) } .map { |resp| ssdp_extract(resp) } .select { |resp| resp["name"] == "upnp:rootdevice" } Hash[raw.map { |resp| [resp["id"], resp["ipaddress"]] }] end |
#ssdp_extract(resp) ⇒ Object
27 28 29 30 31 |
# File 'lib/sparkle_motion/hue/ssdp.rb', line 27 def ssdp_extract(resp) { "id" => usn_to_id(resp[:usn]), "name" => resp[:st], "ipaddress" => URI.parse(resp[:location]).host } end |
#ssdp_response?(resp) ⇒ Boolean
Ensure we’re only getting responses from a Philips Hue bridge. The Hue Bridge tends to be obnoxious and announce itself on any SSDP SSDP request, so we assume that we may encounter other obnoxious gear as well…
21 22 23 24 25 |
# File 'lib/sparkle_motion/hue/ssdp.rb', line 21 def ssdp_response?(resp) (resp[:server] || "") .split(/[,\s]+/) .find { |token| token =~ %r{\AIpBridge/\d+(\.\d+)*\z} } end |
#usn_to_id(usn) ⇒ Object
TODO: With all the hassle around ID and the fact that I’m essentially TODO: coercing it down to just MAC address.… Just use the damned IP TODO: or MAC!
36 |
# File 'lib/sparkle_motion/hue/ssdp.rb', line 36 def usn_to_id(usn); usn.split(/:/, 3)[1].split(/-/).last; end |