Skip to content

Commit

Permalink
feat: adds new interface hooks
Browse files Browse the repository at this point in the history
Adds interface hooks for IHasInputs, ILevelControls, IMatrixRouting and AvrControl including state interface types
  • Loading branch information
ndorin committed Mar 13, 2024
1 parent 2edd889 commit 0d1d07a
Show file tree
Hide file tree
Showing 18 changed files with 212 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/lib/shared/hooks/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
export * from './interfaceNames';
// export * from './useIBasicVolumeWithFeedback';
export * from "./useAvrControl";
export * from './useIBasicVolumeWithFeedback';
export * from './useIChannelMessenger';
export * from './useIColor';
export * from './useIDPad';
export * from './useIDvr';
export * from './useIHasInputs';
export * from './useIHasPowerControl';
export * from './useILevelControls';
export * from './useIMatrixRouting';

Check failure on line 11 in src/lib/shared/hooks/interfaces/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './useIMatrixRouting' or its corresponding type declarations.
export * from './useINumeric';
export * from './useIRunDirectRouteAction';
export * from './useIRunRouteAction';
Expand Down
24 changes: 23 additions & 1 deletion src/lib/shared/hooks/interfaces/interfaceNames.ts
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
export type InterfaceNames = "IHasPowerControl" | "IRoutingFeedback" | "IRunDirectRouteAction" | "IRunRouteAction" | "IRouting";
export type InterfaceNames =
| "IBasicVolumeWithFeedback"
| "ICommunicationMonitor"
| "IDeviceInfoProvider"
| "IHasCurrentSourceInfoChange"
| "IHasInputs"
| "IHasPowerControl"
| "IHasPowerControlWithFeedback"
| "IHasSurroundChannels"
| "ILevelControls"
| "IMatrixRouting"
| "IRouting"
| "IRouting"
| "IRoutingFeedback"
| "IRoutingInputs"
| "IRoutingOutputs"
| "IRoutingSink"
| "IRoutingSinkWithSwitching"
| "IRunDirectRouteAction"
| "IRunDirectRouteAction"
| "IRunRouteAction"
| "IRunRouteActoin"
| string;
28 changes: 28 additions & 0 deletions src/lib/shared/hooks/interfaces/useAvrControl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useGetDevice } from 'src/lib/store';
import { PowerState } from 'src/lib/types';
import { IHasInputsReturn, useIHasInputs } from './useIHasInputs';
import { IHasPowerWithFeedbackProps, useIHasPowerControl } from './useIHasPowerControl';




export function useAvrControl(key: string): AvrReturn | undefined {
const avrState = useGetDevice<PowerState>(key);
const powerControl = useIHasPowerControl(key);
const inputControl = useIHasInputs(key);

if (!avrState) return undefined;

return {
avrState,
powerControl,
inputControl: inputControl!,
};
}

interface AvrReturn {
avrState: PowerState;
powerControl: IHasPowerWithFeedbackProps;
inputControl: IHasInputsReturn;
}

24 changes: 24 additions & 0 deletions src/lib/shared/hooks/interfaces/useIHasInputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useGetDevice } from 'src/lib/store';
import { InputsState } from 'src/lib/types';
import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';


export function useIHasInputs(key: string): IHasInputsReturn | undefined {
const { sendMessage } = useWebsocketContext();
const device = useGetDevice<InputsState>(key);

console.log('device', device);

if (!device) return undefined;

const setInput = (inputKey: string) => {
sendMessage(`/device/${key}/${inputKey}`, null);
};

return { inputsState: device, setInput };
}

export interface IHasInputsReturn {
inputsState: InputsState;
setInput: (inputKey: string) => void;
}
37 changes: 37 additions & 0 deletions src/lib/shared/hooks/interfaces/useILevelControls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useGetDevice } from 'src/lib/store';
import { LevelControlsState } from 'src/lib/types/state/state/LevelControlsState';
import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';


export function useILevelControls(key: string): ILevelControlsReturn | undefined {
const { sendMessage, sendSimpleMessage } = useWebsocketContext();
const device = useGetDevice<LevelControlsState>(key);

if (!device) return undefined;

const setLevel = (levelKey: string, value: number) =>
sendSimpleMessage(`${levelKey}/level`, value);

const muteToggle = (levelKey: string) => sendMessage(`${levelKey}/muteToggle`, null);

const muteOn = (levelKey: string) => sendMessage(`${levelKey}/muteOn`, null);

const muteOff = (levelKey: string) => sendMessage(`${levelKey}/muteOff`, null);

return {
levelState: device,
setLevel,
muteToggle,
muteOn,
muteOff,
};
}

export interface ILevelControlsReturn {
levelState: LevelControlsState;
setLevel: (levelKey: string, value: number) => void;
muteToggle: (levelKey: string) => void;
muteOn: (levelKey: string) => void;
muteOff: (levelKey: string) => void;
}

33 changes: 33 additions & 0 deletions src/lib/shared/hooks/interfaces/useIMatrixrouting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useGetDevice } from 'src/lib/store';
import { MatrixRoutingState } from 'src/lib/types/state/state/MatrixRoutingState';
import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';
import { SignalType } from './useIRunDirectRouteAction';

/**
* Hook to allow routing and feedback of a matrix switcher that implements IMatrixRouting
* @param key key of matrix routing device
* @returns
*/
export function useIMatrixRouting(key: string): IMatrixRoutingReturn | undefined {
const { sendMessage } = useWebsocketContext();
const device = useGetDevice<MatrixRoutingState>(key);

if (!device) return undefined;

const setRoute = (route: RouteRequest) => {
sendMessage(`/device/${key}/route`, route);
};

return { matrixRoutingState: device, setRoute };
}

export interface IMatrixRoutingReturn {
matrixRoutingState: MatrixRoutingState;
setRoute: (route: RouteRequest) => void;
}

interface RouteRequest {
inputKey: string;
outputKey: string;
routeType: SignalType;
}
4 changes: 4 additions & 0 deletions src/lib/shared/hooks/interfaces/useTwoWayDisplayBase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useGetDevice } from "src/lib/store";
import { DisplayState } from "src/lib/types";
import { IHasInputsReturn, useIHasInputs } from './useIHasInputs';
import {
IHasPowerWithFeedbackProps,
useIHasPowerControl,
Expand All @@ -11,6 +12,7 @@ export function useTwoWayDisplayBase(
): TwoWayDisplayBaseReturn | undefined {
const displayState = useGetDevice<DisplayState>(key);
const powerControl = useIHasPowerControl(key);
const inputControl = useIHasInputs(key);

// bail if state is undefined
if (!displayState) return undefined;
Expand All @@ -25,12 +27,14 @@ export function useTwoWayDisplayBase(
return {
displayState,
powerControl,
inputControl: inputControl!,
powerFb: { powerOnFb, powerOffFb },
};
}

interface TwoWayDisplayBaseReturn {
displayState: DisplayState;
powerControl: IHasPowerWithFeedbackProps;
inputControl: IHasInputsReturn;
powerFb: { powerOnFb: boolean; powerOffFb: boolean };
}
3 changes: 3 additions & 0 deletions src/lib/types/interfaces/IOnline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IOnline {
isOnline: boolean;
}
3 changes: 2 additions & 1 deletion src/lib/types/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './iKeyName';
export * from './IKeyName';

Check failure on line 1 in src/lib/types/interfaces/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './IKeyName' or its corresponding type declarations.
export * from './IOnline';
export * from './version';

2 changes: 1 addition & 1 deletion src/lib/types/state/state/DeviceInfoState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export interface DeviceInfoState {
SerialNumber: string;

FirmwareVersion: string;
}
}
5 changes: 3 additions & 2 deletions src/lib/types/state/state/DeviceState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IKeyName } from '../../interfaces/iKeyName';
import { InterfaceNames } from 'src/lib/shared';
import { IKeyName } from '../../interfaces/IKeyName';

Check failure on line 2 in src/lib/types/state/state/DeviceState.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../interfaces/IKeyName' or its corresponding type declarations.
import { CommMonitorState } from './CommMonitorState';

/** Base device state class */
Expand Down Expand Up @@ -27,7 +28,7 @@ export interface DeviceState extends IKeyName {
/**
* The interfaces implmented on this instance of the device
*/
interfaces: string[];
interfaces: InterfaceNames[];

commMonitor?: CommMonitorState;
}
3 changes: 0 additions & 3 deletions src/lib/types/state/state/EnvironmentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { DeviceState } from './DeviceState';
import { ShadeState } from './ShadeState';

export interface EnvironmentState extends DeviceState {
key: string;

name: string;

lightingScenes: LightingScene[];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SourceListItem } from '../sourceListItem';
import { DeviceState } from './DeviceState';

export interface IHasCurrentSourceInfoChangeState {
export interface IHasCurrentSourceInfoChangeState extends DeviceState {
currentSourceKey: string;
currentSource: SourceListItem;
}
11 changes: 11 additions & 0 deletions src/lib/types/state/state/InputsState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IKeyName } from '../../interfaces';

Check failure on line 1 in src/lib/types/state/state/InputsState.ts

View workflow job for this annotation

GitHub Actions / build

Module '"../../interfaces"' has no exported member 'IKeyName'.

export interface InputsState {
currentInputKey?: string;

inputs: Record<string, Input>;
}

export interface Input extends IKeyName {
isSelected: boolean;
}
6 changes: 6 additions & 0 deletions src/lib/types/state/state/LevelControlsState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Volume } from '../volume/volume';
import { DeviceState } from './DeviceState';

export interface LevelControlsState extends DeviceState {
levelControls: Record<string, Volume>
}
23 changes: 23 additions & 0 deletions src/lib/types/state/state/MatrixRoutingState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { SignalType } from 'src/lib/shared';
import { IKeyName } from '../../interfaces';

Check failure on line 2 in src/lib/types/state/state/MatrixRoutingState.ts

View workflow job for this annotation

GitHub Actions / build

Module '"../../interfaces"' has no exported member 'IKeyName'.
import { IOnline } from '../../interfaces/IOnline';
import { DeviceState } from './DeviceState';

export interface MatrixRoutingState {
inputs: Record<string, InputSlot>;
outputs: Record<string, OutputSlot>;
}

export interface InputSlot extends DeviceState, IKeyName, IOnline, IVideoSync {
txDeviceKey: string;
}

export interface OutputSlot extends IKeyName {
rxDeviceKey: string;

currentRoutes: Record<SignalType, InputSlot>;
}

export interface IVideoSync {
videoSyncDetected: boolean;
}
3 changes: 3 additions & 0 deletions src/lib/types/state/state/PowerState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PowerState {
powerState: boolean;
}
4 changes: 4 additions & 0 deletions src/lib/types/state/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ export * from './CommMonitorState';
export * from './DeviceState';
export * from './DisplayState';
export * from './EnvironmentState';
export * from './InputsState';
export * from './LevelControlsState';
export * from './LightingState';
export * from './MatrixRoutingState';
export * from './MeetingInfo';
export * from './PowerState';
export * from './PresetChannel';
export * from './RoomState';
export * from './RoutingState';
Expand Down

0 comments on commit 0d1d07a

Please sign in to comment.