Skip to content

Commit

Permalink
feat: IHasSelectableItems working. Adds IHasSurroundChannels hook and…
Browse files Browse the repository at this point in the history
… state object
  • Loading branch information
ndorin committed Mar 15, 2024
1 parent 32306d6 commit 1ba1a5d
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 60 deletions.
3 changes: 1 addition & 2 deletions src/lib/shared/hooks/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export * from "./useICommunicationMonitor";
export * from "./useIDPad";
export * from "./useIDeviceInfoMessenger";
export * from "./useIDvr";
export * from "./useIHasInputs";
export * from "./useIHasPowerControl";
export * from "./useIHasSelectableItems";
export * from "./useILevelControls";
export * from "./useILightingScenes";
export * from "./useIMatrixRouting";

Check failure on line 14 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.
Expand All @@ -17,7 +17,6 @@ export * from "./useIRunDirectRouteAction";
export * from "./useIRunRouteAction";
export * from "./useISetTopBoxcontrols";
export * from "./useIShadesOpenCloseStop";
export * from "./useISurroundSoundModes";
export * from "./useISwitchedOutput";
export * from "./useITransport";
export * from "./useMobileControlTouchpanelController";
Expand Down
23 changes: 17 additions & 6 deletions src/lib/shared/hooks/interfaces/useAvrControl.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import { useGetDevice } from 'src/lib/store';
import { PowerState } from 'src/lib/types';
import { IHasInputsReturn, useIHasInputs } from './useIHasInputs';
import { IHasInputsState } from 'src/lib/types/state/state/IHasInputsState';
import { IHasSurroundSoundModesState } from 'src/lib/types/state/state/IHasSurroundSoundModesState';
import { useDeviceIBasicVolumeWithFeedback } from '../useDeviceIBasicVolumeWithFeedback';
import { IBasicVolumeWithFeedbackProps } from './useIBasicVolumeWithFeedback';
import { IHasPowerWithFeedbackProps, useIHasPowerControl } from './useIHasPowerControl';



import { IHasSelectableItemsReturn, useIHasSelectableItems } from './useIHasSelectableItems';
import { IHasSurroundChannelsReturn, useIHasSurroundChannels } from './useIHasSurroundChannels';

export function useAvrControl(key: string): AvrReturn | undefined {
const avrState = useGetDevice<PowerState>(key);
const powerControl = useIHasPowerControl(key);
const inputControl = useIHasInputs(key);
const inputControl = useIHasSelectableItems<IHasInputsState>(key);
const surroundSoundModes = useIHasSelectableItems<IHasSurroundSoundModesState>(key);
const mainVolumeControl = useDeviceIBasicVolumeWithFeedback(key);
const surroundChannels = useIHasSurroundChannels(key);

if (!avrState) return undefined;

return {
avrState,
powerControl,
inputControl: inputControl!,
surroundSoundModes: surroundSoundModes!,
surroundChannels: surroundChannels!,
mainVolumeControl: mainVolumeControl!
};
}

interface AvrReturn {
avrState: PowerState;
powerControl: IHasPowerWithFeedbackProps;
inputControl: IHasInputsReturn;
inputControl: IHasSelectableItemsReturn<IHasInputsState>;
surroundSoundModes: IHasSelectableItemsReturn<IHasSurroundSoundModesState>;
surroundChannels: IHasSurroundChannelsReturn;
mainVolumeControl: IBasicVolumeWithFeedbackProps;
}

22 changes: 0 additions & 22 deletions src/lib/shared/hooks/interfaces/useIHasInputs.ts

This file was deleted.

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

/**
* Hook for devices that have selectable items
* TState is the type of the expected state of the device
*/
export function useIHasSelectableItems<TState>(key: string): IHasSelectableItemsReturn<TState> | undefined {
const { sendMessage } = useWebsocketContext();
const device = useGetDevice<TState>(key);

console.log('deviceState', device);

if (!device) return undefined;

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

return { itemsState: device, selectItem };
}

export interface IHasSelectableItemsReturn<TState> {
itemsState: TState;
selectItem: (itemKey: string) => void;
}
29 changes: 29 additions & 0 deletions src/lib/shared/hooks/interfaces/useIHasSurroundChannels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IHasSurroundChannelsState, useGetDevice } from 'src/lib';
import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';


export function useIHasSurroundChannels(key: string): IHasSurroundChannelsReturn | undefined {
const { sendMessage } = useWebsocketContext();

const surroundChannels = useGetDevice<IHasSurroundChannelsState>(key);

const setDefaultChannelLevels = () => {
sendMessage(`/device/${key}/setDefaultChannelLevels`, null);
}

const getFullStatus = () => {
if(surroundChannels?.surroundChannels === undefined) return;
const channelKeys = Object.keys(surroundChannels?.surroundChannels);
channelKeys.forEach((channel) => {
sendMessage(`/device/${key}/${channel}/fullStatus`, null);
});
}

return { surroundChannels, setDefaultChannelLevels, getFullStatus };
}

export interface IHasSurroundChannelsReturn {
surroundChannels: IHasSurroundChannelsState | undefined;
setDefaultChannelLevels: () => void;
getFullStatus: () => void;
}
32 changes: 16 additions & 16 deletions src/lib/shared/hooks/interfaces/useISurroundSoundModes.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { useGetDevice } from 'src/lib/store';
import { SurroundSoundModeState } from 'src/lib/types';
import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';
// import { useGetDevice } from 'src/lib/store';
// import { SurroundSoundModeState } from 'src/lib/types';
// import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';


export function useISurroundSoundModes(key: string): ISurroundSoundModesReturn | undefined {
const { sendMessage } = useWebsocketContext();
const device = useGetDevice<SurroundSoundModeState>(key);
// export function useISurroundSoundModes(key: string): ISurroundSoundModesReturn | undefined {
// const { sendMessage } = useWebsocketContext();
// const device = useGetDevice<SurroundSoundModeState>(key);

if (!device) return undefined;
// if (!device) return undefined;

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

return { modeState: device, setMode };
}
// return { modeState: device, setMode };
// }

export interface ISurroundSoundModesReturn {
modeState: SurroundSoundModeState;
setMode: (inputKey: string) => void;
}
// export interface ISurroundSoundModesReturn {
// modeState: SurroundSoundModeState;
// setMode: (inputKey: string) => void;
// }
7 changes: 4 additions & 3 deletions src/lib/shared/hooks/interfaces/useTwoWayDisplayBase.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { useGetDevice } from "src/lib/store";
import { DisplayState } from "src/lib/types";
import { IHasInputsReturn, useIHasInputs } from './useIHasInputs';
import { IHasInputsState } from 'src/lib/types/state/state/IHasInputsState';
import {
IHasPowerWithFeedbackProps,
useIHasPowerControl,
} from "./useIHasPowerControl";
import { IHasSelectableItemsReturn, useIHasSelectableItems } from './useIHasSelectableItems';


export function useTwoWayDisplayBase(
key: string
): TwoWayDisplayBaseReturn | undefined {
const displayState = useGetDevice<DisplayState>(key);
const powerControl = useIHasPowerControl(key);
const inputControl = useIHasInputs(key);
const inputControl = useIHasSelectableItems<IHasInputsState>(key);

// bail if state is undefined
if (!displayState) return undefined;
Expand All @@ -35,6 +36,6 @@ export function useTwoWayDisplayBase(
interface TwoWayDisplayBaseReturn {
displayState: DisplayState;
powerControl: IHasPowerWithFeedbackProps;
inputControl: IHasInputsReturn;
inputControl: IHasSelectableItemsReturn<IHasInputsState>;
powerFb: { powerOnFb: boolean; powerOffFb: boolean };
}
4 changes: 2 additions & 2 deletions src/lib/types/interfaces/ISelectableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { IKeyName } from 'src/lib';

export interface ISelectableItem extends IKeyName {
isSelected: boolean;
name: string;
key: string;
Name: string;
Key: string;
}
5 changes: 5 additions & 0 deletions src/lib/types/state/state/IHasInputsState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IHasSelectableItemsState } from './IHasSelectableItemsState';

export interface IHasInputsState {
inputs: IHasSelectableItemsState;
}
8 changes: 8 additions & 0 deletions src/lib/types/state/state/IHasSelectableItemsState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ISelectableItem } from '../../interfaces/ISelectableItem';

export interface IHasSelectableItemsState {
currentItem?: string;

items: Record<string, ISelectableItem>;
}

5 changes: 5 additions & 0 deletions src/lib/types/state/state/IHasSurroundChannelsState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Volume } from '../volume/volume';

export interface IHasSurroundChannelsState {
surroundChannels: Record<string, Volume>;
}
5 changes: 5 additions & 0 deletions src/lib/types/state/state/IHasSurroundSoundModesState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IHasSelectableItemsState } from './IHasSelectableItemsState';

export interface IHasSurroundSoundModesState {
surroundSoundModes: IHasSelectableItemsState;
}
8 changes: 0 additions & 8 deletions src/lib/types/state/state/InputsState.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/lib/types/state/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export * from './DeviceInfoState';
export * from './DeviceState';
export * from './DisplayState';
export * from './EnvironmentState';
export * from './InputsState';
export * from './IHasInputsState';
export * from './IHasSelectableItemsState';
export * from './IHasSurroundChannelsState';
export * from './IHasSurroundSoundModesState';
export * from './LevelControlsState';
export * from './LightingState';
export * from './MatrixRoutingState';
Expand Down

0 comments on commit 1ba1a5d

Please sign in to comment.