move shadow state output to custom format function

This commit is contained in:
Emil Lerch 2025-12-09 13:44:03 -08:00
parent 750d931ffe
commit 82babf0ce6
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -273,6 +273,16 @@ const DeviceShadow = struct {
pub fn deinit(self: *DeviceShadow) void {
self.json_data.deinit();
}
pub fn format(self: DeviceShadow, writer: *std.Io.Writer) std.Io.Writer.Error!void {
try writer.writeAll("Current Shadow State:\n");
try writer.print(" heater_serial_number: {?s}\n", .{self.heater_serial_number});
try writer.print(" set_recirculation_enabled: {?}\n", .{self.set_recirculation_enabled});
try writer.print(" recirculation_enabled: {?}\n", .{self.recirculation_enabled});
try writer.print(" recirculation_duration: {?}\n", .{self.recirculation_duration});
try writer.print(" set_domestic_temperature: {?}\n", .{self.set_domestic_temperature});
try writer.print(" operation_enabled: {?}\n", .{self.operation_enabled});
}
};
fn parseDeviceShadow(parsed: json.Parsed(json.Value)) !DeviceShadow {
@ -413,13 +423,7 @@ pub fn main() !void {
var status = try getRecirculationStatus(allocator, auth.id_token, sid);
defer status.deinit();
try stdout.print("\nCurrent Shadow State:\n", .{});
try stdout.print(" heater_serial_number: {?s}\n", .{status.heater_serial_number});
try stdout.print(" set_recirculation_enabled: {?}\n", .{status.set_recirculation_enabled});
try stdout.print(" recirculation_enabled: {?}\n", .{status.recirculation_enabled});
try stdout.print(" recirculation_duration: {?}\n", .{status.recirculation_duration});
try stdout.print(" set_domestic_temperature: {?}\n", .{status.set_domestic_temperature});
try stdout.print(" operation_enabled: {?}\n", .{status.operation_enabled});
try stdout.print("\n{f}", .{status});
const recirc_enabled = status.recirculation_enabled orelse false;