diff --git a/src/homeassistant.zig b/src/homeassistant.zig index 66aab40..53fe798 100644 --- a/src/homeassistant.zig +++ b/src/homeassistant.zig @@ -858,36 +858,16 @@ pub fn handleDeviceAction( // Execute the action switch (action) { - .turn_on => { - try client.callService(entity.domain, "turn_on", entity.entity_id, null); - return ActionResult{ - .speech = try std.fmt.allocPrint( - allocator, - "Turned on the {s}.", - .{entity.friendly_name}, - ), - .end_session = true, + .turn_on, .turn_off, .toggle => { + const service = switch (action) { + .turn_on => "turn_on", + .turn_off => "turn_off", + .toggle => "toggle", + else => unreachable, }; - }, - .turn_off => { - try client.callService(entity.domain, "turn_off", entity.entity_id, null); + try client.callService(entity.domain, service, entity.entity_id, null); return ActionResult{ - .speech = try std.fmt.allocPrint( - 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}, - ), + .speech = try allocator.dupe(u8, "