-
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.
feat: IHasSelectableItems working. Adds IHasSurroundChannels hook and…
… state object
- Loading branch information
Showing
14 changed files
with
122 additions
and
60 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,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; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
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,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
29
src/lib/shared/hooks/interfaces/useIHasSurroundChannels.ts
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,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
32
src/lib/shared/hooks/interfaces/useISurroundSoundModes.ts
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,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; | ||
// } |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IHasSelectableItemsState } from './IHasSelectableItemsState'; | ||
|
||
export interface IHasInputsState { | ||
inputs: IHasSelectableItemsState; | ||
} |
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,8 @@ | ||
import { ISelectableItem } from '../../interfaces/ISelectableItem'; | ||
|
||
export interface IHasSelectableItemsState { | ||
currentItem?: string; | ||
|
||
items: Record<string, ISelectableItem>; | ||
} | ||
|
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,5 @@ | ||
import { Volume } from '../volume/volume'; | ||
|
||
export interface IHasSurroundChannelsState { | ||
surroundChannels: 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,5 @@ | ||
import { IHasSelectableItemsState } from './IHasSelectableItemsState'; | ||
|
||
export interface IHasSurroundSoundModesState { | ||
surroundSoundModes: IHasSelectableItemsState; | ||
} |
This file was deleted.
Oops, something went wrong.
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