Skip to content

Commit 8142d5c

Browse files
authored
Merge pull request #8 from PepperDash/feature/add-interface-hooks
Feature/add interface hooks
2 parents 6110741 + add6c97 commit 8142d5c

File tree

77 files changed

+1248
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1248
-131
lines changed

src/components/RoomConfigurationDisplay.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
2-
useGetAllDeviceStateFromRoomConfiguration
2+
useGetAllDeviceStateFromRoomConfiguration, useINumeric
33
} from "src/lib/shared";
44
import { useRoomConfiguration } from "src/lib/store/rooms/roomsSelectors";
55
import { useRoomKey } from "src/lib/store/runtimeConfig/runtimeSelectors";
66

77
const RoomConfigurationDisplay = () => {
88
const roomKey = useRoomKey();
99
const config = useRoomConfiguration(roomKey);
10+
const numericKey = useINumeric(roomKey);
1011

1112
useGetAllDeviceStateFromRoomConfiguration({ config });
1213

@@ -19,6 +20,7 @@ const RoomConfigurationDisplay = () => {
1920
<div className="w-100 h-100 d-flex flex-column text-center overflow-auto">
2021
Room Config for {roomKey}:
2122
<pre className="text-wrap overflow-auto">{configData}</pre>
23+
<button {...numericKey.digit0}>0</button>
2224
</div>
2325
</>
2426
);

src/lib/shared/Buttons/IconButton/IconButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ export const IconButton = ({
5656
onPointerLeave?.(e);
5757
}}
5858
>
59-
<MultiIcon
59+
{MultiIcon && <MultiIcon
6060
className={`${iconClassName || classes.iconsm}`}
6161
{...{ active: showActive, disabled }}
62-
/>
62+
/>}
6363
<div className={otherContentClassName}>{otherContent}</div>
6464
</button>
6565
);

src/lib/shared/Buttons/NamedIconButton/NamedIconButton.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ export function NamedIconButton({
55
name,
66
...otherProps
77
}: NamedIconButtonProps) {
8-
return <IconButton multiIcon={iconsDictionary[name]} {...otherProps} />;
8+
const multiIcon = iconsDictionary[name] ?? null;
9+
10+
if(!multiIcon) console.error(`Icon ${name} not found in dictionary`);
11+
12+
return <IconButton multiIcon={multiIcon} {...otherProps} />;
913
}
1014

1115
type NamedIconButtonProps = Omit<IconButtonProps, 'multiIcon'> & {

src/lib/shared/helpers/volumeHelpers.ts

Whitespace-only changes.

src/lib/shared/hooks/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export * from "./useGetDeviceStateFromRoomConfiguration";
2-
// export * from "./usePressHoldRelease"
31
export * from "./interfaces";
2+
export * from "./useDeviceIBasicVolumeWithFeedback";
3+
export * from "./useGetDeviceStateFromRoomConfiguration";
4+
export * from "./usePressHoldRelease";
5+
export * from "./useRoomIBasicVolumeWithFeedback";
6+
+25-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1-
export * from './interfaceNames';
2-
export * from './useIHasPowerControl';
3-
export * from './useIRunDirectRouteAction';
4-
export * from './useMobileControlTouchpanelController';
5-
export * from './useTwoWayDisplayBase';
1+
export * from "./interfaceNames";
2+
export * from "./useAvrControl";
3+
export * from "./useEndpoint";
4+
export * from "./useIBasicVolumeWithFeedback";
5+
export * from "./useIChannelMessenger";
6+
export * from "./useIColor";
7+
export * from "./useICommunicationMonitor";
8+
export * from "./useIDPad";
9+
export * from "./useIDeviceInfoMessenger";
10+
export * from "./useIDvr";
11+
export * from "./useIHasPowerControl";
12+
export * from "./useIHasSelectableItems";
13+
export * from "./useILevelControls";
14+
export * from "./useILightingScenes";
15+
export * from "./useIMatrixRouting";
16+
export * from "./useINumeric";
17+
export * from "./useIRoomEventSchedule";
18+
export * from "./useIRunDirectRouteAction";
19+
export * from "./useIRunRouteAction";
20+
export * from "./useISetTopBoxcontrols";
21+
export * from "./useIShadesOpenCloseStop";
22+
export * from "./useISwitchedOutput";
23+
export * from "./useITransport";
24+
export * from "./useMobileControlTouchpanelController";
25+
export * from "./useTwoWayDisplayBase";
626

Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
export type InterfaceNames = "IHasPowerControl" | "IRoutingFeedback" | "IRunDirectRouteAction" | "IRunRouteAction" | "IRouting";
1+
export type InterfaceNames =
2+
| "IBasicVolumeWithFeedback"
3+
| "ICommunicationMonitor"
4+
| "IDeviceInfoProvider"
5+
| "IHasCurrentSourceInfoChange"
6+
| "IHasInputs"
7+
| "IHasPowerControl"
8+
| "IHasPowerControlWithFeedback"
9+
| "IHasSurroundChannels"
10+
| "ILevelControls"
11+
| "IMatrixRouting"
12+
| "IRouting"
13+
| "IRouting"
14+
| "IRoutingFeedback"
15+
| "IRoutingInputs"
16+
| "IRoutingOutputs"
17+
| "IRoutingSink"
18+
| "IRoutingSinkWithSwitching"
19+
| "IRunDirectRouteAction"
20+
| "IRunDirectRouteAction"
21+
| "IRunRouteAction"
22+
| "IRunRouteActoin"
23+
| string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { useGetDevice } from 'src/lib/store';
2+
import { PowerState } from 'src/lib/types';
3+
import { IHasInputsState } from 'src/lib/types/state/state/IHasInputsState';
4+
import { IHasSurroundSoundModesState } from 'src/lib/types/state/state/IHasSurroundSoundModesState';
5+
import { useDeviceIBasicVolumeWithFeedback } from '../useDeviceIBasicVolumeWithFeedback';
6+
import { IBasicVolumeWithFeedbackReturn } from './useIBasicVolumeWithFeedback';
7+
import { IHasPowerWithFeedbackProps, useIHasPowerControl } from './useIHasPowerControl';
8+
import { IHasSelectableItemsReturn, useIHasSelectableItems } from './useIHasSelectableItems';
9+
import { IHasSurroundChannelsReturn, useIHasSurroundChannels } from './useIHasSurroundChannels';
10+
11+
export function useAvrControl(key: string): AvrReturn | undefined {
12+
const avrState = useGetDevice<PowerState>(key);
13+
const powerControl = useIHasPowerControl(key);
14+
const inputControl = useIHasSelectableItems<IHasInputsState>(key);
15+
const surroundSoundModes = useIHasSelectableItems<IHasSurroundSoundModesState>(key);
16+
const mainVolumeControl = useDeviceIBasicVolumeWithFeedback(key);
17+
const surroundChannels = useIHasSurroundChannels(key);
18+
19+
if (!avrState) return undefined;
20+
21+
return {
22+
avrState,
23+
powerControl,
24+
inputControl: inputControl!,
25+
surroundSoundModes: surroundSoundModes!,
26+
surroundChannels: surroundChannels!,
27+
mainVolumeControl: mainVolumeControl!
28+
};
29+
}
30+
31+
interface AvrReturn {
32+
avrState: PowerState;
33+
powerControl: IHasPowerWithFeedbackProps;
34+
inputControl: IHasSelectableItemsReturn<IHasInputsState>;
35+
surroundSoundModes: IHasSelectableItemsReturn<IHasSurroundSoundModesState>;
36+
surroundChannels: IHasSurroundChannelsReturn;
37+
mainVolumeControl: IBasicVolumeWithFeedbackReturn;
38+
}
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useGetDevice } from 'src/lib';
2+
import { EndpointState } from 'src/lib/types/state/state/endpointState/endpointState';
3+
4+
5+
export function useEndpoint(key: string): IEndpointReturn | undefined {
6+
7+
const endpointState = useGetDevice<EndpointState>(key);
8+
9+
if (!endpointState) return undefined;
10+
11+
return { endpointState };
12+
}
13+
14+
export interface IEndpointReturn {
15+
endpointState: EndpointState;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Volume } from "src/lib/types";
2+
import { useWebsocketContext } from "src/lib/utils/useWebsocketContext";
3+
import { useButtonHeldHeartbeat } from "../useHeldButtonAction";
4+
import { PressHoldReleaseReturn } from "../usePressHoldRelease";
5+
6+
export function useIBasicVolumeWithFeedback(
7+
path: string, volumeState: Volume | undefined
8+
): IBasicVolumeWithFeedbackReturn | undefined {
9+
const { sendMessage, sendSimpleMessage } = useWebsocketContext();
10+
11+
const volumeUp = useButtonHeldHeartbeat(`${path}`, "volumeUp");
12+
const volumeDown = useButtonHeldHeartbeat(`${path}`, "volumeDown");
13+
14+
if (!volumeState) return undefined;
15+
16+
const setLevel = (value: number) =>
17+
sendSimpleMessage(`${path}/level`, value);
18+
19+
const muteToggle = () => sendMessage(`${path}/muteToggle`, null);
20+
21+
const muteOn = () => sendMessage(`${path}/muteOn`, null);
22+
23+
const muteOff = () => sendMessage(`${path}/muteOff`, null);
24+
25+
return {
26+
volumeState,
27+
volumeUp,
28+
volumeDown,
29+
setLevel,
30+
muteToggle,
31+
muteOn,
32+
muteOff,
33+
};
34+
}
35+
36+
export interface IBasicVolumeWithFeedbackReturn {
37+
volumeState: Volume;
38+
volumeUp: PressHoldReleaseReturn;
39+
volumeDown: PressHoldReleaseReturn;
40+
setLevel: (level: number) => void;
41+
muteToggle: () => void;
42+
muteOn: () => void;
43+
muteOff: () => void;
44+
}
45+
46+
export function useGetIBasicVolumeWithFeedback(
47+
path: string, volumeState: Volume | undefined
48+
): IBasicVolumeWithFeedbackReturn | undefined {
49+
const { sendMessage, sendSimpleMessage } = useWebsocketContext();
50+
51+
const volumeUp = useButtonHeldHeartbeat(`${path}`, "volumeUp");
52+
const volumeDown = useButtonHeldHeartbeat(`${path}`, "volumeDown");
53+
54+
if (!volumeState) return undefined;
55+
56+
const setLevel = (value: number) =>
57+
sendSimpleMessage(`${path}/level`, value);
58+
59+
const muteToggle = () => sendMessage(`${path}/muteToggle`, null);
60+
61+
const muteOn = () => sendMessage(`${path}/muteOn`, null);
62+
63+
const muteOff = () => sendMessage(`${path}/muteOff`, null);
64+
65+
return {
66+
volumeState,
67+
volumeUp,
68+
volumeDown,
69+
setLevel,
70+
muteToggle,
71+
muteOn,
72+
muteOff,
73+
};
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useButtonHeldHeartbeat } from '../useHeldButtonAction';
2+
import { PressHoldReleaseReturn } from '../usePressHoldRelease';
3+
4+
export function useIChannelMessenger(key: string): IChannelMessengerProps | undefined {
5+
6+
const path = `/device/${key}`;
7+
8+
const channelUp = useButtonHeldHeartbeat(path, 'chanUp');
9+
10+
const channelDown = useButtonHeldHeartbeat(path, 'chanDown');
11+
12+
const lastChannel = useButtonHeldHeartbeat(path, 'lastChan');
13+
14+
const guide = useButtonHeldHeartbeat(path, 'guide');
15+
16+
const info = useButtonHeldHeartbeat(path, 'info');
17+
18+
const exit = useButtonHeldHeartbeat(path, 'exit');
19+
20+
return { channelUp, channelDown, lastChannel, guide, info, exit };
21+
}
22+
23+
export interface IChannelMessengerProps {
24+
channelUp: PressHoldReleaseReturn;
25+
channelDown: PressHoldReleaseReturn;
26+
lastChannel: PressHoldReleaseReturn;
27+
guide: PressHoldReleaseReturn;
28+
info: PressHoldReleaseReturn;
29+
exit: PressHoldReleaseReturn;
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useButtonHeldHeartbeat } from '../useHeldButtonAction';
2+
import { PressHoldReleaseReturn } from '../usePressHoldRelease';
3+
4+
export function useIColor(key: string): IColorProps | undefined {
5+
const path = `/device/${key}`;
6+
7+
const red = useButtonHeldHeartbeat(path, 'red');
8+
9+
const green = useButtonHeldHeartbeat(path, 'green');
10+
11+
const yellow = useButtonHeldHeartbeat(path, 'yellow');
12+
13+
const blue = useButtonHeldHeartbeat(path, 'blue');
14+
15+
return { red, green, yellow, blue };
16+
}
17+
18+
export interface IColorProps {
19+
red: PressHoldReleaseReturn;
20+
green: PressHoldReleaseReturn;
21+
yellow: PressHoldReleaseReturn;
22+
blue: PressHoldReleaseReturn;
23+
}
24+
25+
26+
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CommunicationMonitorState, useGetDevice } from 'src/lib';
2+
3+
export function useICommunicationMonitor(key: string): ICommunicationMonitorReturn | undefined {
4+
const device = useGetDevice<CommunicationMonitorState>(key);
5+
6+
if (!device) return undefined;
7+
8+
return {
9+
communicationMonitorState: device,
10+
};
11+
}
12+
13+
export interface ICommunicationMonitorReturn {
14+
communicationMonitorState: CommunicationMonitorState;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useButtonHeldHeartbeat } from "../useHeldButtonAction";
2+
import { PressHoldReleaseReturn } from "../usePressHoldRelease";
3+
4+
export function useIDPad(key: string): IDPadProps | undefined {
5+
const path = `/device/${key}`;
6+
7+
const up = useButtonHeldHeartbeat(path, "up");
8+
const down = useButtonHeldHeartbeat(path, "down");
9+
const left = useButtonHeldHeartbeat(path, "left");
10+
const right = useButtonHeldHeartbeat(path, "right");
11+
const select = useButtonHeldHeartbeat(path, "select");
12+
const menu = useButtonHeldHeartbeat(path, "menu");
13+
const exit = useButtonHeldHeartbeat(path, "exit");
14+
15+
return { up, down, left, right, select, menu, exit };
16+
}
17+
18+
export interface IDPadProps {
19+
up: PressHoldReleaseReturn;
20+
down: PressHoldReleaseReturn;
21+
left: PressHoldReleaseReturn;
22+
right: PressHoldReleaseReturn;
23+
select: PressHoldReleaseReturn;
24+
menu: PressHoldReleaseReturn;
25+
exit: PressHoldReleaseReturn;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DeviceInfo, DeviceInfoState, useGetDevice } from 'src/lib';
2+
3+
4+
export function useIDeviceInfoMessenger(key: string): DeviceInfo | undefined {
5+
const device = useGetDevice<DeviceInfoState>(key);
6+
7+
if (!device) return undefined;
8+
9+
return device.deviceInfo || undefined;
10+
11+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useButtonHeldHeartbeat } from '../useHeldButtonAction';
2+
import { PressHoldReleaseReturn } from '../usePressHoldRelease';
3+
4+
export function useIDvr(key: string): IDvrProps | undefined {
5+
const path = `/device/${key}`;
6+
7+
8+
const dvrList = useButtonHeldHeartbeat(path, 'dvrList');
9+
10+
const record = useButtonHeldHeartbeat(path, 'record');
11+
12+
return { dvrList, record };
13+
}
14+
15+
interface IDvrProps {
16+
dvrList: PressHoldReleaseReturn;
17+
record: PressHoldReleaseReturn;
18+
}
19+
20+
21+

0 commit comments

Comments
 (0)