diff --git a/src/main.zig b/src/main.zig index 29deab3..9c4fcb5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -228,7 +228,7 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co } /// Starts recirculation for the specified device with given duration -fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial_number: []const u8, duration_minutes: u32) !bool { +fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial_number: []const u8, duration_minutes: u32) !void { var client = http.Client{ .allocator = allocator }; defer client.deinit(); @@ -258,7 +258,7 @@ fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial }, }); - return result.status == .ok; + if (result.status != .ok) return error.StartRecirculationFailed; } const DeviceShadow = struct { @@ -435,10 +435,34 @@ pub fn main() !void { if (recirc_enabled) { try stdout.print("\nāœ“ Recirculation is already active\n", .{}); - // Recirculation code commented out as requested } else { - // Recirculation code would go here but not called during testing - try stdout.print("\n(Recirculation start function available but not called during testing)\n", .{}); + try stdout.print("\n🚿 Starting 15-minute recirculation...\n", .{}); + try stdout.flush(); + + startRecirculation( + allocator, + auth.id_token, + sid, + 15, + ) catch |e| { + try stderr.print("āŒ Failed to start recirculation\n", .{}); + try stderr.flush(); + return e; + }; + + try stdout.print("āœ“ Recirculation command sent\n", .{}); + try stdout.print("ā³ Waiting 20 seconds for device to respond...\n", .{}); + try stdout.flush(); + + std.Thread.sleep(20 * std.time.ns_per_s); + + var post_command_state = try getRecirculationStatus( + allocator, + auth.id_token, + sid, + ); + defer post_command_state.deinit(); + try stdout.print("\n{f}", .{post_command_state}); } try stdout.flush(); } else {