hue_switch 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +56 -0
- data/lib/hue_switch/version.rb +1 -1
- data/lib/hue_switch.rb +87 -63
- metadata +3 -4
- data/.gitignore +0 -9
- data/.travis.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0436b41204a89e0553f8014d4e2e1765f5a72c8b
|
4
|
+
data.tar.gz: 4a0e10572daa901e68c7efaf76285e90f07ed93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa736f8cfdf609b955eaa7111aad12c9f65e14345da7760095153fc10121dd94ef9b2093d59f28f256904210287e85cb569abf6e03222112dd04662bbe0b2c65
|
7
|
+
data.tar.gz: 7b111dc0b67e3445cd9f31a1f0caf0e293dde6a8c2b9a16a3096c08b98da3d2ef39507e5070bec77ddf7e985b53caee737c512ec96e0eefc40dba3ca804ca091
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hue_switch (1.0.5)
|
5
|
+
chronic (~> 0.10.0)
|
6
|
+
chronic_duration (~> 0)
|
7
|
+
httparty (~> 0.13.0)
|
8
|
+
numbers_in_words (~> 0.2.0)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (4.2.4)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
chronic (0.10.2)
|
20
|
+
chronic_duration (0.10.6)
|
21
|
+
numerizer (~> 0.1.1)
|
22
|
+
diff-lcs (1.1.3)
|
23
|
+
httparty (0.13.5)
|
24
|
+
json (~> 1.8)
|
25
|
+
multi_xml (>= 0.5.2)
|
26
|
+
i18n (0.7.0)
|
27
|
+
json (1.8.3)
|
28
|
+
minitest (5.8.0)
|
29
|
+
multi_xml (0.5.5)
|
30
|
+
numbers_in_words (0.2.0)
|
31
|
+
activesupport
|
32
|
+
numerizer (0.1.1)
|
33
|
+
rake (10.4.2)
|
34
|
+
rspec (2.4.0)
|
35
|
+
rspec-core (~> 2.4.0)
|
36
|
+
rspec-expectations (~> 2.4.0)
|
37
|
+
rspec-mocks (~> 2.4.0)
|
38
|
+
rspec-core (2.4.0)
|
39
|
+
rspec-expectations (2.4.0)
|
40
|
+
diff-lcs (~> 1.1.2)
|
41
|
+
rspec-mocks (2.4.0)
|
42
|
+
thread_safe (0.3.5)
|
43
|
+
tzinfo (1.2.2)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 1.9)
|
51
|
+
hue_switch!
|
52
|
+
rake (~> 10.0)
|
53
|
+
rspec (~> 2.4, >= 2.4.0)
|
54
|
+
|
55
|
+
BUNDLED WITH
|
56
|
+
1.10.3
|
data/lib/hue_switch/version.rb
CHANGED
data/lib/hue_switch.rb
CHANGED
@@ -3,13 +3,26 @@ require 'chronic_duration'
|
|
3
3
|
require 'httparty'
|
4
4
|
require 'numbers_in_words'
|
5
5
|
require 'numbers_in_words/duck_punch'
|
6
|
+
require 'timeout'
|
6
7
|
|
7
8
|
class Switch
|
8
9
|
attr_accessor :command, :lights_array, :_group, :body, :schedule_params, :schedule_ids
|
9
10
|
def initialize(command = "", _group = 0, &block)
|
10
11
|
|
11
12
|
@user = "1234567890"
|
12
|
-
|
13
|
+
begin
|
14
|
+
Timeout::timeout(5) {
|
15
|
+
@ip = HTTParty.get("https://www.meethue.com/api/nupnp").first["internalipaddress"]
|
16
|
+
}
|
17
|
+
rescue Timeout::Error
|
18
|
+
"Time Out"
|
19
|
+
rescue NoMethodError
|
20
|
+
"Cannot Find Bridge"
|
21
|
+
rescue Errno::ECONNREFUSED
|
22
|
+
"connection refused"
|
23
|
+
rescue SocketError
|
24
|
+
"Cannot connect to local network"
|
25
|
+
end
|
13
26
|
|
14
27
|
authorize_user
|
15
28
|
populate_switch
|
@@ -23,22 +36,6 @@ class Switch
|
|
23
36
|
instance_eval(&block) if block_given?
|
24
37
|
end
|
25
38
|
|
26
|
-
def authorize_user
|
27
|
-
unless HTTParty.get("http://#{@ip}/api/#{@user}/config").include?("whitelist")
|
28
|
-
if HTTParty.post("http://#{@ip}/api", :body => ({:devicetype => "Hue_Switch", :username=>"1234567890"}).to_json).first.include?("error")
|
29
|
-
raise "You need to press the link button on the bridge and run again"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def populate_switch
|
35
|
-
@colors = {red: 65280, pink: 56100, purple: 52180, violet: 47188, blue: 46920, turquoise: 31146, green: 25500, yellow: 12750, orange: 8618}
|
36
|
-
@mired_colors = {candle: 500, relax: 467, reading: 346, neutral: 300, concentrate: 231, energize: 136}
|
37
|
-
@scenes = [] ; HTTParty.get("http://#{@ip}/api/#{@user}/scenes").keys.each { |k| @scenes.push(k) }
|
38
|
-
@groups = {} ; HTTParty.get("http://#{@ip}/api/#{@user}/groups").each { |k,v| @groups["#{v['name']}".downcase] = k } ; @groups["all"] = "0"
|
39
|
-
@lights = {} ; HTTParty.get("http://#{@ip}/api/#{@user}/lights").each { |k,v| @lights["#{v['name']}".downcase] = k }
|
40
|
-
end
|
41
|
-
|
42
39
|
def hue (numeric_value)
|
43
40
|
clear_attributes
|
44
41
|
self.body[:hue] = numeric_value
|
@@ -51,8 +48,11 @@ class Switch
|
|
51
48
|
|
52
49
|
def color(color_name)
|
53
50
|
clear_attributes
|
54
|
-
@colors.keys.include?(color_name.to_sym)
|
55
|
-
|
51
|
+
if @colors.keys.include?(color_name.to_sym)
|
52
|
+
self.body[:hue] = @colors[color_name.to_sym]
|
53
|
+
else
|
54
|
+
self.body[:ct] = @mired_colors[color_name.to_sym]
|
55
|
+
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def saturation(depth)
|
@@ -149,38 +149,7 @@ class Switch
|
|
149
149
|
|
150
150
|
# Parses times in words (e.g., "eight forty five") to standard HH:MM format
|
151
151
|
|
152
|
-
def
|
153
|
-
numbers.map!(&:in_numbers)
|
154
|
-
numbers.map!(&:to_s)
|
155
|
-
numbers.push("0") if numbers[1] == nil
|
156
|
-
numbers = numbers.shift + ':' + (numbers[0].to_i + numbers[1].to_i).to_s
|
157
|
-
numbers.gsub!(':', ':0') if numbers.split(":")[1].length < 2
|
158
|
-
numbers
|
159
|
-
end
|
160
|
-
|
161
|
-
def parse_time(string)
|
162
|
-
string.sub!(" noon", " twelve in the afternoon")
|
163
|
-
string.sub!("midnight", "twelve in the morning")
|
164
|
-
time_modifier = string.downcase.scan(/(evening)|(night|tonight)|(afternoon)|(pm)|(a.m.)|(morning)|(today)/).flatten.compact.first
|
165
|
-
guess = Time.now.strftime('%H').to_i >= 12 ? "p.m." : "a.m."
|
166
|
-
time_modifier = time_modifier.nil? ? guess : time_modifier
|
167
|
-
day_modifier = string.scan(/(tomorrow)|(next )?(monday|tuesday|wednesday|thursday|friday|saturday|sunday)/).flatten.compact.join(' ')
|
168
|
-
numbers_in_words = string.scan(Regexp.union((1..59).map(&:in_words)))
|
169
|
-
set_time = numbers_to_times(numbers_in_words)
|
170
|
-
set_time = Chronic.parse(day_modifier + ' ' + set_time + ' ' + time_modifier)
|
171
|
-
end
|
172
|
-
|
173
|
-
def set_time(string)
|
174
|
-
if string.scan(/ seconds?| minutes?| hours?| days?| weeks?/).any?
|
175
|
-
set_time = Time.now + ChronicDuration.parse(string)
|
176
|
-
elsif string.scan(/\d/).any?
|
177
|
-
set_time = Chronic.parse(string)
|
178
|
-
else
|
179
|
-
set_time = parse_time(string)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def schedule (on_or_off = :default, string)
|
152
|
+
def schedule (string, on_or_off = :default)
|
184
153
|
self.body[:on] = true if on_or_off == :on
|
185
154
|
self.body[:on] = false if on_or_off == :off
|
186
155
|
set_time = set_time(string)
|
@@ -253,7 +222,24 @@ class Switch
|
|
253
222
|
self.voice command
|
254
223
|
end
|
255
224
|
|
256
|
-
#The rest of the methods allow access to most of the Switch class functionality by supplying a single string
|
225
|
+
#The rest of the methods allow access to most of the Switch class functionality by supplying a single string
|
226
|
+
|
227
|
+
def voice(string)
|
228
|
+
self.reset
|
229
|
+
self.command << string
|
230
|
+
|
231
|
+
parse_voice(string)
|
232
|
+
|
233
|
+
if self.command.include?("schedule")
|
234
|
+
state = string.match(/off|on/)[0].to_sym rescue nil
|
235
|
+
self.send("schedule", *[string, state])
|
236
|
+
else
|
237
|
+
string.include?(' off') ? self.send("off") : self.send("on")
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
private
|
242
|
+
|
257
243
|
def parse_leading(methods)
|
258
244
|
methods.each do |l|
|
259
245
|
capture = (self.command.match (/\b#{l}\s\w+/)).to_s.split(' ')
|
@@ -282,7 +268,6 @@ class Switch
|
|
282
268
|
|
283
269
|
def parse_scene(scene_name)
|
284
270
|
scene_name.gsub!(' ','-') if scene_name.size > 1
|
285
|
-
p scene_name
|
286
271
|
self.send("scene", scene_name)
|
287
272
|
end
|
288
273
|
|
@@ -305,18 +290,57 @@ class Switch
|
|
305
290
|
parse_save_scene if self.command.scan(/save (scene|seen) as/).length > 0
|
306
291
|
end
|
307
292
|
|
308
|
-
def
|
309
|
-
|
310
|
-
|
293
|
+
def numbers_to_times(numbers)
|
294
|
+
numbers.map!(&:in_numbers)
|
295
|
+
numbers.map!(&:to_s)
|
296
|
+
numbers.push("0") if numbers[1] == nil
|
297
|
+
numbers = numbers.shift + ':' + (numbers[0].to_i + numbers[1].to_i).to_s
|
298
|
+
numbers.gsub!(':', ':0') if numbers.split(":")[1].length < 2
|
299
|
+
numbers
|
300
|
+
end
|
311
301
|
|
312
|
-
|
302
|
+
def parse_time(string)
|
303
|
+
string.sub!(" noon", " twelve in the afternoon")
|
304
|
+
string.sub!("midnight", "twelve in the morning")
|
305
|
+
time_modifier = string.downcase.scan(/(evening)|(night|tonight)|(afternoon)|(pm)|(a.m.)|(am)|(p.m.)|(morning)|(today)/).flatten.compact.first
|
306
|
+
guess = Time.now.strftime('%H').to_i >= 12 ? "p.m." : "a.m."
|
307
|
+
time_modifier = time_modifier.nil? ? guess : time_modifier
|
308
|
+
day_modifier = string.scan(/(tomorrow)|(next )?(monday|tuesday|wednesday|thursday|friday|saturday|sunday)/).flatten.compact.join(' ')
|
309
|
+
numbers_in_words = string.scan(Regexp.union((1..59).map(&:in_words)))
|
310
|
+
set_time = numbers_to_times(numbers_in_words)
|
311
|
+
set_time = Chronic.parse(day_modifier + ' ' + set_time + ' ' + time_modifier)
|
312
|
+
end
|
313
313
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
314
|
+
def set_time(string)
|
315
|
+
if string.scan(/ seconds?| minutes?| hours?| days?| weeks?/).any?
|
316
|
+
set_time = string.partition("in").last.strip!
|
317
|
+
set_time = Time.now + ChronicDuration.parse(string)
|
318
|
+
elsif string.scan(/\d/).any?
|
319
|
+
set_time = string.partition("at").last.strip!
|
320
|
+
set_time = Chronic.parse(set_time)
|
318
321
|
else
|
319
|
-
|
320
|
-
|
322
|
+
set_time = string.partition("at").last.strip!
|
323
|
+
set_time = parse_time(set_time)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def authorize_user
|
328
|
+
begin
|
329
|
+
unless HTTParty.get("http://#{@ip}/api/#{@user}/config").include?("whitelist")
|
330
|
+
if HTTParty.post("http://#{@ip}/api", :body => ({:devicetype => "Hue_Switch", :username=>"1234567890"}).to_json).first.include?("error")
|
331
|
+
raise "You need to press the link button on the bridge and run again"
|
332
|
+
end
|
333
|
+
end
|
334
|
+
rescue Errno::ECONNREFUSED
|
335
|
+
"Cannot Reach Bridge"
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
def populate_switch
|
340
|
+
@colors = {red: 65280, pink: 56100, purple: 52180, violet: 47188, blue: 46920, turquoise: 31146, green: 25500, yellow: 12750, orange: 8618}
|
341
|
+
@mired_colors = {candle: 500, relax: 467, reading: 346, neutral: 300, concentrate: 231, energize: 136}
|
342
|
+
@scenes = [] ; HTTParty.get("http://#{@ip}/api/#{@user}/scenes").keys.each { |k| @scenes.push(k) }
|
343
|
+
@groups = {} ; HTTParty.get("http://#{@ip}/api/#{@user}/groups").each { |k,v| @groups["#{v['name']}".downcase] = k } ; @groups["all"] = "0"
|
344
|
+
@lights = {} ; HTTParty.get("http://#{@ip}/api/#{@user}/lights").each { |k,v| @lights["#{v['name']}".downcase] = k }
|
321
345
|
end
|
322
346
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hue_switch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sarkonovich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -122,9 +122,8 @@ executables: []
|
|
122
122
|
extensions: []
|
123
123
|
extra_rdoc_files: []
|
124
124
|
files:
|
125
|
-
- ".gitignore"
|
126
|
-
- ".travis.yml"
|
127
125
|
- Gemfile
|
126
|
+
- Gemfile.lock
|
128
127
|
- README.md
|
129
128
|
- Rakefile
|
130
129
|
- bin/console
|
data/.gitignore
DELETED
data/.travis.yml
DELETED