- Add Tasmota device discovery and switchbar quick access

- Features:
    - Tasmota device discovery: Auto-detect network and scan for Tasmota devices
      in Add Smart Plug modal. Supports devices with/without authentication.
    - Switchbar: Quick access widget in sidebar footer for controlling smart plugs
      from anywhere in the app. Shows real-time status and power consumption.
This commit is contained in:
maziggy
2025-12-28 15:02:42 +01:00
parent b3ef6ccb32
commit 0bcedd2c16
18 changed files with 9488 additions and 8725 deletions
+38 -1
View File
@@ -14,7 +14,11 @@ async function request<T>(
if (!response.ok) {
const error = await response.json().catch(() => ({}));
throw new Error(error.detail || `HTTP ${response.status}`);
const detail = error.detail;
const message = typeof detail === 'string'
? detail
: (detail ? JSON.stringify(detail) : `HTTP ${response.status}`);
throw new Error(message);
}
return response.json();
@@ -659,6 +663,8 @@ export interface SmartPlug {
schedule_enabled: boolean;
schedule_on_time: string | null;
schedule_off_time: string | null;
// Switchbar visibility
show_in_switchbar: boolean;
// Status
last_state: string | null;
last_checked: string | null;
@@ -687,6 +693,8 @@ export interface SmartPlugCreate {
schedule_enabled?: boolean;
schedule_on_time?: string | null;
schedule_off_time?: string | null;
// Switchbar visibility
show_in_switchbar?: boolean;
}
export interface SmartPlugUpdate {
@@ -709,6 +717,8 @@ export interface SmartPlugUpdate {
schedule_enabled?: boolean;
schedule_on_time?: string | null;
schedule_off_time?: string | null;
// Switchbar visibility
show_in_switchbar?: boolean;
}
export interface SmartPlugEnergy {
@@ -736,6 +746,21 @@ export interface SmartPlugTestResult {
device_name: string | null;
}
// Tasmota Discovery types
export interface TasmotaScanStatus {
running: boolean;
scanned: number;
total: number;
}
export interface DiscoveredTasmotaDevice {
ip_address: string;
name: string;
module: number | null;
state: string | null;
discovered_at: string | null;
}
// Print Queue types
export interface PrintQueueItem {
id: number;
@@ -1757,6 +1782,18 @@ export const api = {
body: JSON.stringify({ ip_address, username, password }),
}),
// Tasmota Discovery (auto-detects network)
startTasmotaScan: () =>
fetch(`${API_BASE}/smart-plugs/discover/scan`, { method: 'POST' })
.then(res => res.ok ? res.json() : res.json().then(e => { throw new Error(e.detail || `HTTP ${res.status}`); })),
getTasmotaScanStatus: () =>
request<TasmotaScanStatus>('/smart-plugs/discover/status'),
stopTasmotaScan: () =>
fetch(`${API_BASE}/smart-plugs/discover/stop`, { method: 'POST' })
.then(res => res.ok ? res.json() : res.json().then(e => { throw new Error(e.detail || `HTTP ${res.status}`); })),
getDiscoveredTasmotaDevices: () =>
request<DiscoveredTasmotaDevice[]>('/smart-plugs/discover/devices'),
// Print Queue
getQueue: (printerId?: number, status?: string) => {
const params = new URLSearchParams();