|
| 1 | +// Backend API Model Interfaces |
| 2 | +// These types match the Python backend models and API responses |
| 3 | + |
| 4 | +// ======================================== |
| 5 | +// COMMAND MODELS |
| 6 | +// ======================================== |
| 7 | + |
| 8 | +/** Matches Python CommandStatus Literal */ |
| 9 | +export type CommandStatus = |
| 10 | + | "pending" |
| 11 | + | "running" |
| 12 | + | "success" |
| 13 | + | "failed" |
| 14 | + | "timed_out" |
| 15 | + | "cancelled"; |
| 16 | + |
| 17 | +/** Matches Python CommandRecord dataclass */ |
| 18 | +export interface CommandRecord { |
| 19 | + id: string; |
| 20 | + address: string; |
| 21 | + action: string; |
| 22 | + args: Record<string, unknown> | null; |
| 23 | + status: CommandStatus; |
| 24 | + attempts: number; |
| 25 | + result: Record<string, unknown> | null; |
| 26 | + error: string | null; |
| 27 | + error_code: string | null; |
| 28 | + created_at: number; |
| 29 | + started_at: number | null; |
| 30 | + completed_at: number | null; |
| 31 | + timeout: number; |
| 32 | +} |
| 33 | + |
| 34 | +/** Matches Python CommandRequest model */ |
| 35 | +export interface CommandRequest { |
| 36 | + id?: string; |
| 37 | + action: string; |
| 38 | + args?: Record<string, unknown>; |
| 39 | + timeout?: number; |
| 40 | +} |
| 41 | + |
| 42 | +// ======================================== |
| 43 | +// DEVICE STATUS MODELS |
| 44 | +// ======================================== |
| 45 | + |
| 46 | +/** Light device channel definition */ |
| 47 | +export interface LightChannel { |
| 48 | + index: number; |
| 49 | + name: string; |
| 50 | +} |
| 51 | + |
| 52 | +/** Light device parsed status (matches serialize_light_status) */ |
| 53 | +export interface LightParsed { |
| 54 | + message_id: number; |
| 55 | + response_mode: number; |
| 56 | + weekday: number | null; |
| 57 | + current_hour: number | null; |
| 58 | + current_minute: number | null; |
| 59 | + keyframes: LightKeyframe[]; |
| 60 | + time_markers: number[]; |
| 61 | + tail: string; // hex string |
| 62 | +} |
| 63 | + |
| 64 | +/** Light keyframe with computed percentage */ |
| 65 | +export interface LightKeyframe { |
| 66 | + index: number; |
| 67 | + timestamp: number; |
| 68 | + value: number | null; |
| 69 | + percent: number; // computed percentage (0-100) |
| 70 | +} |
| 71 | + |
| 72 | +/** Doser head information */ |
| 73 | +export interface DoserHead { |
| 74 | + mode: number; |
| 75 | + hour: number; |
| 76 | + minute: number; |
| 77 | + dosed_tenths_ml: number; |
| 78 | + extra: string; // hex string |
| 79 | + mode_label: string; // human-friendly mode name |
| 80 | +} |
| 81 | + |
| 82 | +/** Doser device parsed status (matches serialize_doser_status) */ |
| 83 | +export interface DoserParsed { |
| 84 | + weekday: number | null; |
| 85 | + hour: number | null; |
| 86 | + minute: number | null; |
| 87 | + heads: DoserHead[]; |
| 88 | + tail_raw: string; // hex string |
| 89 | + lifetime_totals_tenths_ml: number[]; // lifetime totals in tenths of mL for each head |
| 90 | +} |
| 91 | + |
| 92 | +/** Matches cached_status_to_dict output structure */ |
| 93 | +export interface CachedStatus { |
| 94 | + address: string; |
| 95 | + device_type: "light" | "doser"; |
| 96 | + raw_payload: string | null; |
| 97 | + parsed: DoserParsed | LightParsed | null; |
| 98 | + updated_at: number; |
| 99 | + model_name: string | null; |
| 100 | + connected: boolean; |
| 101 | + channels: LightChannel[] | null; |
| 102 | +} |
| 103 | + |
| 104 | +// ======================================== |
| 105 | +// API RESPONSE MODELS |
| 106 | +// ======================================== |
| 107 | + |
| 108 | +/** Main status endpoint response */ |
| 109 | +export interface StatusResponse { |
| 110 | + [address: string]: CachedStatus; |
| 111 | +} |
| 112 | + |
| 113 | +/** Debug live status response */ |
| 114 | +export interface LiveStatusResponse { |
| 115 | + statuses: (CachedStatus & { address: string })[]; |
| 116 | + errors: string[]; |
| 117 | +} |
| 118 | + |
| 119 | +/** Device scan result */ |
| 120 | +export interface ScanDevice { |
| 121 | + address: string; |
| 122 | + name: string; |
| 123 | + product: string; |
| 124 | + device_type: "light" | "doser"; |
| 125 | +} |
| 126 | + |
| 127 | +// ======================================== |
| 128 | +// COMMAND ARGUMENT INTERFACES |
| 129 | +// ======================================== |
| 130 | + |
| 131 | +/** Arguments for set_brightness command */ |
| 132 | +export interface SetBrightnessArgs { |
| 133 | + brightness: number; // 0-100 |
| 134 | + color: number; // 0-5, channel index |
| 135 | +} |
| 136 | + |
| 137 | +/** Arguments for add_auto_setting command */ |
| 138 | +export interface AddAutoSettingArgs { |
| 139 | + sunrise: string; // HH:MM format |
| 140 | + sunset: string; // HH:MM format |
| 141 | + brightness?: number; // 0-100, for single channel (legacy) |
| 142 | + channels?: Record<string, number>; // Per-channel brightness values |
| 143 | + ramp_up_minutes?: number; // default 0 |
| 144 | + weekdays?: string[]; // e.g., ["monday", "tuesday"] |
| 145 | +} |
| 146 | + |
| 147 | +/** Arguments for set_schedule command (doser) */ |
| 148 | +export interface SetScheduleArgs { |
| 149 | + head_index: number; // 0-3 |
| 150 | + volume_tenths_ml: number; // 0-255 |
| 151 | + hour: number; // 0-23 |
| 152 | + minute: number; // 0-59 |
| 153 | + weekdays?: string[]; // e.g., ["monday", "tuesday"] |
| 154 | + confirm?: boolean; // default true |
| 155 | + wait_seconds?: number; // default 2.0 |
| 156 | +} |
| 157 | + |
| 158 | +// ======================================== |
| 159 | +// LEGACY COMPATIBILITY |
| 160 | +// ======================================== |
| 161 | + |
| 162 | +/** Legacy DeviceStatus interface for backwards compatibility */ |
| 163 | +export interface DeviceStatus { |
| 164 | + device_type: string; |
| 165 | + raw_payload: string | null; |
| 166 | + parsed: Record<string, unknown> | null; |
| 167 | + updated_at: number; |
| 168 | + model_name?: string | null; |
| 169 | + connected?: boolean; |
| 170 | + channels?: LightChannel[] | null; |
| 171 | +} |
0 commit comments