-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds interface hooks for IHasInputs, ILevelControls, IMatrixRouting and AvrControl including state interface types
- Loading branch information
Showing
18 changed files
with
212 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IOnline { | ||
isOnline: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './iKeyName'; | ||
export * from './IKeyName'; | ||
export * from './IOnline'; | ||
export * from './version'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ export interface DeviceInfoState { | |
SerialNumber: string; | ||
|
||
FirmwareVersion: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IKeyName } from '../../interfaces'; | ||
|
||
export interface InputsState { | ||
currentInputKey?: string; | ||
|
||
inputs: Record<string, Input>; | ||
} | ||
|
||
export interface Input extends IKeyName { | ||
isSelected: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { SignalType } from 'src/lib/shared'; | ||
import { IKeyName } from '../../interfaces'; | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface PowerState { | ||
powerState: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters