huey 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,4 +7,6 @@ gem 'chronic'
7
7
 
8
8
  group :development, :test do
9
9
  gem 'timecop'
10
+ gem 'webmock'
11
+ gem 'mocha'
10
12
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- huey (1.1.0)
4
+ huey (1.2.0)
5
5
  chronic (>= 0.9.0)
6
6
  color (>= 1.4.1)
7
7
  eventmachine (>= 1.0.0)
@@ -39,8 +39,8 @@ DEPENDENCIES
39
39
  chronic
40
40
  color-tools
41
41
  huey!
42
- mocha (>= 0.13.1)
42
+ mocha
43
43
  rake
44
44
  timecop
45
- webmock (>= 1.9.0)
45
+ webmock
46
46
  yard (>= 0.8.3)
@@ -14,11 +14,18 @@ You shouldn't need to initialize anything to make Huey work correctly, but if yo
14
14
 
15
15
  ```ruby
16
16
  Huey.configure do |config|
17
+ # Huey now uses the Phillips Hue API to discover local bridges, but you can specify the Hue IP manually if your
18
+ # Huey server is not on your local network.
19
+ config.hue_ip = 123.456.789.012
20
+
21
+ # SSDP is disabled by default.
22
+ config.ssdp = true
23
+
17
24
  # For discovering the Hue hub, usually you won't have to change this
18
- config.ssdp_ip = '239.255.255.250'
25
+ config.ssdp_ip = '239.255.255.250'
19
26
 
20
27
  # Also for discovering the Hue hub
21
- config.ssdp_port = 1900
28
+ config.ssdp_port = 1900
22
29
 
23
30
  # If you get constant errors about not being able to find the Hue hub and you're sure it's connected, increase this
24
31
  config.ssdp_ttl = 1
@@ -72,7 +79,7 @@ For your reference, the attributes on bulb you can change are:
72
79
  - **sat**: For hue/saturation mode. Between `0` and `254`.
73
80
  - **xy**: For CIE 1931 mode. An array of two floats, like: [0.44, 0.4051]
74
81
  - **ct**: For color temperature mode. Expressed in [mireds](http://en.wikipedia.org/wiki/Mired), an integer between `154` and `500`.
75
- - **transitiontime**: An integer. Tenths of a second, so `10` is 1 second, and `100` is 10 seconds. Use `0` for instantaneous transitions.
82
+ - **transitiontime**: An integer. Tenths of a second, so `10` is 1 second, and `100` is 10 seconds. Use `0` for instantaneous transitions.
76
83
 
77
84
  I used [http://rsmck.co.uk/hue](http://rsmck.co.uk/hue) as the source for all this stuff.
78
85
 
@@ -12,6 +12,7 @@ require 'huey/version'
12
12
  require 'huey/config'
13
13
  require 'huey/errors'
14
14
  require 'huey/ssdp'
15
+ require 'huey/portal'
15
16
  require 'huey/request'
16
17
  require 'huey/bulb'
17
18
  require 'huey/group'
@@ -9,9 +9,11 @@ module Huey #:nodoc
9
9
  extend Options
10
10
 
11
11
  # All the default options.
12
+ option :ssdp, default: false
12
13
  option :ssdp_ip, default: '239.255.255.250'
13
14
  option :ssdp_port, default: 1900
14
15
  option :ssdp_ttl, default: 1
16
+ option :hue_ip, default: nil
15
17
  option :uuid, default: '0123456789abdcef0123456789abcdef'
16
18
 
17
19
  # The default logger for Huey: either the Rails logger or just stdout.
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module Huey
4
+ module Portal
5
+ def self.hue_ip
6
+ return @hue_ip if @hue_ip
7
+
8
+ response = HTTParty.get('http://www.meethue.com/api/nupnp').first
9
+
10
+ raise Huey::Errors::CouldNotFindHue if response.nil? || response.empty?
11
+
12
+ @hue_ip = response['internalipaddress']
13
+ end
14
+ end
15
+ end
@@ -7,7 +7,7 @@ module Huey
7
7
  [:get, :post, :put, :delete].each do |method|
8
8
  define_method(method) do |url = '', options = {}|
9
9
  response = HTTParty.send(method,
10
- "http://#{Huey::SSDP.hue_ip}/api/#{Huey::Config.uuid}/#{url}",
10
+ "http://#{self.hue_ip}/api/#{Huey::Config.uuid}/#{url}",
11
11
  options).parsed_response
12
12
 
13
13
  if self.error?(response, 1)
@@ -20,7 +20,7 @@ module Huey
20
20
  end
21
21
 
22
22
  def register
23
- response = HTTParty.post("http://#{Huey::SSDP.hue_ip}/api",
23
+ response = HTTParty.post("http://#{self.hue_ip}/api",
24
24
  body: MultiJson.dump({username: Huey::Config.uuid,
25
25
  devicetype: 'Huey'})).parsed_response
26
26
 
@@ -50,6 +50,16 @@ module Huey
50
50
  end
51
51
  end
52
52
 
53
+
54
+ def hue_ip
55
+ return Huey::Config.hue_ip if Huey::Config.hue_ip
56
+
57
+ if Huey::Config.ssdp
58
+ Huey::SSDP.hue_ip
59
+ else
60
+ Huey::Portal.hue_ip
61
+ end
62
+ end
53
63
  end
54
64
 
55
65
  end
@@ -1,3 +1,3 @@
1
1
  module Huey
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -12,7 +12,7 @@ class Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def set_hue_ip(ip)
15
- Huey::SSDP.instance_variable_set(:@hue_ip, ip)
15
+ Huey::Request.stubs(:hue_ip).returns(ip)
16
16
  end
17
17
 
18
18
  def fake_searcher
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class PortalTest < Test::Unit::TestCase
4
+
5
+ def test_gets_local_bridge_ip
6
+ stub_request(:get, 'http://www.meethue.com/api/nupnp').to_return(body: MultiJson.dump([{"id" => "001788fffe0931a2", "internalipaddress" => "192.168.123.123", "macaddress" => "00:17:88:09:31:a2"}]), headers: {"Content-Type" => 'application/json'})
7
+
8
+ assert_equal Huey::Portal.hue_ip, '192.168.123.123'
9
+
10
+ assert_requested :get, 'http://www.meethue.com/api/nupnp'
11
+ end
12
+
13
+ def test_does_not_find_local_bride
14
+ stub_request(:get, 'http://www.meethue.com/api/nupnp').to_return(body: MultiJson.dump([]), headers: {"Content-Type" => 'application/json'})
15
+
16
+ assert_raises Huey::Errors::CouldNotFindHue do
17
+ Huey::Portal.hue_ip
18
+ end
19
+
20
+ assert_requested :get, 'http://www.meethue.com/api/nupnp'
21
+ end
22
+
23
+ end
@@ -38,4 +38,13 @@ class RequestTest < Test::Unit::TestCase
38
38
 
39
39
  assert_requested :get, "http://0.0.0.0/api/0123456789abdcef0123456789abcdef/"
40
40
  end
41
+
42
+ def test_uses_configured_ip_instead_of_searching
43
+ Huey::Request.unstub(:hue_ip)
44
+ Huey::Config.hue_ip = '123.456.789.012'
45
+
46
+ assert_equal '123.456.789.012', Huey::Request.hue_ip
47
+
48
+ Huey::Config.hue_ip = nil
49
+ end
41
50
  end
@@ -3,8 +3,8 @@ require 'test_helper'
3
3
  class SSDPTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
+ Huey::SSDP.instance_variable_set(:@hue_ip, nil)
6
7
  super
7
- set_hue_ip(nil)
8
8
  end
9
9
 
10
10
  def test_raises_error_with_no_ip
metadata CHANGED
@@ -1,125 +1,142 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Veraticus
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-13 00:00:00.000000000 Z
12
+ date: 2013-05-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: eventmachine
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 1.0.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.0.0
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: httparty
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: 0.9.0
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: 0.9.0
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: chronic
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: 0.9.0
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: 0.9.0
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: color
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - '>='
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: 1.4.1
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - '>='
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: 1.4.1
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: bundler
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - '>='
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: '0'
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - '>='
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: '0'
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: yard
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - '>='
99
+ - - ! '>='
88
100
  - !ruby/object:Gem::Version
89
101
  version: 0.8.3
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - '>='
107
+ - - ! '>='
95
108
  - !ruby/object:Gem::Version
96
109
  version: 0.8.3
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: mocha
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
- - - '>='
115
+ - - ! '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: 0.13.1
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
- - - '>='
123
+ - - ! '>='
109
124
  - !ruby/object:Gem::Version
110
125
  version: 0.13.1
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: webmock
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
- - - '>='
131
+ - - ! '>='
116
132
  - !ruby/object:Gem::Version
117
133
  version: 1.9.0
118
134
  type: :development
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
- - - '>='
139
+ - - ! '>='
123
140
  - !ruby/object:Gem::Version
124
141
  version: 1.9.0
125
142
  description: Everything you could want for making Phillips Hue lightbulbs obey your
@@ -145,6 +162,7 @@ files:
145
162
  - lib/huey/errors.rb
146
163
  - lib/huey/event.rb
147
164
  - lib/huey/group.rb
165
+ - lib/huey/portal.rb
148
166
  - lib/huey/request.rb
149
167
  - lib/huey/ssdp.rb
150
168
  - lib/huey/ssdp/searcher.rb
@@ -155,30 +173,32 @@ files:
155
173
  - test/unit/bulb_test.rb
156
174
  - test/unit/event_test.rb
157
175
  - test/unit/group_test.rb
176
+ - test/unit/portal_test.rb
158
177
  - test/unit/request_test.rb
159
178
  - test/unit/ssdp_test.rb
160
179
  homepage: https://github.com/Veraticus/huey
161
180
  licenses: []
162
- metadata: {}
163
181
  post_install_message:
164
182
  rdoc_options: []
165
183
  require_paths:
166
184
  - lib
167
185
  required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
168
187
  requirements:
169
- - - '>='
188
+ - - ! '>='
170
189
  - !ruby/object:Gem::Version
171
190
  version: 1.9.1
172
191
  required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
173
193
  requirements:
174
- - - '>='
194
+ - - ! '>='
175
195
  - !ruby/object:Gem::Version
176
196
  version: '0'
177
197
  requirements: []
178
198
  rubyforge_project:
179
- rubygems_version: 2.0.0
199
+ rubygems_version: 1.8.23
180
200
  signing_key:
181
- specification_version: 4
201
+ specification_version: 3
182
202
  summary: Quick and simple discovery and control of Phillips Hue lightbulbs
183
203
  test_files: []
184
204
  has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 01536b0adcdaeb163bebe6af4ffff2dc7cce1d1f
4
- data.tar.gz: d66a6dffc76bf8a9bbecd0f4d2e4ecae8011cdf6
5
- SHA512:
6
- metadata.gz: 16f00680f0a1b9dfca733b0e2a261080b077984a03e43bb817360030ec4cc6b9c3f8f4487eed2176fbadda629812cd0b39a07626117f83d356f66968c22ef978
7
- data.tar.gz: 79572a3a755f36b8db109c12d1aea9acaa8246b5749555ea86dcdc5fdef9bf2fd24bd0df5ae5279d6fb930d151acb7e04fc55e1a1c8b5e0b590cd907d3d94a77