alexa_hue 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alexa_hue/custom_slots.rb +3 -3
- data/lib/alexa_hue/hue/client.rb +15 -12
- data/lib/alexa_hue/hue/helpers.rb +17 -17
- data/lib/alexa_hue/hue/js_client.rb +4 -11
- data/lib/alexa_hue/hue/voice_parser.rb +20 -62
- data/lib/alexa_hue/version.rb +1 -1
- data/lib/alexa_hue.rb +4 -39
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57a0ac8e1a676ca01553ffd07787129c43dc5a17
|
4
|
+
data.tar.gz: 48e7ca98535697a5ca4721e954e5346b40678887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a7abed1501fb8e48a008a437d81e54cced4358a7270c26bef2aa82385a4d49c297af824f2760bb29f0fea8828d11411766eabd4c58241a28490d2f2f371cb0c
|
7
|
+
data.tar.gz: f6bc4b6015915cd1fb076269eaea1ce5b73eeb201e48fa744e7056858f2851fb8f2f864320a747a15d06223537c00c2279aa5285e18fcc6f0352067d219857ee
|
@@ -3,10 +3,10 @@ module Hue
|
|
3
3
|
def self.custom_slots
|
4
4
|
client = Hue::Client.new
|
5
5
|
slots = "LIGHTS"
|
6
|
-
client.instance_variable_get(
|
7
|
-
client.instance_variable_get(
|
6
|
+
client.instance_variable_get("@lights").keys.each {|x| slots << "\n#{x}"}
|
7
|
+
client.instance_variable_get("@groups").keys.each {|x| slots << "\n#{x}"}
|
8
8
|
slots << "\n\nSCENE"
|
9
|
-
client.instance_variable_get(
|
9
|
+
client.instance_variable_get("@scenes").keys.each {|x| slots << "\n#{x}"}
|
10
10
|
slots << "\n"
|
11
11
|
slots << File.read(File.expand_path('../../../skills_config/custom_slots.txt', __FILE__))
|
12
12
|
slots
|
data/lib/alexa_hue/hue/client.rb
CHANGED
@@ -50,15 +50,17 @@ module Hue
|
|
50
50
|
@client.put_all_lights(alert: 'select')
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
# Not currently used??
|
54
|
+
|
55
|
+
# def hue(numeric_value)
|
56
|
+
# @body.reset
|
57
|
+
# @body.hue = numeric_value
|
58
|
+
# end
|
57
59
|
|
58
|
-
def mired(numeric_value)
|
59
|
-
|
60
|
-
|
61
|
-
end
|
60
|
+
# def mired(numeric_value)
|
61
|
+
# @body.reset
|
62
|
+
# @body.ct = numeric_value
|
63
|
+
# end
|
62
64
|
|
63
65
|
def color(color_name)
|
64
66
|
@body.reset
|
@@ -81,7 +83,7 @@ module Hue
|
|
81
83
|
@body.transitiontime = in_seconds * 10
|
82
84
|
end
|
83
85
|
|
84
|
-
def light
|
86
|
+
def light(*args)
|
85
87
|
@lights_array = []
|
86
88
|
@_group = ""
|
87
89
|
@body.clear_scene
|
@@ -103,7 +105,7 @@ module Hue
|
|
103
105
|
@body.scene = scene_details["id"]
|
104
106
|
end
|
105
107
|
|
106
|
-
def
|
108
|
+
def savescene(scene_name)
|
107
109
|
fade(2) if @body.transitiontime == nil
|
108
110
|
light_group = @_group.empty? ? @client.get_all_lights.body["lights"] : @client.get_group(group: @_group).body["lights"]
|
109
111
|
params = {name: scene_name.gsub!(' ','-'), lights: light_group, transitiontime: @body.transitiontime}
|
@@ -112,7 +114,7 @@ module Hue
|
|
112
114
|
end
|
113
115
|
|
114
116
|
def toggle_lights
|
115
|
-
@lights_array.each { |l| @client.
|
117
|
+
@lights_array.each { |l| @client.put_light({lights: l}.merge(@body.to_hash)) }
|
116
118
|
end
|
117
119
|
|
118
120
|
def toggle_group
|
@@ -124,7 +126,7 @@ module Hue
|
|
124
126
|
@client.put_group({group: @_group}.merge(@body.to_hash(without_scene: true)))
|
125
127
|
else
|
126
128
|
@client.get_scenes[@body[:scene]]["lights"].each do |l|
|
127
|
-
@client.
|
129
|
+
@client.put_light({lights: l}.merge(@body.to_hash))
|
128
130
|
end
|
129
131
|
end
|
130
132
|
end
|
@@ -177,6 +179,7 @@ module Hue
|
|
177
179
|
end
|
178
180
|
|
179
181
|
def alert(value)
|
182
|
+
value = value.to_sym
|
180
183
|
if value == :short
|
181
184
|
@body.alert = "select"
|
182
185
|
elsif value == :long
|
@@ -39,24 +39,24 @@ module Hue
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def fix_schedule_syntax(string)
|
43
|
-
|
44
|
-
|
42
|
+
# def fix_schedule_syntax(string)
|
43
|
+
# sub_time = string.match(/time \d{2}:\d{2}/)
|
44
|
+
# sub_duration = string.match(/schedule PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?/)
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
# if sub_time
|
47
|
+
# sub_time = sub_time.to_s
|
48
|
+
# string.slice!(sub_time).strip
|
49
|
+
# string << " #{sub_time}"
|
50
|
+
# string.sub!("time", "schedule at")
|
51
|
+
# end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
53
|
+
# if sub_duration
|
54
|
+
# sub_duration = sub_duration.to_s
|
55
|
+
# string.slice!(sub_duration).strip
|
56
|
+
# sub_duration = ChronicDuration.parse(sub_duration.split(' ').last)
|
57
|
+
# string << " schedule in #{sub_duration} seconds"
|
58
|
+
# end
|
59
|
+
# string.strip if string
|
60
|
+
# end
|
61
61
|
end
|
62
62
|
end
|
@@ -17,14 +17,9 @@ module Hue
|
|
17
17
|
|
18
18
|
def save_scene(scene_name)
|
19
19
|
fade(2) if @body.transitiontime == nil
|
20
|
-
|
21
|
-
light_group = @client.get_all_lights.body["lights"]
|
22
|
-
else
|
23
|
-
light_group = @client.get_group(group: @_group).body["lights"]
|
24
|
-
end
|
20
|
+
light_group = @_group.empty? ? @client.get_all_lights.body["lights"] : @client.get_group(group: @_group).body["lights"]
|
25
21
|
params = {name: scene_name.gsub!(' ','-'), lights: light_group, transitiontime: @body.transitiontime}
|
26
|
-
|
27
|
-
confirm if response.first.keys[0] == "success"
|
22
|
+
confirm if @client.put_scene(scene: scene_name, options: params).body.first.keys[0] == "success"
|
28
23
|
end
|
29
24
|
|
30
25
|
def delete_schedules!
|
@@ -54,10 +49,8 @@ module Hue
|
|
54
49
|
end
|
55
50
|
end
|
56
51
|
|
57
|
-
def
|
58
|
-
|
59
|
-
@client.get_activate_scene(scene: @body.scene)
|
60
|
-
end
|
52
|
+
def toggle_scene
|
53
|
+
@client.get_activate_scene(scene: @body.scene)
|
61
54
|
end
|
62
55
|
|
63
56
|
def off
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'alexa_hue/hue/client'
|
2
2
|
require 'alexa_hue/hue/js_client'
|
3
3
|
require 'alexa_hue/hue/helpers'
|
4
|
+
require 'active_support/core_ext/hash'
|
4
5
|
|
5
6
|
module Hue
|
6
7
|
class VoiceParser
|
@@ -12,70 +13,27 @@ module Hue
|
|
12
13
|
@client = options[:js] ? Hue::JsClient.new(options[:js]) : Hue::Client.new
|
13
14
|
end
|
14
15
|
|
15
|
-
def voice(
|
16
|
+
def voice(echo_response)
|
16
17
|
@client.reset
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
|
19
|
+
echo_response.slots.to_h.except(:state).each do |key, value|
|
20
|
+
if value
|
21
|
+
if value.split(' ').last == "light"
|
22
|
+
key = "light"
|
23
|
+
value = value[/(.*)\s/,1]
|
24
|
+
elsif value.split(' ').last == "lights"
|
25
|
+
key = "lights"
|
26
|
+
value = value.split(' ').count == 1 ? "lights" : value[/(.*)\s/,1]
|
27
|
+
end
|
28
|
+
|
29
|
+
value = value.in_numbers if value.scan(Regexp.union( (1..10).map {|k| k.in_words} ) ).any?
|
30
|
+
value = ((value.to_f/10.to_f)*255).to_i if (value.class == Fixnum) && (key.to_s != "fade")
|
31
|
+
@client.send(key.to_sym, value)
|
32
|
+
puts "Calling: #{key}(#{value})"
|
33
|
+
end
|
26
34
|
end
|
27
|
-
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def parse_leading(methods)
|
32
|
-
methods.each do |l|
|
33
|
-
capture = (@client.command.match (/\b#{l}\s\w+/)).to_s.split(' ')
|
34
|
-
method = capture[0]
|
35
|
-
value = capture[1]
|
36
|
-
value = value.in_numbers if value.scan(Regexp.union( (1..10).map {|k| k.in_words} ) ).any?
|
37
|
-
value = ((value.to_f/10.to_f)*255).to_i if (value.class == Fixnum) && (l != "fade")
|
38
|
-
@client.send( method, value )
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def parse_trailing(method)
|
43
|
-
all_keys = Regexp.union((@client.groups.keys + @client.lights.keys).flatten)
|
44
|
-
value = @client.command.match(all_keys).to_s
|
45
|
-
@client.send(method.first, value)
|
46
|
-
end
|
47
|
-
|
48
|
-
def parse_dynamic(methods)
|
49
|
-
methods.each do |d|
|
50
|
-
capture = (@client.command.match (/\w+ #{d}\b/)).to_s.split(' ')
|
51
|
-
method = capture[1]
|
52
|
-
value = capture[0].to_sym
|
53
|
-
@client.send(method, value)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def parse_scene(scene_name)
|
58
|
-
scene_name.gsub!(' ','-') if scene_name.size > 1
|
59
|
-
@client.scene(scene_name)
|
60
|
-
end
|
61
|
-
|
62
|
-
def parse_save_scene
|
63
|
-
save_scene = @client.command.partition(/save (scene|seen) as /).last
|
64
|
-
@client.save_scene(save_scene)
|
65
|
-
end
|
66
|
-
|
67
|
-
def parse_voice(string)
|
68
|
-
string.gsub!('schedule ','')
|
69
|
-
trailing = string.split(' ') & %w[lights light]
|
70
|
-
leading = string.split(' ') & %w[hue brightness saturation fade color]
|
71
|
-
dynamic = string.split(' ') & %w[colorloop alert]
|
72
|
-
scene_name = string.partition(" scene").first
|
73
|
-
|
74
|
-
parse_scene(scene_name) if string.include?(" scene") && !string.include?("save")
|
75
|
-
parse_leading(leading) if leading.any?
|
76
|
-
parse_trailing(trailing) if trailing.any?
|
77
|
-
parse_dynamic(dynamic) if dynamic.any?
|
78
|
-
parse_save_scene if @client.command.scan(/save (scene|seen) as/).length > 0
|
35
|
+
|
36
|
+
echo_response.slots.state == "off" ? @client.off : @client.on
|
79
37
|
end
|
80
38
|
end
|
81
39
|
end
|
data/lib/alexa_hue/version.rb
CHANGED
data/lib/alexa_hue.rb
CHANGED
@@ -28,37 +28,12 @@ module Hue
|
|
28
28
|
LEVELS.keys.reverse_each { |level| @echo_request.slots.send(attribute).sub!(level, LEVELS[level]) } if @echo_request.slots.send(attribute) && @echo_request.slots.schedule.nil?
|
29
29
|
end
|
30
30
|
|
31
|
-
@echo_request
|
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} "
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
fix_schedule_syntax(@string)
|
48
|
-
@string.sub!("color loop", "colorloop")
|
49
|
-
@string.strip!
|
50
|
-
switch.voice @string
|
31
|
+
switch.voice @echo_request
|
51
32
|
end
|
52
|
-
|
53
|
-
# if @echo_request.slots.lights.nil? && @echo_request.slots.scene.nil? && @echo_request.slots.savescene.nil?
|
54
|
-
# 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
|
55
|
-
# end
|
56
33
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
# end
|
61
|
-
# end
|
34
|
+
if (@echo_request.slots.lights.nil? && @echo_request.slots.scene.nil? && @echo_request.slots.savescene.nil?) || @echo_request.slots.lights&.scan(/light|lights/).empty?
|
35
|
+
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
|
36
|
+
end
|
62
37
|
|
63
38
|
# if @echo_request.slots.lights
|
64
39
|
# if @echo_request.slots.lights.include?('lights')
|
@@ -71,16 +46,6 @@ module Hue
|
|
71
46
|
# end
|
72
47
|
# end
|
73
48
|
# end
|
74
|
-
|
75
|
-
|
76
|
-
#if @string.include?('light ')
|
77
|
-
# if (@string.split(' ') & switch.list_lights.keys.join(', ').downcase.split(', ')).empty?
|
78
|
-
# r = AlexaObjects::Response.new
|
79
|
-
# r.end_session = true
|
80
|
-
# r.spoken_response = "I couldn't find a light with the name #{@echo_request.slots.lights}"
|
81
|
-
# halt r.without_card.to_json
|
82
|
-
# end
|
83
|
-
#end
|
84
49
|
|
85
50
|
return AlexaObjects::Response.new(spoken_response: "okay").to_json
|
86
51
|
end
|