hue-lib 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/hue-lib.gemspec +1 -1
- data/lib/hue/bridge.rb +20 -10
- data/lib/hue/bulb.rb +27 -15
- data/spec/hue/bridge_spec.rb +5 -0
- data/spec/hue/bulb_spec.rb +6 -0
- data/spec/json/application_uuid/lights/post_success.json +7 -0
- metadata +3 -2
data/hue-lib.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "hue-lib"
|
6
|
-
s.version = '0.7.
|
6
|
+
s.version = '0.7.1'
|
7
7
|
s.authors = ["Birkir A. Barkarson", "Aaron Hurley"]
|
8
8
|
s.email = ["birkirb@stoicviking.net"]
|
9
9
|
s.homepage = "https://github.com/birkirb/hue-lib"
|
data/lib/hue/bridge.rb
CHANGED
@@ -18,6 +18,10 @@ module Hue
|
|
18
18
|
index(uri)
|
19
19
|
end
|
20
20
|
|
21
|
+
def add_lights
|
22
|
+
create(uri('lights'))
|
23
|
+
end
|
24
|
+
|
21
25
|
def lights
|
22
26
|
index(uri('lights'))
|
23
27
|
end
|
@@ -35,7 +39,6 @@ module Hue
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def bulbs
|
38
|
-
# puts status['lights'].inspect
|
39
42
|
@bulbs ||= lights.keys.map { |b| Bulb.new(self, b) }
|
40
43
|
end
|
41
44
|
|
@@ -50,14 +53,6 @@ module Hue
|
|
50
53
|
# ids.each{|x| remove_schedule x}
|
51
54
|
# end
|
52
55
|
|
53
|
-
def get_light_state(id)
|
54
|
-
index(uri('lights', id))
|
55
|
-
end
|
56
|
-
|
57
|
-
def set_light_state(id, state)
|
58
|
-
update(uri('lights', id, 'state'), state)
|
59
|
-
end
|
60
|
-
|
61
56
|
def register
|
62
57
|
create(URI.parse(bridge_uri),
|
63
58
|
{"username" => application_id, "devicetype" => Hue.device_type})
|
@@ -67,6 +62,18 @@ module Hue
|
|
67
62
|
delete(uri('config', 'whitelist', application_id))
|
68
63
|
end
|
69
64
|
|
65
|
+
def get_light(id)
|
66
|
+
index(uri('lights', id))
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_light(id, property)
|
70
|
+
update(uri('lights', id), property)
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_light_state(id, state)
|
74
|
+
update(uri('lights', id, 'state'), state)
|
75
|
+
end
|
76
|
+
|
70
77
|
private
|
71
78
|
|
72
79
|
def uri(*args)
|
@@ -95,7 +102,10 @@ module Hue
|
|
95
102
|
Hue.logger.info("Sending #{payload.to_s if payload} to #{url.to_s}")
|
96
103
|
response = nil
|
97
104
|
begin
|
98
|
-
|
105
|
+
http = Net::HTTP.new(url.host, url.port)
|
106
|
+
http.open_timeout = 3 # Quick timeout on connection fail.
|
107
|
+
http.read_timeout = 10 # Slower timeout on read fail, but way faster than the default.
|
108
|
+
response = http.start { |http| http.request(request) }
|
99
109
|
rescue => err
|
100
110
|
Hue.logger.error(err.message)
|
101
111
|
raise Hue::Error.new("Problem reaching bridge.", err)
|
data/lib/hue/bulb.rb
CHANGED
@@ -21,7 +21,7 @@ module Hue
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def refresh!
|
24
|
-
@status = bridge.
|
24
|
+
@status = bridge.get_light(id)
|
25
25
|
end
|
26
26
|
|
27
27
|
def info
|
@@ -55,12 +55,12 @@ module Hue
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def on
|
58
|
-
|
58
|
+
update_state(on: true)
|
59
59
|
on?
|
60
60
|
end
|
61
61
|
|
62
62
|
def off
|
63
|
-
|
63
|
+
update_state(on: false)
|
64
64
|
off?
|
65
65
|
end
|
66
66
|
|
@@ -72,9 +72,9 @@ module Hue
|
|
72
72
|
|
73
73
|
def brightness=(bri)
|
74
74
|
if scale = Hue.percent_to_unit_interval(bri)
|
75
|
-
|
75
|
+
update_state(bri: (scale * BRIGHTNESS_MAX).round)
|
76
76
|
else
|
77
|
-
|
77
|
+
update_state(bri: bri.to_i)
|
78
78
|
end
|
79
79
|
brightness
|
80
80
|
end
|
@@ -100,7 +100,7 @@ module Hue
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def color=(col)
|
103
|
-
|
103
|
+
update_state(col.to_hash)
|
104
104
|
set_color
|
105
105
|
end
|
106
106
|
|
@@ -113,16 +113,17 @@ module Hue
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def blink
|
116
|
-
|
116
|
+
update_state(alert: 'lselect')
|
117
117
|
end
|
118
118
|
|
119
119
|
def solid
|
120
|
-
|
120
|
+
update_state(alert: 'none')
|
121
121
|
end
|
122
122
|
|
123
123
|
def flash
|
124
|
-
|
125
|
-
update
|
124
|
+
update_state(alert: 'select')
|
125
|
+
# immediately update to expected state
|
126
|
+
@status['state']['alert'] = 'none'
|
126
127
|
end
|
127
128
|
|
128
129
|
def transition_time
|
@@ -145,12 +146,23 @@ module Hue
|
|
145
146
|
@color = Colors.parse_state(state)
|
146
147
|
end
|
147
148
|
|
148
|
-
def
|
149
|
+
def update_state(settings = {})
|
149
150
|
if bridge.set_light_state(id, options.merge(settings))
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
set_status(settings, 'state')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def update(settings = {})
|
156
|
+
if bridge.set_light(id, settings)
|
157
|
+
set_status(settings)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def set_status(settings, key = nil)
|
162
|
+
if @status
|
163
|
+
status = key ? @status[key] : @status
|
164
|
+
settings.each do |key, value|
|
165
|
+
status[key.to_s] = value
|
154
166
|
end
|
155
167
|
end
|
156
168
|
end
|
data/spec/hue/bridge_spec.rb
CHANGED
@@ -50,6 +50,11 @@ describe Hue::Bridge do
|
|
50
50
|
with_fake_delete("config/whitelist/#{TEST_APPLICATION_UUID}")
|
51
51
|
bridge.unregister
|
52
52
|
end
|
53
|
+
|
54
|
+
it 'should allow scanning for new lights' do
|
55
|
+
with_fake_post("#{TEST_APPLICATION_UUID}/lights")
|
56
|
+
bridge.add_lights
|
57
|
+
end
|
53
58
|
end
|
54
59
|
|
55
60
|
context 'when instantiated with a new config' do
|
data/spec/hue/bulb_spec.rb
CHANGED
@@ -62,6 +62,12 @@ describe Hue::Bulb do
|
|
62
62
|
bulb.off.should be_true
|
63
63
|
end
|
64
64
|
|
65
|
+
it 'should allow changing the name' do
|
66
|
+
with_fake_update('lights/1', name: 'New name')
|
67
|
+
bulb.name = 'New name'
|
68
|
+
bulb.name.should == 'New name'
|
69
|
+
end
|
70
|
+
|
65
71
|
it 'should allow setting hue, saturation and brightness' do
|
66
72
|
color = Hue::Colors::HueSaturation.new(21845, 1293)
|
67
73
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hue-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-02-
|
13
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- spec/hue/config/application_spec.rb
|
119
119
|
- spec/hue/config/bridge_spec.rb
|
120
120
|
- spec/hue_spec.rb
|
121
|
+
- spec/json/application_uuid/lights/post_success.json
|
121
122
|
- spec/json/config.json
|
122
123
|
- spec/json/config/whitelist/application_uuid/delete_success.json
|
123
124
|
- spec/json/get_success.json
|