diff --git a/web2/components/light/light-list.tsx b/web2/components/light/light-list.tsx index 1347b0c3..712f6c1c 100644 --- a/web2/components/light/light-list.tsx +++ b/web2/components/light/light-list.tsx @@ -159,6 +159,11 @@ export function LightList() { variant: "destructive", }); }); + + dispatch({ + type: "UPDATE_ALL_STATE", + payload: { state: anyLightOn ? "OFF" : "ON" }, + }); }; return ( diff --git a/web2/components/light/state.ts b/web2/components/light/state.ts index 468d4e68..c7d9fa6d 100644 --- a/web2/components/light/state.ts +++ b/web2/components/light/state.ts @@ -19,6 +19,10 @@ type Action = device: Device; payload: Partial>; } + | { + type: "UPDATE_ALL_STATE"; + payload: Partial>; + } | { type: "SET_LIGHTS"; lights: z.infer[]; @@ -37,10 +41,7 @@ type Action = name: string; }; -function devicesAreEqual( - a: Device, - b: Device -) { +function devicesAreEqual(a: Device, b: Device) { return ( a.device_id === b.device_id && a.device_type === b.device_type && @@ -63,6 +64,14 @@ export function reducer( : light ), }; + case "UPDATE_ALL_STATE": + return { + ...state, + lights: state.lights.map((light) => ({ + ...light, + state: action.payload, + })), + }; case "SET_LIGHTS": return { ...state,