Module: Sinatra::Hue
- Defined in:
- lib/alexa_hue.rb,
lib/alexa_hue/version.rb,
lib/alexa_hue/hue_switch.rb,
lib/alexa_hue/custom_slots.rb,
lib/alexa_hue/intent_schema.rb,
lib/alexa_hue/sample_utterances.rb
Defined Under Namespace
Classes: Device, SSDP, Switch
Constant Summary
collapse
- VERSION =
"1.0.1"
Class Method Summary
collapse
Class Method Details
.custom_slots ⇒ Object
3
4
5
|
# File 'lib/alexa_hue/custom_slots.rb', line 3
def self.custom_slots
File.read(File.expand_path('../../../skills_config/custom_slots.txt', __FILE__))
end
|
.devices(options = {}) ⇒ Object
17
18
19
|
# File 'lib/alexa_hue/hue_switch.rb', line 17
def devices(options = {})
SSDP.new(options).devices
end
|
.first(options = {}) ⇒ Object
21
22
23
24
|
# File 'lib/alexa_hue/hue_switch.rb', line 21
def first(options = {})
options = options.merge(:first => true)
SSDP.new(options).devices
end
|
.intent_schema ⇒ Object
3
4
5
|
# File 'lib/alexa_hue/intent_schema.rb', line 3
def self.intent_schema
File.read(File.expand_path('../../../skills_config/intent_schema.txt', __FILE__))
end
|
.registered(app) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/alexa_hue.rb', line 19
def self.registered(app)
app.post '/alexa_hue' do
content_type :json
if @echo_request.launch_request?
response = AlexaObjects::Response.new
response.spoken_response = "I'm ready to control the lights"
response.end_session = false
response.without_card.to_json
elsif @echo_request.intent_name == "ControlLights"
if @echo_request.slots.brightness
LEVELS.keys.reverse_each { |level| @echo_request.slots.brightness.sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
end
if @echo_request.slots.saturation
LEVELS.keys.reverse_each { |level| @echo_request.slots.saturation.sub!(level, LEVELS[level]) } if @echo_request.slots.schedule.nil?
end
puts @echo_request.slots
@echo_request.slots.to_h.each do |k,v|
@string ||= ""
next unless v
if k == :scene || k == :alert
@string << "#{v.to_s} #{k.to_s} "
elsif k == :lights || k == :modifier || k == :state
@string << "#{v.to_s} "
elsif k == :savescene
@string << "save scene as #{v.to_s} "
elsif k == :flash
@string << "start long alert "
else
@string << "#{k.to_s} #{v.to_s} "
end
end
fix_schedule_syntax(@string)
@string.sub!("color loop", "colorloop")
@string.strip!
begin
switch = Hue::Switch.new
rescue RuntimeError
response = AlexaObjects::Response.new
response.end_session = true
response.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."
halt response.without_card.to_json
end
if @echo_request.slots.lights.nil? && @echo_request.slots.scene.nil? && @echo_request.slots.savescene.nil?
r = AlexaObjects::Response.new
r.end_session = false
r.spoken_response = "Please specify which light or lights you'd like to adjust. I'm ready to control the lights."
halt r.without_card.to_json
end
if @echo_request.slots.lights
if @echo_request.slots.lights.scan(/light|lights/).empty?
r = AlexaObjects::Response.new
r.end_session = false
r.spoken_response = "Please specify which light or lights you'd like to adjust. I'm ready to control the lights."
halt r.without_card.to_json
end
end
puts @echo_request.slots.lights
if @echo_request.slots.lights
if @echo_request.slots.lights.include?('lights')
puts switch.list_groups.keys.join(', ').downcase
if !(switch.list_groups.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' lights','')}"))
r = AlexaObjects::Response.new
r.end_session = true
r.spoken_response = "I couldn't find a group with the name #{@echo_request.slots.lights}"
halt r.without_card.to_json
end
elsif @echo_request.slots.lights.include?('light')
if !(switch.list_lights.keys.join(', ').downcase.include?("#{@echo_request.slots.lights.sub(' light','')}"))
r = AlexaObjects::Response.new
r.end_session = true
r.spoken_response = "I couldn't find a light with the name #{@echo_request.slots.lights}"
halt r.without_card.to_json
end
end
end
switch.voice @string
response = AlexaObjects::Response.new
response.end_session = true
response.spoken_response = "okay"
response.card_content = "#{@string}...#{@data}"
response.without_card.to_json
elsif @echo_request.intent_name == "EndSession"
response = AlexaObjects::Response.new
response.end_session = true
response.spoken_response = "exiting lighting"
response.without_card.to_json
elsif @echo_request.session_ended_request?
response = AlexaObjects::Response.new
response.end_session = true
response.without_card.to_json
end
end
end
|
.sample_utterances ⇒ Object
3
4
5
|
# File 'lib/alexa_hue/sample_utterances.rb', line 3
def self.sample_utterances
File.read(File.expand_path('../../../skills_config/sample_utterances.txt', __FILE__))
end
|