Skip to content

Commit 8e15f77

Browse files
Merge pull request #73 from PepperDash/selector-updates
fix: add selectors for device interfaces and checking if a device supports a specific interface
2 parents b858949 + 0aa4d06 commit 8e15f77

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/lib/store/runtimeConfig/runtime.hooks.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { useAppSelector } from '../hooks';
22
import {
33
selectClientId,
44
selectDeviceInterfaceSupport,
5+
selectDeviceSupportsInterface,
6+
selectInterfacesForDevice,
57
selectIsTouchpanel,
68
selectRoomKey,
79
selectRuntimeInfo,
@@ -33,3 +35,11 @@ export const useIsTouchpanel = () => useAppSelector(selectIsTouchpanel);
3335

3436
export const useDeviceInterfaceSupport = () =>
3537
useAppSelector(selectDeviceInterfaceSupport);
38+
39+
export const useInterfacesForDevice = (deviceKey: string) =>
40+
useAppSelector(selectInterfacesForDevice(deviceKey));
41+
42+
export const useDeviceSupportsInterface = (
43+
deviceKey: string,
44+
interfaceToCheck: string
45+
) => useAppSelector(selectDeviceSupportsInterface(deviceKey, interfaceToCheck));

src/lib/store/runtimeConfig/runtime.selectors.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,17 @@ export const selectDeviceInterfaceSupport = createSelector(
5252
runtimeState,
5353
(state) => state.roomData.deviceInterfaceSupport
5454
);
55+
56+
export const selectInterfacesForDevice = (deviceKey: string) =>
57+
createSelector(
58+
selectDeviceInterfaceSupport,
59+
(devices) => devices?.[deviceKey]?.interfaces ?? []
60+
);
61+
62+
export const selectDeviceSupportsInterface = (
63+
deviceKey: string,
64+
interfaceToCheck: string
65+
) =>
66+
createSelector(selectInterfacesForDevice(deviceKey), (interfaces) =>
67+
interfaces.includes(interfaceToCheck)
68+
);

0 commit comments

Comments
 (0)