ai added comments

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

View file

@ -8,11 +8,13 @@ const appsync_url = "https://s34ox7kri5dsvdr43bfgp6qh6i.appsync-api.us-east-1.am
const api_key = "da2-dm2g4rqvjbaoxcpo4eccs3k5he";
const shadow_api_url = "https://698suy4zs3.execute-api.us-east-1.amazonaws.com/Prod/thing";
/// Authentication result containing ID token and user UUID
const AuthResult = struct {
id_token: []const u8,
user_uuid: []const u8,
};
/// Credentials loaded from file with managed memory
const CognitoCredentials = struct {
allocator: std.mem.Allocator,
buffer: []const u8,
@ -26,6 +28,8 @@ const CognitoCredentials = struct {
self.password = undefined;
}
};
/// Reads username and password from .credentials file (one per line)
fn readCredentials(allocator: std.mem.Allocator) !CognitoCredentials {
// TODO: something different
const file = try std.fs.cwd().openFile(".credentials", .{});
@ -46,6 +50,7 @@ fn readCredentials(allocator: std.mem.Allocator) !CognitoCredentials {
};
}
/// Authenticates with AWS Cognito and returns ID token and user UUID
fn authenticate(allocator: std.mem.Allocator, username: []const u8, password: []const u8) !AuthResult {
var client = http.Client{ .allocator = allocator };
defer client.deinit();
@ -97,6 +102,7 @@ fn authenticate(allocator: std.mem.Allocator, username: []const u8, password: []
return .{ .id_token = id_token_copy, .user_uuid = user_uuid_copy };
}
/// Fetches device list from AppSync GraphQL API for the given user
fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []const u8) !json.Parsed(json.Value) {
var client = http.Client{ .allocator = allocator };
defer client.deinit();
@ -126,6 +132,7 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co
return try json.parseFromSlice(json.Value, allocator, response_body, .{});
}
/// 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 {
var client = http.Client{ .allocator = allocator };
defer client.deinit();
@ -153,6 +160,7 @@ fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial
return result.status == .ok;
}
/// Queries the device shadow to get current recirculation status
fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, serial_number: []const u8) !json.Parsed(json.Value) {
var client = http.Client{ .allocator = allocator };
defer client.deinit();