Skip to content

Commit 6e9c3e1

Browse files
committed
refactor: reorganize and enhance type definitions for backend and UI models
1 parent d24b22d commit 6e9c3e1

7 files changed

Lines changed: 398 additions & 310 deletions

File tree

frontend/src/api/commands.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,3 @@ export async function getCommand(
3939
`api/devices/${encodeURIComponent(address)}/commands/${encodeURIComponent(commandId)}`
4040
);
4141
}
42-
43-
/**
44-
* Get light configuration for a device
45-
*/
46-
export async function getLightConfiguration(address: string) {
47-
return fetchJson(`api/configurations/lights/${encodeURIComponent(address)}`);
48-
}

frontend/src/api/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,45 @@ export {
1414
export {
1515
getDeviceStatus,
1616
getLiveStatus,
17-
refreshDeviceStatus
17+
connectDevice,
18+
disconnectDevice,
19+
refreshDeviceStatus,
20+
scanDevices,
1821
} from "./devices";
1922

2023
// Configuration management
2124
export {
25+
// Doser configuration functions
2226
getDoserConfigurations,
2327
getDoserConfiguration,
2428
updateDoserConfiguration,
2529
deleteDoserConfiguration,
30+
// Light configuration functions
2631
getLightConfigurations,
2732
getLightConfiguration,
2833
updateLightConfiguration,
2934
deleteLightConfiguration,
35+
// Configuration summary
3036
getConfigurationSummary,
37+
// Helper functions
3138
formatMacAddress,
3239
getShortDeviceName,
3340
isValidTimeFormat,
3441
sortAutoSettings,
3542
validateDoserConfig,
3643
validateLightProfile,
44+
// System configuration
45+
getSystemTimezone,
46+
// Metadata functions
47+
updateDoserMetadata,
48+
getDoserMetadata,
49+
listDoserMetadata,
50+
updateLightMetadata,
51+
getLightMetadata,
52+
listLightMetadata,
3753
} from "./configurations";
3854

55+
// Configuration types
3956
export type {
4057
DoserHead,
4158
DoserDevice,
@@ -44,4 +61,7 @@ export type {
4461
LightProfile,
4562
LightDevice,
4663
ConfigurationSummary,
64+
SystemTimezone,
65+
DeviceMetadata,
66+
LightMetadata,
4767
} from "./configurations";
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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

Comments
 (0)