alexa_hue 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4a6e8ca4b56fe2a6cd2eece2da39267159f9025
4
- data.tar.gz: 7095152315f70877ab2359665558296901912a14
3
+ metadata.gz: 9899901a0800aaac312d75eba07974c4caf1777f
4
+ data.tar.gz: 63a10072deb984d0c3a9f5908e82a2c61474fc24
5
5
  SHA512:
6
- metadata.gz: 3fe7d7d210600fe573bbea05fedbcf23d44bbad90dddc8e0a81c4c70cd0eb8e25b75625d746c8361c4f7fde6f0afc9a799652cc645590dbd1b29daca42466424
7
- data.tar.gz: 85b7d71dfaff8d58174301df1f623f0c45477b163d4c43ae5755cb39630f61f271dedda432bb186c6c80dde09809fb19219fd8ac4768191bcda47fc734f7df4d
6
+ metadata.gz: 392e2fde49d7b0cfca31e316817fd674abe79663bb65c7596a9df49322b820a9fe6b9da9f4c6c83286516bf4316e94e18959023e6bd521c4d6fb6d8016c24f1a
7
+ data.tar.gz: 6118cb8026c5b30b063e80582652013705cc03b7aa9523de7850bbf4e630d9c59861bf5db2f8f06dbe0cd7965be6834113181577c156247e4632cdc22c004fad
@@ -1,4 +1,4 @@
1
1
  module Hue
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end
4
4
 
data/lib/alexa_hue.rb CHANGED
@@ -11,21 +11,24 @@ require 'alexa_hue/hue/voice_parser'
11
11
  require 'alexa_hue/hue/helpers'
12
12
  require 'chronic_duration'
13
13
 
14
+
15
+ LEVELS = {} ; [*1..10].each { |t| LEVELS[t.to_s ] = t.in_words }
16
+
17
+
14
18
  module Hue
15
19
  include Hue::Helpers
16
20
  extend Sinatra::Extension
17
21
 
18
22
  helpers do
19
- LEVELS = {} ; [*1..10].each { |t| LEVELS[t.to_s ] = t.in_words }
20
-
21
23
  def control_lights
22
- [:brightness, :saturation].each do |attribute|
23
- if @echo_request.slots.send(attribute)
24
- LEVELS.keys.reverse_each { |level| @echo_request.slots.send(attribute).sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
25
- end
24
+ if @echo_request.slots.brightness
25
+ LEVELS.keys.reverse_each { |level| @echo_request.slots.brightness.sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
26
+ end
27
+
28
+ if @echo_request.slots.saturation
29
+ LEVELS.keys.reverse_each { |level| @echo_request.slots.saturation.sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
26
30
  end
27
31
 
28
- # TODO: ...something about this feel ugly and unexpressive
29
32
  @echo_request.slots.to_h.each do |k,v|
30
33
  @string ||= ""
31
34
  next unless v
@@ -41,42 +44,51 @@ module Hue
41
44
  @string << "#{k.to_s} #{v.to_s} "
42
45
  end
43
46
  end
44
-
45
- # TODO: create context for these statements
47
+
46
48
  fix_schedule_syntax(@string)
47
- @string.sub!("color loop", "colorloop").strip!
49
+ @string.sub!("color loop", "colorloop")
50
+ @string.strip!
51
+
52
+ begin
53
+ switch = Hue::Switch.new
54
+ rescue RuntimeError
55
+ 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
56
+ end
48
57
 
49
- if @echo_request.slots.scene.nil? && @echo_request.slots.savescene.nil?
50
- if @echo_request.slots.lights.nil? || @echo_request.slots.lights&.scan(/light|lights/).empty?
58
+ if @echo_request.slots.lights.nil? && @echo_request.slots.scene.nil? && @echo_request.slots.savescene.nil?
59
+ 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
60
+ end
61
+
62
+ if @echo_request.slots.lights
63
+ if @echo_request.slots.lights.scan(/light|lights/).empty?
51
64
  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
52
65
  end
53
66
  end
54
67
 
55
- # TODO: 58-68 seem to both express the same thought from alexa, could be simplified?
56
68
  if @echo_request.slots.lights
57
69
  if @echo_request.slots.lights.include?('lights')
58
- if !(hue_client.list_groups.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' lights','')}"))
70
+ if !(switch.list_groups.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' lights','')}"))
59
71
  halt AlexaObjects::Response.new(spoken_response: "I couldn't find a group with the name #{@echo_request.slots.lights}").to_json
60
72
  end
61
73
  elsif @echo_request.slots.lights.include?('light')
62
- if !(hue_client.list_lights.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' light','')}"))
74
+ if !(switch.list_lights.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' light','')}"))
63
75
  halt AlexaObjects::Response.new(spoken_response: "I couldn't find a light with the name #{@echo_request.slots.lights}").to_json
64
76
  end
65
77
  end
66
78
  end
79
+
67
80
 
68
- #TODO : majorly create context for this
69
- hue_client.voice @string
81
+ #if @string.include?('light ')
82
+ # if (@string.split(' ') & switch.list_lights.keys.join(', ').downcase.split(', ')).empty?
83
+ # r = AlexaObjects::Response.new
84
+ # r.end_session = true
85
+ # r.spoken_response = "I couldn't find a light with the name #{@echo_request.slots.lights}"
86
+ # halt r.without_card.to_json
87
+ # end
88
+ #end
89
+ switch.voice @string
70
90
 
71
91
  return AlexaObjects::Response.new(spoken_response: "okay").to_json
72
92
  end
73
-
74
- def hue_client
75
- begin
76
- @client = Hue::Switch.new
77
- rescue RuntimeError
78
- 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
79
- end
80
- end
81
93
  end
82
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_hue
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Lucas