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 +4 -4
- data/lib/huemote.rb +2 -2
- data/lib/huemote/bridge.rb +6 -66
- data/lib/huemote/client.rb +7 -7
- data/lib/huemote/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33e0123a389a11d755de13f14aa2f4826ab35f7b
|
4
|
+
data.tar.gz: 2bc12f2992fa4e3611aed8c43f8a80bb7247f115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 019d60ce3b9a6a8631c2fa717ede95b202d93616b1abd7d721de35efbe283a4e59b2c62e3d53bdbefb5f39cae268396df024ca56bf7b02f563b94948f3e25b59
|
7
|
+
data.tar.gz: 7b5afa4964f62c0ded5435a290a2d04abb9f821e57f7066e5819a8ff25f4e3d9eb15170a99a6582071bcbc395188d77fd36cc4724a36bc2cb0e33b2bd38fdd63
|
data/lib/huemote.rb
CHANGED
data/lib/huemote/bridge.rb
CHANGED
@@ -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 ||=
|
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(
|
33
|
-
@bridge = nil
|
16
|
+
def discover(broadcast = '255.255.255.255')
|
34
17
|
client = Huemote::Client.new
|
35
|
-
|
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
|
-
|
42
|
-
end
|
21
|
+
body = client.get("http://#{host}:80/description.xml").body
|
43
22
|
|
44
|
-
|
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
|
|
data/lib/huemote/client.rb
CHANGED
@@ -41,13 +41,13 @@ module Huemote
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
module HTTParty
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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']
|
data/lib/huemote/version.rb
CHANGED
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.
|
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-
|
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:
|