alexa_hue 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/alexa_hue.gemspec +1 -1
- data/lib/alexa_hue/custom_slots.rb +4 -6
- data/lib/alexa_hue/hue_switch.rb +12 -38
- data/lib/alexa_hue/intent_schema.rb +4 -6
- data/lib/alexa_hue/sample_utterances.rb +4 -6
- data/lib/alexa_hue/version.rb +3 -4
- data/lib/alexa_hue.rb +55 -106
- metadata +2 -3
- data/lib/alexa_hue/endpoint.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 939ace937c9a84b49de17edb7195b74a5a6dc433
|
4
|
+
data.tar.gz: de31f09e481c0b904f704ec7b33a3349aa0f0827
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c375f8c8205baf13a4d7b7b055bc8778bb96a2826b18a0ba6f00d30603a9f0bb839f8078e36006ac4de429b40a78d7454bf3b1897c5e818f8dbc4ed014e5fd98
|
7
|
+
data.tar.gz: 8033ac7150f3fb23608e593d3c26e9d79862fedb7b86e4aa0d059027c19910e38d78ac89bdf86ba61e59b99769da5540e9daacc0dfc9413a79c31d0dcba91a9f
|
data/alexa_hue.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'alexa_hue/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "alexa_hue"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Hue::VERSION
|
9
9
|
spec.authors = ["Kyle Lucas"]
|
10
10
|
spec.email = ["kglucas93@gmail.com"]
|
11
11
|
spec.summary = %q{A sinatra middleware for alexa hue actions.}
|
@@ -1,7 +1,5 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
File.read(File.expand_path('../../../skills_config/custom_slots.txt', __FILE__))
|
5
|
-
end
|
1
|
+
module Hue
|
2
|
+
def self.custom_slots
|
3
|
+
File.read(File.expand_path('../../../skills_config/custom_slots.txt', __FILE__))
|
6
4
|
end
|
7
|
-
end
|
5
|
+
end
|
data/lib/alexa_hue/hue_switch.rb
CHANGED
@@ -10,7 +10,6 @@ require 'numbers_in_words'
|
|
10
10
|
require 'numbers_in_words/duck_punch'
|
11
11
|
require 'timeout'
|
12
12
|
|
13
|
-
module Sinatra
|
14
13
|
module Hue
|
15
14
|
module_function
|
16
15
|
|
@@ -26,24 +25,14 @@ module Hue
|
|
26
25
|
class Switch
|
27
26
|
attr_accessor :command, :lights_array, :_group, :body, :schedule_params, :schedule_ids
|
28
27
|
def initialize(command = "", _group = 0, &block)
|
29
|
-
|
30
28
|
@user = "1234567890"
|
31
|
-
begin
|
32
|
-
@ip = HTTParty.get("https://www.meethue.com/api/nupnp").first["internalipaddress"] rescue nil
|
33
|
-
if @ip.nil?
|
34
|
-
bridge = get_bridge_by_SSDP
|
35
|
-
@ip = bridge.ip
|
36
|
-
end
|
37
29
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
rescue SocketError
|
45
|
-
puts "Cannot connect to local network"
|
46
|
-
end
|
30
|
+
begin
|
31
|
+
@ip = HTTParty.get("https://www.meethue.com/api/nupnp").first["internalipaddress"] rescue nil
|
32
|
+
@ip ||= get_bridge_by_SSDP.ip
|
33
|
+
rescue
|
34
|
+
puts "Cannot connect to bridge."
|
35
|
+
end
|
47
36
|
|
48
37
|
authorize_user
|
49
38
|
populate_switch
|
@@ -58,16 +47,12 @@ module Hue
|
|
58
47
|
end
|
59
48
|
|
60
49
|
def list_lights
|
61
|
-
|
62
|
-
HTTParty.get("http://#{@ip}/api/#{@user}/lights").each { |k,v| light_list["#{v['name']}".downcase] = k }
|
63
|
-
light_list
|
50
|
+
HTTParty.get("http://#{@ip}/api/#{@user}/lights").map{|k,v|[k,"#{v['name']}".downcase]}.to_h
|
64
51
|
end
|
65
52
|
|
66
53
|
def list_groups
|
67
|
-
|
68
|
-
|
69
|
-
group_list["all"] = "0"
|
70
|
-
group_list
|
54
|
+
HTTParty.get("http://#{@ip}/api/#{@user}/groups").map{|k,v|[k,"#{v['name']}".downcase]}.to_h.merge("all" =>
|
55
|
+
"0")
|
71
56
|
end
|
72
57
|
|
73
58
|
def list_scenes
|
@@ -111,9 +96,7 @@ module Hue
|
|
111
96
|
end
|
112
97
|
|
113
98
|
def clear_attributes
|
114
|
-
self.body.
|
115
|
-
self.body.delete(:ct)
|
116
|
-
self.body.delete(:hue)
|
99
|
+
self.body.delete_if{|k|[:scene,:ct,:hue].include?(k)}
|
117
100
|
end
|
118
101
|
|
119
102
|
def fade(in_seconds)
|
@@ -143,19 +126,17 @@ module Hue
|
|
143
126
|
end
|
144
127
|
|
145
128
|
def confirm
|
146
|
-
|
147
|
-
HTTParty.put("http://#{@ip}/api/#{@user}/groups/0/action" , :body => params.to_json)
|
129
|
+
HTTParty.put("http://#{@ip}/api/#{@user}/groups/0/action" , :body => {:alert => 'select'}.to_json)
|
148
130
|
end
|
149
131
|
|
150
132
|
def save_scene(scene_name)
|
151
|
-
scene_name.gsub!(' ','-')
|
152
133
|
self.fade 2 if self.body[:transitiontime] == nil
|
153
134
|
if self._group.empty?
|
154
135
|
light_group = HTTParty.get("http://#{@ip}/api/#{@user}/groups/0")["lights"]
|
155
136
|
else
|
156
137
|
light_group = HTTParty.get("http://#{@ip}/api/#{@user}/groups/#{self._group}")["lights"]
|
157
138
|
end
|
158
|
-
params = {name: scene_name, lights: light_group, transitiontime: self.body[:transitiontime]}
|
139
|
+
params = {name: scene_name.gsub!(' ','-'), lights: light_group, transitiontime: self.body[:transitiontime]}
|
159
140
|
response = HTTParty.put("http://#{@ip}/api/#{@user}/scenes/#{scene_name}", :body => params.to_json)
|
160
141
|
confirm if response.first.keys[0] == "success"
|
161
142
|
end
|
@@ -174,7 +155,6 @@ module Hue
|
|
174
155
|
elsif self.body[:on] == false
|
175
156
|
# turn off individual lights in the scene
|
176
157
|
(HTTParty.get("http://#{@ip}/api/#{@user}/scenes"))[self.body[:scene]]["lights"].each do |l|
|
177
|
-
puts self.body
|
178
158
|
HTTParty.put("http://#{@ip}/api/#{@user}/lights/#{l}/state", :body => (self.body).to_json)
|
179
159
|
end
|
180
160
|
end
|
@@ -272,7 +252,6 @@ module Hue
|
|
272
252
|
#The rest of the methods allow access to most of the Switch class functionality by supplying a single string
|
273
253
|
|
274
254
|
def voice(string)
|
275
|
-
puts string
|
276
255
|
self.reset
|
277
256
|
self.command << string
|
278
257
|
|
@@ -400,10 +379,6 @@ module Hue
|
|
400
379
|
end
|
401
380
|
end
|
402
381
|
|
403
|
-
|
404
|
-
# The Device and SSDP classes are basically lifted from Sam Soffes' great GitHub repo:
|
405
|
-
# https://github.com/soffes/discover.
|
406
|
-
|
407
382
|
class Device
|
408
383
|
attr_reader :ip
|
409
384
|
attr_reader :port
|
@@ -521,4 +496,3 @@ module Hue
|
|
521
496
|
end
|
522
497
|
end
|
523
498
|
end
|
524
|
-
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
File.read(File.expand_path('../../../skills_config/intent_schema.txt', __FILE__))
|
5
|
-
end
|
1
|
+
module Hue
|
2
|
+
def self.intent_schema
|
3
|
+
File.read(File.expand_path('../../../skills_config/intent_schema.txt', __FILE__))
|
6
4
|
end
|
7
|
-
end
|
5
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
File.read(File.expand_path('../../../skills_config/sample_utterances.txt', __FILE__))
|
5
|
-
end
|
1
|
+
module Hue
|
2
|
+
def self.sample_utterances
|
3
|
+
File.read(File.expand_path('../../../skills_config/sample_utterances.txt', __FILE__))
|
6
4
|
end
|
7
|
-
end
|
5
|
+
end
|
data/lib/alexa_hue/version.rb
CHANGED
data/lib/alexa_hue.rb
CHANGED
@@ -14,131 +14,80 @@ require 'alexa_hue/fix_schedule_syntax'
|
|
14
14
|
|
15
15
|
LEVELS = {} ; [*1..10].each { |t| LEVELS[t.to_s ] = t.in_words }
|
16
16
|
|
17
|
-
module Sinatra
|
18
|
-
module Hue
|
19
|
-
def self.registered(app)
|
20
|
-
app.post '/alexa_hue' do
|
21
|
-
content_type :json
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
# Behavior for Launch Request
|
26
|
-
if @echo_request.launch_request?
|
27
|
-
response = AlexaObjects::Response.new
|
28
|
-
response.spoken_response = "I'm ready to control the lights"
|
29
|
-
response.end_session = false
|
30
|
-
response.without_card.to_json
|
31
|
-
|
32
|
-
# Behavior for ControlLights intent. Keys and values need to be adjusted a bit to work with HueSwitch #voice syntax.
|
33
|
-
elsif @echo_request.intent_name == "ControlLights"
|
34
|
-
if @echo_request.slots.brightness
|
35
|
-
LEVELS.keys.reverse_each { |level| @echo_request.slots.brightness.sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
|
36
|
-
end
|
18
|
+
module Hue
|
19
|
+
extend Sinatra::Extension
|
37
20
|
|
38
|
-
|
39
|
-
|
40
|
-
|
21
|
+
helpers do
|
22
|
+
def control_lights
|
23
|
+
if @echo_request.slots.brightness
|
24
|
+
LEVELS.keys.reverse_each { |level| @echo_request.slots.brightness.sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
|
25
|
+
end
|
41
26
|
|
42
|
-
|
43
|
-
@echo_request.slots.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
fix_schedule_syntax(@string)
|
60
|
-
@string.sub!("color loop", "colorloop")
|
61
|
-
@string.strip!
|
62
|
-
|
63
|
-
begin
|
64
|
-
switch = Hue::Switch.new
|
65
|
-
rescue RuntimeError
|
66
|
-
response = AlexaObjects::Response.new
|
67
|
-
response.end_session = true
|
68
|
-
response.spoken_response = "Hello. Before using Hue lighting, you'll need to give me access to your Hue bridge." +
|
69
|
-
" Please press the link button on your bridge and launch the skill again within ten seconds."
|
70
|
-
halt response.without_card.to_json
|
27
|
+
if @echo_request.slots.saturation
|
28
|
+
LEVELS.keys.reverse_each { |level| @echo_request.slots.saturation.sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
@echo_request.slots.to_h.each do |k,v|
|
32
|
+
@string ||= ""
|
33
|
+
next unless v
|
34
|
+
if k == :scene || k == :alert
|
35
|
+
@string << "#{v.to_s} #{k.to_s} "
|
36
|
+
elsif k == :lights || k == :modifier || k == :state
|
37
|
+
@string << "#{v.to_s} "
|
38
|
+
elsif k == :savescene
|
39
|
+
@string << "save scene as #{v.to_s} "
|
40
|
+
elsif k == :flash
|
41
|
+
@string << "start long alert "
|
42
|
+
else
|
43
|
+
@string << "#{k.to_s} #{v.to_s} "
|
71
44
|
end
|
45
|
+
end
|
72
46
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
r.spoken_response = "Please specify which light or lights you'd like to adjust. I'm ready to control the lights."
|
77
|
-
halt r.without_card.to_json
|
78
|
-
end
|
47
|
+
fix_schedule_syntax(@string)
|
48
|
+
@string.sub!("color loop", "colorloop")
|
49
|
+
@string.strip!
|
79
50
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
51
|
+
begin
|
52
|
+
switch = Hue::Switch.new
|
53
|
+
rescue RuntimeError
|
54
|
+
halt AlexaObjects::Response.new(spoken_response: "Hello. Before using Hue lighting, you'll need to give me access to your Hue bridge. Please press the link button on your bridge and launch the skill again within ten seconds.").to_json
|
55
|
+
end
|
56
|
+
|
57
|
+
if @echo_request.slots.lights.nil? && @echo_request.slots.scene.nil? && @echo_request.slots.savescene.nil?
|
58
|
+
halt AlexaObjects::Response.new(end_session: false, spoken_response: "Please specify which light or lights you'd like to adjust. I'm ready to control the lights.").to_json
|
59
|
+
end
|
60
|
+
|
61
|
+
if @echo_request.slots.lights
|
62
|
+
if @echo_request.slots.lights.scan(/light|lights/).empty?
|
63
|
+
halt AlexaObjects::Response.new(end_session: false, spoken_response: "Please specify which light or lights you'd like to adjust. I'm ready to control the lights.").to_json
|
87
64
|
end
|
65
|
+
end
|
88
66
|
|
89
|
-
|
90
|
-
if @echo_request.slots.lights
|
67
|
+
if @echo_request.slots.lights
|
91
68
|
if @echo_request.slots.lights.include?('lights')
|
92
|
-
puts switch.list_groups.keys.join(', ').downcase
|
93
69
|
if !(switch.list_groups.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' lights','')}"))
|
94
|
-
|
95
|
-
r.end_session = true
|
96
|
-
r.spoken_response = "I couldn't find a group with the name #{@echo_request.slots.lights}"
|
97
|
-
halt r.without_card.to_json
|
70
|
+
halt AlexaObjects::Response.new(spoken_response: "I couldn't find a group with the name #{@echo_request.slots.lights}").to_json
|
98
71
|
end
|
99
|
-
|
100
72
|
elsif @echo_request.slots.lights.include?('light')
|
101
73
|
if !(switch.list_lights.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' light','')}"))
|
102
|
-
|
103
|
-
r.end_session = true
|
104
|
-
r.spoken_response = "I couldn't find a light with the name #{@echo_request.slots.lights}"
|
105
|
-
halt r.without_card.to_json
|
74
|
+
halt AlexaObjects::Response.new(spoken_response: "I couldn't find a light with the name #{@echo_request.slots.lights}").to_json
|
106
75
|
end
|
107
76
|
end
|
108
77
|
end
|
109
78
|
|
110
79
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
80
|
+
#if @string.include?('light ')
|
81
|
+
# if (@string.split(' ') & switch.list_lights.keys.join(', ').downcase.split(', ')).empty?
|
82
|
+
# r = AlexaObjects::Response.new
|
83
|
+
# r.end_session = true
|
84
|
+
# r.spoken_response = "I couldn't find a light with the name #{@echo_request.slots.lights}"
|
85
|
+
# halt r.without_card.to_json
|
86
|
+
# end
|
87
|
+
#end
|
88
|
+
switch.voice @string
|
120
89
|
|
121
|
-
|
122
|
-
response.end_session = true
|
123
|
-
response.spoken_response = "okay"
|
124
|
-
response.card_content = "#{@string}...#{@data}"
|
125
|
-
response.without_card.to_json # change to .with_card.to_json for debugging info
|
126
|
-
|
127
|
-
# Behavior for End Session requests.
|
128
|
-
elsif @echo_request.intent_name == "EndSession"
|
129
|
-
response = AlexaObjects::Response.new
|
130
|
-
response.end_session = true
|
131
|
-
response.spoken_response = "exiting lighting"
|
132
|
-
response.without_card.to_json
|
133
|
-
|
134
|
-
elsif @echo_request.session_ended_request?
|
135
|
-
response = AlexaObjects::Response.new
|
136
|
-
response.end_session = true
|
137
|
-
response.without_card.to_json
|
138
|
-
end
|
139
|
-
end
|
90
|
+
return AlexaObjects::Response.new(spoken_response: "okay").to_json
|
140
91
|
end
|
141
92
|
end
|
142
|
-
|
143
|
-
register Hue
|
144
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa_hue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Lucas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -207,7 +207,6 @@ files:
|
|
207
207
|
- alexa_hue.gemspec
|
208
208
|
- lib/alexa_hue.rb
|
209
209
|
- lib/alexa_hue/custom_slots.rb
|
210
|
-
- lib/alexa_hue/endpoint.rb
|
211
210
|
- lib/alexa_hue/fix_schedule_syntax.rb
|
212
211
|
- lib/alexa_hue/hue_switch.rb
|
213
212
|
- lib/alexa_hue/intent_schema.rb
|