reformat strings

This commit is contained in:
Emil Lerch 2025-12-09 12:12:28 -08:00
parent 1013a05b83
commit b49ac43f08
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -55,7 +55,9 @@ fn authenticate(allocator: std.mem.Allocator, username: []const u8, password: []
var client = http.Client{ .allocator = allocator };
defer client.deinit();
const body = try std.fmt.allocPrint(allocator, "{{\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"{s}\",\"AuthParameters\":{{\"USERNAME\":\"{s}\",\"PASSWORD\":\"{s}\"}}}}", .{ client_id, username, password });
const body = try std.fmt.allocPrint(allocator,
\\{{"AuthFlow":"USER_PASSWORD_AUTH","ClientId":"{s}","AuthParameters":{{"USERNAME":"{s}","PASSWORD":"{s}"}}}}
, .{ client_id, username, password });
defer allocator.free(body);
const uri = try std.Uri.parse(cognito_url);
@ -107,9 +109,32 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co
var client = http.Client{ .allocator = allocator };
defer client.deinit();
const query = "query GetUserByEmail($email: String!) { getUserByEmail(email: $email) { items { id email devices { items { id thing_name device_name dsn model info { serial_id } } } } } }";
const query =
\\query GetUserByEmail($email: String!) {
\\ getUserByEmail(email: $email) {
\\ items {
\\ id
\\ email
\\ devices {
\\ items {
\\ id
\\ thing_name
\\ device_name
\\ dsn
\\ model
\\ info {
\\ serial_id
\\ }
\\ }
\\ }
\\ }
\\ }
\\}
;
const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"email\":\"{s}\"}}}}", .{ query, username });
const body = try std.fmt.allocPrint(allocator,
\\{{"query":"{s}","variables":{{"email":"{s}"}}}}
, .{ query, username });
defer allocator.free(body);
const uri = try std.Uri.parse(appsync_url);
@ -137,14 +162,20 @@ fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial
var client = http.Client{ .allocator = allocator };
defer client.deinit();
const url = try std.fmt.allocPrint(allocator, "{s}/{s}/shadow", .{ shadow_api_url, serial_number });
const url = try std.fmt.allocPrint(allocator,
\\{s}/{s}/shadow
, .{ shadow_api_url, serial_number });
defer allocator.free(url);
const body = try std.fmt.allocPrint(allocator, "{{\"recirculation_duration\":{d},\"set_recirculation_enabled\":true}}", .{duration_minutes});
const body = try std.fmt.allocPrint(allocator,
\\{{"recirculation_duration":{d},"set_recirculation_enabled":true}}
, .{duration_minutes});
defer allocator.free(body);
const uri = try std.Uri.parse(url);
const auth_header = try std.fmt.allocPrint(allocator, "Bearer {s}", .{id_token});
const auth_header = try std.fmt.allocPrint(allocator,
\\Bearer {s}
, .{id_token});
defer allocator.free(auth_header);
const result = try client.fetch(.{
@ -165,9 +196,22 @@ fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, se
var client = http.Client{ .allocator = allocator };
defer client.deinit();
const query = "query GetDeviceShadow($heater_serial_number: ID!) { getDeviceShadow(heater_serial_number: $heater_serial_number) { heater_serial_number set_recirculation_enabled recirculation_enabled recirculation_duration set_domestic_temperature operation_enabled } }";
const query =
\\query GetDeviceShadow($heater_serial_number: ID!) {
\\ getDeviceShadow(heater_serial_number: $heater_serial_number) {
\\ heater_serial_number
\\ set_recirculation_enabled
\\ recirculation_enabled
\\ recirculation_duration
\\ set_domestic_temperature
\\ operation_enabled
\\ }
\\}
;
const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"heater_serial_number\":\"{s}\"}}}}", .{ query, serial_number });
const body = try std.fmt.allocPrint(allocator,
\\{{"query":"{s}","variables":{{"heater_serial_number":"{s}"}}}}
, .{ query, serial_number });
defer allocator.free(body);
const uri = try std.Uri.parse(appsync_url);