Skip to content

Commit

Permalink
feat: adds hook for lighting scene devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ndorin committed Mar 8, 2024
1 parent 9ea5faa commit 2edd889
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib/shared/hooks/interfaces/useILightingScenes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useGetDevice } from 'src/lib/store';
import { LightingState } from 'src/lib/types';
import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';

export function useILightingScenes(key: string): ILightingScenesReturn | undefined {
const { sendMessage } = useWebsocketContext();
const device = useGetDevice<LightingState>(key);

if (!device) return undefined;

const setScene = (scene: string) => {
sendMessage(`/device/${key}/scene`, scene);
};

return { lightingState: device, selectScene: setScene };
}

export interface ILightingScenesReturn {
lightingState: LightingState;
selectScene: (scene: string) => void;
}

0 comments on commit 2edd889

Please sign in to comment.