huey 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01536b0adcdaeb163bebe6af4ffff2dc7cce1d1f
4
+ data.tar.gz: d66a6dffc76bf8a9bbecd0f4d2e4ecae8011cdf6
5
+ SHA512:
6
+ metadata.gz: 16f00680f0a1b9dfca733b0e2a261080b077984a03e43bb817360030ec4cc6b9c3f8f4487eed2176fbadda629812cd0b39a07626117f83d356f66968c22ef978
7
+ data.tar.gz: 79572a3a755f36b8db109c12d1aea9acaa8246b5749555ea86dcdc5fdef9bf2fd24bd0df5ae5279d6fb930d151acb7e04fc55e1a1c8b5e0b590cd907d3d94a77
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- huey (1.0.1)
4
+ huey (1.1.0)
5
5
  chronic (>= 0.9.0)
6
6
  color (>= 1.4.1)
7
7
  eventmachine (>= 1.0.0)
@@ -11,7 +11,7 @@ GEM
11
11
  remote: http://rubygems.org/
12
12
  specs:
13
13
  addressable (2.3.2)
14
- chronic (0.9.0)
14
+ chronic (0.9.1)
15
15
  color (1.4.1)
16
16
  color-tools (1.3.0)
17
17
  crack (0.3.1)
@@ -22,7 +22,7 @@ GEM
22
22
  metaclass (0.0.1)
23
23
  mocha (0.13.1)
24
24
  metaclass (~> 0.0.1)
25
- multi_json (1.6.1)
25
+ multi_json (1.7.2)
26
26
  multi_xml (0.5.3)
27
27
  rake (0.9.5)
28
28
  timecop (0.5.9.2)
@@ -58,6 +58,8 @@ bulb.update(bri: 100, ct: 500) # Set and save in one step
58
58
  bulb.rgb = '#8FF1F5' # Everyone loves aqua
59
59
 
60
60
  bulb.commit # Alias for save
61
+
62
+ bulb.reload # Refresh changes to the bulb, made perhaps with another app
61
63
  ```
62
64
 
63
65
  Changes to the bulb only take effect when you call `save` on it. If you prefer, `save` is aliased as `commit`.
@@ -157,6 +159,12 @@ The SSDP discovery driver is lifted whole cloth from turboladen's [UPNP](https:/
157
159
 
158
160
  I am not affiliated with Phillips or the Phillips Hue in any way. I just think it's neat. While this Gem works for me, if it causes your lights to catastrophically fail it's not my fault. (Though I think the chances of this happening are pretty unlikely, you never know.)
159
161
 
162
+ ## Contributors
163
+
164
+ Many thanks to the following diligent contributors, without whom this project would not be nearly as awesome:
165
+
166
+ * [sankage](https://github.com/sankage)
167
+
160
168
  ## Copyright
161
169
 
162
170
  Copyright (c) 2012 Josh Symonds.
@@ -24,7 +24,7 @@ module Huey
24
24
  block_given? ? yield(Huey::Config) : Huey::Config
25
25
  end
26
26
  alias :config :configure
27
-
27
+
28
28
  def logger
29
29
  Huey::Config.logger
30
30
  end
@@ -26,9 +26,17 @@ module Huey
26
26
  @changes = {}
27
27
  @name = hash['name']
28
28
 
29
+ reload(hash)
30
+ end
31
+
32
+ def reload(hash = nil)
33
+ hash ||= Huey::Request.get("lights/#{self.id}")
34
+
29
35
  (Huey::Bulb::ATTRIBUTES - [:name]).each do |attribute|
30
36
  instance_variable_set("@#{attribute}".to_sym, hash['state'][attribute.to_s])
31
37
  end
38
+
39
+ self
32
40
  end
33
41
 
34
42
  Huey::Bulb::ATTRIBUTES.each do |attribute|
@@ -103,6 +111,7 @@ module Huey
103
111
  end
104
112
 
105
113
  def alert!
114
+ self.update(alert: 'none') if self.alert != 'none'
106
115
  self.update(alert: 'select')
107
116
  end
108
117
 
@@ -44,7 +44,7 @@ module Huey #:nodoc
44
44
  def #{name}?
45
45
  #{name}
46
46
  end
47
-
47
+
48
48
  def reset_#{name}
49
49
  settings[#{name.inspect}] = defaults[#{name.inspect}]
50
50
  end
@@ -1,19 +1,30 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Huey
4
-
5
4
  # All the error specific to Huey.
6
5
  module Errors
7
-
6
+
8
7
  # Generic error class.
9
8
  class Error < StandardError; end
10
-
9
+
11
10
  # CouldNotFindHub is raised when no IP address can be found for Hue.
12
- class CouldNotFindHue < Error; end
11
+ class CouldNotFindHue < Error; end
13
12
 
14
13
  # PressLinkButton is raised if the link button hasn't been pressed yet.
15
14
  class PressLinkButton < Error; end
16
15
 
16
+ # The bulb can't be updated since it is off
17
+ class BulbOff < Error; end
18
+
19
+ # Cannot add bulb to group since it is full
20
+ class GroupTableFull < Error; end
21
+
22
+ # Cannot make request due to missing parameters
23
+ class MissingParameters < Error; end
24
+
25
+ # Error occured in the bridge, not the request
26
+ class InternalBridgeError < Error; end
27
+
17
28
  # HueResponseError is raised if we receive an odd response from the Hue.
18
29
  class HueResponseError < Error; end
19
30
  end
@@ -14,7 +14,7 @@ module Huey
14
14
  value.each do |k, v|
15
15
  options[k.to_sym] = v
16
16
  end
17
-
17
+
18
18
  Huey::Event.new(options)
19
19
  end
20
20
  Huey::Event.all
@@ -1,18 +1,18 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Huey
4
-
5
4
  # Wraps requests to the actual Hue itself
6
5
  class Request
7
6
  class << self
8
-
9
7
  [:get, :post, :put, :delete].each do |method|
10
8
  define_method(method) do |url = '', options = {}|
11
- response = HTTParty.send(method, "http://#{Huey::SSDP.hue_ip}/api/#{Huey::Config.uuid}/#{url}", options).parsed_response
9
+ response = HTTParty.send(method,
10
+ "http://#{Huey::SSDP.hue_ip}/api/#{Huey::Config.uuid}/#{url}",
11
+ options).parsed_response
12
12
 
13
13
  if self.error?(response, 1)
14
14
  self.register
15
- return self.send(method, url, options)
15
+ return self.send(method, url, options)
16
16
  end
17
17
 
18
18
  response
@@ -20,7 +20,9 @@ module Huey
20
20
  end
21
21
 
22
22
  def register
23
- response = HTTParty.post("http://#{Huey::SSDP.hue_ip}/api", body: MultiJson.dump({username: Huey::Config.uuid, devicetype: 'Huey'})).parsed_response
23
+ response = HTTParty.post("http://#{Huey::SSDP.hue_ip}/api",
24
+ body: MultiJson.dump({username: Huey::Config.uuid,
25
+ devicetype: 'Huey'})).parsed_response
24
26
 
25
27
  raise Huey::Errors::PressLinkButton, 'Press the link button and try your request again' if self.error?(response, 101)
26
28
 
@@ -32,7 +34,18 @@ module Huey
32
34
  if response.first['error']['type'] == type
33
35
  true
34
36
  else
35
- raise Huey::Errors::HueResponseError, response
37
+ case response.first['error']['type']
38
+ when 5
39
+ raise Huey::Errors::MissingParameters, response
40
+ when 201
41
+ raise Huey::Errors::BulbOff, response
42
+ when 301..302
43
+ raise Huey::Errors::GroupTableFull, response
44
+ when 901
45
+ raise Huey::Errors::InternalBridgeError, response
46
+ else
47
+ raise Huey::Errors::HueResponseError, response
48
+ end
36
49
  end
37
50
  end
38
51
  end
@@ -1,3 +1,3 @@
1
1
  module Huey
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -27,6 +27,15 @@ class BulbTest < Test::Unit::TestCase
27
27
  @bulb.alert!
28
28
  end
29
29
 
30
+ def test_send_second_alert_to_bulb
31
+ @bulb.alert = 'select'
32
+
33
+ Huey::Request.expects(:put).with("lights/1/state", body: MultiJson.dump({alert: 'none'})).once.returns(true)
34
+ Huey::Request.expects(:put).with("lights/1/state", body: MultiJson.dump({alert: 'select'})).once.returns(true)
35
+
36
+ @bulb.alert!
37
+ end
38
+
30
39
  def test_bulb_get_attributes
31
40
  Huey::Bulb::ATTRIBUTES.each do |attr|
32
41
  assert @bulb.respond_to?(attr), "#{attr} is not set"
@@ -76,4 +85,16 @@ class BulbTest < Test::Unit::TestCase
76
85
  assert_equal 245, @bulb.bri
77
86
  end
78
87
 
88
+ def test_refresh_state
89
+ response = light_response('2', 'Bedroom').values.first
90
+ response['state'].merge!('on' => true)
91
+ Huey::Request.expects(:get).once.returns(response)
92
+
93
+ @bulb = Huey::Bulb.find(2)
94
+ assert_equal false, @bulb.on
95
+
96
+ @bulb.reload
97
+ assert_equal true, @bulb.on
98
+ end
99
+
79
100
  end
metadata CHANGED
@@ -1,142 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Veraticus
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-14 00:00:00.000000000 Z
11
+ date: 2013-04-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: eventmachine
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: httparty
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.9.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.9.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: chronic
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.9.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.9.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: color
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: 1.4.1
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: 1.4.1
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: yard
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: 0.8.3
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: 0.8.3
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: mocha
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: 0.13.1
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: 0.13.1
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: webmock
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: 1.9.0
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
140
123
  - !ruby/object:Gem::Version
141
124
  version: 1.9.0
142
125
  description: Everything you could want for making Phillips Hue lightbulbs obey your
@@ -176,27 +159,26 @@ files:
176
159
  - test/unit/ssdp_test.rb
177
160
  homepage: https://github.com/Veraticus/huey
178
161
  licenses: []
162
+ metadata: {}
179
163
  post_install_message:
180
164
  rdoc_options: []
181
165
  require_paths:
182
166
  - lib
183
167
  required_ruby_version: !ruby/object:Gem::Requirement
184
- none: false
185
168
  requirements:
186
- - - ! '>='
169
+ - - '>='
187
170
  - !ruby/object:Gem::Version
188
171
  version: 1.9.1
189
172
  required_rubygems_version: !ruby/object:Gem::Requirement
190
- none: false
191
173
  requirements:
192
- - - ! '>='
174
+ - - '>='
193
175
  - !ruby/object:Gem::Version
194
176
  version: '0'
195
177
  requirements: []
196
178
  rubyforge_project:
197
- rubygems_version: 1.8.23
179
+ rubygems_version: 2.0.0
198
180
  signing_key:
199
- specification_version: 3
181
+ specification_version: 4
200
182
  summary: Quick and simple discovery and control of Phillips Hue lightbulbs
201
183
  test_files: []
202
184
  has_rdoc: