change to a bell sound to acknowledge on/off/toggle
All checks were successful
Alexa skill build / build (push) Successful in 41s
All checks were successful
Alexa skill build / build (push) Successful in 41s
This commit is contained in:
parent
2910efcb6a
commit
810b4e7df4
1 changed files with 9 additions and 30 deletions
|
|
@ -858,36 +858,16 @@ pub fn handleDeviceAction(
|
||||||
|
|
||||||
// Execute the action
|
// Execute the action
|
||||||
switch (action) {
|
switch (action) {
|
||||||
.turn_on => {
|
.turn_on, .turn_off, .toggle => {
|
||||||
try client.callService(entity.domain, "turn_on", entity.entity_id, null);
|
const service = switch (action) {
|
||||||
return ActionResult{
|
.turn_on => "turn_on",
|
||||||
.speech = try std.fmt.allocPrint(
|
.turn_off => "turn_off",
|
||||||
allocator,
|
.toggle => "toggle",
|
||||||
"Turned on the {s}.",
|
else => unreachable,
|
||||||
.{entity.friendly_name},
|
|
||||||
),
|
|
||||||
.end_session = true,
|
|
||||||
};
|
};
|
||||||
},
|
try client.callService(entity.domain, service, entity.entity_id, null);
|
||||||
.turn_off => {
|
|
||||||
try client.callService(entity.domain, "turn_off", entity.entity_id, null);
|
|
||||||
return ActionResult{
|
return ActionResult{
|
||||||
.speech = try std.fmt.allocPrint(
|
.speech = try allocator.dupe(u8, "<audio src=\"soundbank://soundlibrary/musical/amzn_sfx_electronic_beep_01\"/>"),
|
||||||
allocator,
|
|
||||||
"Turned off the {s}.",
|
|
||||||
.{entity.friendly_name},
|
|
||||||
),
|
|
||||||
.end_session = true,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
.toggle => {
|
|
||||||
try client.callService(entity.domain, "toggle", entity.entity_id, null);
|
|
||||||
return ActionResult{
|
|
||||||
.speech = try std.fmt.allocPrint(
|
|
||||||
allocator,
|
|
||||||
"Toggled the {s}.",
|
|
||||||
.{entity.friendly_name},
|
|
||||||
),
|
|
||||||
.end_session = true,
|
.end_session = true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -1273,8 +1253,7 @@ test "handleDeviceAction turn on light success" {
|
||||||
const result = try handleDeviceAction(allocator, &client, .turn_on, "bedroom", null, null);
|
const result = try handleDeviceAction(allocator, &client, .turn_on, "bedroom", null, null);
|
||||||
defer allocator.free(result.speech);
|
defer allocator.free(result.speech);
|
||||||
|
|
||||||
try std.testing.expect(std.mem.indexOf(u8, result.speech, "Turned on") != null);
|
try std.testing.expect(std.mem.indexOf(u8, result.speech, "<audio src=") != null);
|
||||||
try std.testing.expect(std.mem.indexOf(u8, result.speech, "Bedroom Light") != null);
|
|
||||||
try std.testing.expect(result.end_session);
|
try std.testing.expect(result.end_session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue