Display TpLink Tapo power usage values

This commit is contained in:
Jack Mechem 2026-05-21 16:08:53 -07:00
parent e6b5fed399
commit a0487c0b59
Signed by: jackmechem
SSH key fingerprint: SHA256:GjIjMAC33pzYOe+hWcX5uvgnPrVFAXSrquvt84AOJbU
5 changed files with 187 additions and 0 deletions

24
app/lib/getPower.ts Normal file
View file

@ -0,0 +1,24 @@
export interface TapoDevice {
name: string;
ip: string;
alias: string;
model: string;
on: boolean;
current_power_w: number;
today_energy_wh: number;
month_energy_wh: number;
today_runtime_min: number;
month_runtime_min: number;
}
export interface PowerData {
timestamp: string;
devices: TapoDevice[];
}
export async function getPower(): Promise<PowerData> {
const res = await fetch("/api/power");
if (res.status === 401) throw new Error("UNAUTHORIZED");
if (!res.ok) throw new Error(`Failed to fetch power: ${res.status}`);
return res.json() as Promise<PowerData>;
}