Display TpLink Tapo power usage values
This commit is contained in:
parent
e6b5fed399
commit
a0487c0b59
5 changed files with 187 additions and 0 deletions
24
app/lib/getPower.ts
Normal file
24
app/lib/getPower.ts
Normal 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>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue