philips_hue 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +3 -1
- data/lib/philips_hue.rb +2 -0
- data/lib/philips_hue/helpers.rb +78 -0
- data/lib/philips_hue/light.rb +2 -80
- data/lib/philips_hue/version.rb +1 -1
- data/philips_hue.gemspec +4 -2
- metadata +24 -2
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
philips_hue (0.1.
|
4
|
+
philips_hue (0.1.9)
|
5
5
|
httparty (>= 0.10.0)
|
6
6
|
json (>= 1.6)
|
7
7
|
|
@@ -21,6 +21,7 @@ GEM
|
|
21
21
|
coderay (~> 1.0.5)
|
22
22
|
method_source (~> 0.8)
|
23
23
|
slop (~> 3.4)
|
24
|
+
rake (10.0.2)
|
24
25
|
slop (3.4.3)
|
25
26
|
|
26
27
|
PLATFORMS
|
@@ -30,3 +31,4 @@ DEPENDENCIES
|
|
30
31
|
awesome_print
|
31
32
|
philips_hue!
|
32
33
|
pry
|
34
|
+
rake
|
data/lib/philips_hue.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
module PhilipsHue::Helpers
|
2
|
+
|
3
|
+
def red
|
4
|
+
self.xy = [0.6446, 0.3289]
|
5
|
+
end
|
6
|
+
|
7
|
+
def green
|
8
|
+
self.xy = [0.4034, 0.5067]
|
9
|
+
end
|
10
|
+
|
11
|
+
def blue
|
12
|
+
self.xy = [0.1727, 0.0512]
|
13
|
+
end
|
14
|
+
|
15
|
+
def yellow
|
16
|
+
self.xy = [0.4447, 0.4918]
|
17
|
+
end
|
18
|
+
|
19
|
+
# flash once
|
20
|
+
def blip
|
21
|
+
self.alert = "select"
|
22
|
+
end
|
23
|
+
|
24
|
+
# flash repeatedly
|
25
|
+
def blink
|
26
|
+
self.alert = "lselect"
|
27
|
+
end
|
28
|
+
|
29
|
+
# flash a specified color
|
30
|
+
# xy is the color to use
|
31
|
+
# delay is the length of the flash (in seconds)
|
32
|
+
# crazymode causes the light to blink during the flash
|
33
|
+
def flash(xy, delay = 1, crazymode = false)
|
34
|
+
# use state() and set() to minimize number of API calls
|
35
|
+
original = self.state
|
36
|
+
|
37
|
+
# turns the light on and maxes brightness too
|
38
|
+
flash_state = {
|
39
|
+
:xy => xy,
|
40
|
+
:on => true,
|
41
|
+
:bri => 255
|
42
|
+
}
|
43
|
+
|
44
|
+
# blink instead if the color is not going to change
|
45
|
+
if xy == original["xy"] && original["colormode"] == "xy"
|
46
|
+
flash_state["alert"] = "select"
|
47
|
+
end
|
48
|
+
|
49
|
+
# blink repeatedly if crazymode flag is set
|
50
|
+
# (works best for delay >2 seconds)
|
51
|
+
flash_state["alert"] = "lselect" if crazymode
|
52
|
+
|
53
|
+
# the state to which to restore
|
54
|
+
# (color gets set after)
|
55
|
+
final_state = {
|
56
|
+
:on => original["on"],
|
57
|
+
:bri => original["bri"],
|
58
|
+
:alert => original["alert"]
|
59
|
+
}
|
60
|
+
|
61
|
+
# smartly return to the original color
|
62
|
+
case original["colormode"]
|
63
|
+
when "xy"
|
64
|
+
final_state[:xy] = original["xy"]
|
65
|
+
when "ct"
|
66
|
+
final_state[:ct] = original["ct"]
|
67
|
+
when "hs"
|
68
|
+
final_state[:hue] = original["hue"]
|
69
|
+
end
|
70
|
+
|
71
|
+
# flash!
|
72
|
+
set(flash_state)
|
73
|
+
# zzz...
|
74
|
+
sleep delay
|
75
|
+
# restore the light to its original state
|
76
|
+
set(final_state)
|
77
|
+
end
|
78
|
+
end
|
data/lib/philips_hue/light.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module PhilipsHue
|
2
2
|
class Light
|
3
3
|
|
4
|
+
include Helpers
|
5
|
+
|
4
6
|
def initialize(light_name, light_id, api_endpoint, key)
|
5
7
|
@name = light_name
|
6
8
|
@light_id = light_id
|
@@ -131,86 +133,6 @@ module PhilipsHue
|
|
131
133
|
state["effect"]
|
132
134
|
end
|
133
135
|
|
134
|
-
# cheap helper method
|
135
|
-
def red
|
136
|
-
self.xy = [0.6446, 0.3289]
|
137
|
-
end
|
138
|
-
|
139
|
-
# cheap helper method
|
140
|
-
def green
|
141
|
-
self.xy = [0.4034, 0.5067]
|
142
|
-
end
|
143
|
-
|
144
|
-
# cheap helper method
|
145
|
-
def blue
|
146
|
-
self.xy = [0.1727, 0.0512]
|
147
|
-
end
|
148
|
-
|
149
|
-
# cheap helper method
|
150
|
-
def yellow
|
151
|
-
self.xy = [0.4447, 0.4918]
|
152
|
-
end
|
153
|
-
|
154
|
-
# flash once
|
155
|
-
def blip
|
156
|
-
self.alert = "select"
|
157
|
-
end
|
158
|
-
|
159
|
-
# flash repeatedly
|
160
|
-
def blink
|
161
|
-
self.alert = "lselect"
|
162
|
-
end
|
163
|
-
|
164
|
-
# flash a specified color
|
165
|
-
# xy is the color to use
|
166
|
-
# delay is the length of the flash (in seconds)
|
167
|
-
# crazymode causes the light to blink during the flash
|
168
|
-
def flash(xy, delay = 1, crazymode = false)
|
169
|
-
# use state() and set() to minimize number of API calls
|
170
|
-
original = self.state
|
171
|
-
|
172
|
-
# turns the light on and maxes brightness too
|
173
|
-
flash_state = {
|
174
|
-
:xy => xy,
|
175
|
-
:on => true,
|
176
|
-
:bri => 255
|
177
|
-
}
|
178
|
-
|
179
|
-
# blink instead if the color is not going to change
|
180
|
-
if xy == original["xy"] && original["colormode"] == "xy"
|
181
|
-
flash_state["alert"] = "select"
|
182
|
-
end
|
183
|
-
|
184
|
-
# blink repeatedly if crazymode flag is set
|
185
|
-
# (works best for delay >2 seconds)
|
186
|
-
flash_state["alert"] = "lselect" if crazymode
|
187
|
-
|
188
|
-
# the state to which to restore
|
189
|
-
# (color gets set after)
|
190
|
-
final_state = {
|
191
|
-
:on => original["on"],
|
192
|
-
:bri => original["bri"],
|
193
|
-
:alert => original["alert"]
|
194
|
-
}
|
195
|
-
|
196
|
-
# smartly return to the original color
|
197
|
-
case original["colormode"]
|
198
|
-
when "xy"
|
199
|
-
final_state[:xy] = original["xy"]
|
200
|
-
when "ct"
|
201
|
-
final_state[:ct] = original["ct"]
|
202
|
-
when "hs"
|
203
|
-
final_state[:hue] = original["hue"]
|
204
|
-
end
|
205
|
-
|
206
|
-
# flash!
|
207
|
-
set(flash_state)
|
208
|
-
# zzz...
|
209
|
-
sleep delay
|
210
|
-
# restore the light to its original state
|
211
|
-
set(final_state)
|
212
|
-
end
|
213
|
-
|
214
136
|
# handy aliases
|
215
137
|
alias_method :brightness, :bri
|
216
138
|
alias_method :brightness=, :bri=
|
data/lib/philips_hue/version.rb
CHANGED
data/philips_hue.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'philips_hue/version'
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
5
|
s.name = 'philips_hue'
|
5
6
|
s.version = PhilipsHue::VERSION
|
6
7
|
s.platform = Gem::Platform::RUBY
|
7
|
-
s.date = Time.now.utc.strftime(
|
8
|
+
s.date = Time.now.utc.strftime('%Y-%m-%d')
|
8
9
|
s.summary = 'Philips Hue'
|
9
10
|
s.description = 'A library to control and query Philips Hue lights'
|
10
11
|
s.authors = ['Dana Merrick']
|
@@ -16,5 +17,6 @@ Gem::Specification.new do |s|
|
|
16
17
|
s.add_runtime_dependency 'json', ['>= 1.6']
|
17
18
|
s.add_development_dependency 'awesome_print'
|
18
19
|
s.add_development_dependency 'pry'
|
20
|
+
s.add_development_dependency 'rake'
|
19
21
|
#s.post_install_message = ''
|
20
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philips_hue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: A library to control and query Philips Hue lights
|
79
95
|
email: dana.merrick@gmail.com
|
80
96
|
executables: []
|
@@ -95,6 +111,7 @@ files:
|
|
95
111
|
- bin/sandbox.rb
|
96
112
|
- lib/philips_hue.rb
|
97
113
|
- lib/philips_hue/bridge.rb
|
114
|
+
- lib/philips_hue/helpers.rb
|
98
115
|
- lib/philips_hue/light.rb
|
99
116
|
- lib/philips_hue/version.rb
|
100
117
|
- philips_hue.gemspec
|
@@ -110,12 +127,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
127
|
- - ! '>='
|
111
128
|
- !ruby/object:Gem::Version
|
112
129
|
version: '0'
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: 4383546524838310607
|
113
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
134
|
none: false
|
115
135
|
requirements:
|
116
136
|
- - ! '>='
|
117
137
|
- !ruby/object:Gem::Version
|
118
138
|
version: '0'
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
hash: 4383546524838310607
|
119
142
|
requirements: []
|
120
143
|
rubyforge_project:
|
121
144
|
rubygems_version: 1.8.24
|
@@ -123,4 +146,3 @@ signing_key:
|
|
123
146
|
specification_version: 3
|
124
147
|
summary: Philips Hue
|
125
148
|
test_files: []
|
126
|
-
has_rdoc:
|