huemote 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9be51c602e6af5ead50c6971f39506a6a5032421
4
- data.tar.gz: 114b210e64560c8a666030a6098e37767da0bc2e
3
+ metadata.gz: 33e0123a389a11d755de13f14aa2f4826ab35f7b
4
+ data.tar.gz: 2bc12f2992fa4e3611aed8c43f8a80bb7247f115
5
5
  SHA512:
6
- metadata.gz: 4b2a0ff35970f5de67a3dc2997370f0cc758200ea12e01224abd329872365555b17ed6350e60af22481d00416efaaa82f0fb6c2097ece58f3c76da56154cfd5a
7
- data.tar.gz: 63f14a307fce18f9cbeaeb9552de0b8612a57547c576ee702f8025a571f6803f192521786af8cb647652b588530782201ea2d2b7c6ead929afe559e44f24bd39
6
+ metadata.gz: 019d60ce3b9a6a8631c2fa717ede95b202d93616b1abd7d721de35efbe283a4e59b2c62e3d53bdbefb5f39cae268396df024ca56bf7b02f563b94948f3e25b59
7
+ data.tar.gz: 7b5afa4964f62c0ded5435a290a2d04abb9f821e57f7066e5819a8ff25f4e3d9eb15170a99a6582071bcbc395188d77fd36cc4724a36bc2cb0e33b2bd38fdd63
@@ -8,8 +8,8 @@ module Huemote
8
8
  require_relative './huemote/bridge'
9
9
 
10
10
  class << self
11
- def discover(socket=nil)
12
- Huemote::Bridge.discover
11
+ def discover(broadcast='255.255.255.255')
12
+ Huemote::Bridge.send(:discover,broadcast)
13
13
  end
14
14
  end
15
15
  end
@@ -5,82 +5,22 @@ module Huemote
5
5
  class Bridge
6
6
  DEVICE_TYPE = "Huemote"
7
7
  USERNAME = "HuemoteRubyGem"
8
- MULTICAST_ADDR = '239.255.255.250'
9
- BIND_ADDR = '0.0.0.0'
10
- PORT = 1900
11
- DISCOVERY= <<-EOF
12
- M-SEARCH * HTTP/1.1\r
13
- HOST: 239.255.255.250:1900\r
14
- MAN: "ssdp:discover"\r
15
- MX: 10\r
16
- ST: urn:schemas-upnp-org:device:Basic:1\r
17
- \r
18
- EOF
19
8
 
20
9
  class << self
21
10
  def get
22
- @bridge ||= begin
23
- client = Huemote::Client.new
24
- body = nil
25
- device = fetch_upnp.detect{|host,port|body = client.get("http://#{host}:#{port}/description.xml").body; body.match('<modelURL>http://www.meethue.com</modelURL>')}
26
- self.new(*device,body)
27
- end
11
+ @bridge ||= discover
28
12
  end
29
13
 
30
14
  private
31
15
 
32
- def discover(socket = nil)
33
- @bridge = nil
16
+ def discover(broadcast = '255.255.255.255')
34
17
  client = Huemote::Client.new
35
- body = nil
36
-
37
- devices, socket = fetch_upnp(true,socket)
38
- device = devices.detect{|host,port|body = client.get("http://#{host}:#{port}/description.xml").body; body.match('<modelURL>http://www.meethue.com</modelURL>')}
39
- @bridge = self.new(*device,body)
18
+ arp = `ping -t 1 #{broadcast} > /dev/null && arp -na | grep 0:17:88`.split("\n")[0]
19
+ host = /\((\d+\.\d+\.\d+\.\d+)\)/.match(arp)[1]
40
20
 
41
- socket
42
- end
21
+ body = client.get("http://#{host}:80/description.xml").body
43
22
 
44
- def ssdp_socket
45
- socket = UDPSocket.new
46
- socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new(BIND_ADDR).hton)
47
- socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_MULTICAST_TTL, 1)
48
- socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1)
49
- socket.bind(BIND_ADDR,PORT)
50
- socket
51
- end
52
-
53
- def listen(socket,devices)
54
- sleep 1
55
- Thread.start do
56
- loop do
57
- message, _ = socket.recvfrom(1024)
58
- match = message.match(/LOCATION:\s+http:\/\/([^\/]+)/)
59
- devices << match[1].split(':') if match
60
- end
61
- end
62
- end
63
-
64
- def fetch_upnp(return_socket=false,socket=nil)
65
- socket ||= ssdp_socket
66
- devices = []
67
-
68
- 3.times { socket.send(DISCOVERY, 0, MULTICAST_ADDR, PORT) }
69
-
70
- # The following is a bit silly, but is necessary for JRuby support,
71
- # which seems to have some issues with socket interruption. If you have
72
- # a working JRuby solution that doesn't require this kind of hackery,
73
- # by all means, submit a pull request!
74
-
75
- listen(socket,devices).tap{|l|sleep 1; l.kill}
76
- devices.uniq!
77
-
78
- if return_socket
79
- [devices,socket]
80
- else
81
- socket.close
82
- devices
83
- end
23
+ @bridge = self.new(host,80,body)
84
24
  end
85
25
  end
86
26
 
@@ -41,13 +41,13 @@ module Huemote
41
41
  end
42
42
  end
43
43
 
44
- module HTTParty
45
- DEPENDENCIES = ['httparty']
46
- def self.extended(base)
47
- base.instance_variable_set(:@lib,::HTTParty)
48
- base.extend(SmartLib)
49
- end
50
- end
44
+ #module HTTParty
45
+ # DEPENDENCIES = ['httparty']
46
+ # def self.extended(base)
47
+ # base.instance_variable_set(:@lib,::HTTParty)
48
+ # base.extend(SmartLib)
49
+ # end
50
+ #end
51
51
 
52
52
  module NetHTTP
53
53
  DEPENDENCIES = ['net/http','uri']
@@ -1,3 +1,3 @@
1
1
  module Huemote
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huemote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gisi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Huemote is a Ruby gem for managing Philips Hue lights
14
14
  email:
@@ -17,8 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gitignore
21
- - .travis.yml
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
22
  - Gemfile
23
23
  - LICENSE.txt
24
24
  - README.md
@@ -35,27 +35,27 @@ homepage: https://github.com/gisikw/huemote
35
35
  licenses:
36
36
  - MIT
37
37
  metadata: {}
38
- post_install_message:
38
+ post_install_message:
39
39
  rdoc_options: []
40
40
  require_paths:
41
41
  - lib
42
42
  required_ruby_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - '>='
49
+ - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubyforge_project:
53
+ rubyforge_project:
54
54
  rubygems_version: 2.2.2
55
- signing_key:
55
+ signing_key:
56
56
  specification_version: 4
57
57
  summary: Huemote is a Ruby gem for managing Philips Hue lights
58
58
  test_files:
59
59
  - spec/huemote/bridge_spec.rb
60
60
  - spec/spec_helper.rb
61
- has_rdoc:
61
+ has_rdoc: