-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from OpenDTU-App/multi-device-preparations
- Loading branch information
Showing
25 changed files
with
306 additions
and
93 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
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
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,7 @@ | ||
import { useAppSelector } from '@/store'; | ||
|
||
const useDeviceIndex = (): number | null => { | ||
return useAppSelector(state => state.settings.selectedDtuConfig); | ||
}; | ||
|
||
export default useDeviceIndex; |
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,22 @@ | ||
import type { EqualityFn } from 'react-redux'; | ||
|
||
import type { OpenDTUDeviceState } from '@/types/opendtu/state'; | ||
|
||
import useDeviceIndex from '@/hooks/useDeviceIndex'; | ||
|
||
import { useAppSelector } from '@/store'; | ||
|
||
const useDtuState = <T>( | ||
selector: (state: OpenDTUDeviceState | undefined) => T, | ||
equalityFn?: EqualityFn<T | undefined>, | ||
): T | undefined => { | ||
const index = useDeviceIndex(); | ||
|
||
return useAppSelector( | ||
state => | ||
index === null ? undefined : selector(state.opendtu.dtuStates[index]), | ||
equalityFn, | ||
); | ||
}; | ||
|
||
export default useDtuState; |
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,7 +1,15 @@ | ||
import useDeviceIndex from '@/hooks/useDeviceIndex'; | ||
|
||
import { useAppSelector } from '@/store'; | ||
|
||
const useIsConnected = (): boolean => { | ||
return useAppSelector(state => state.opendtu.isConnected); | ||
const index = useDeviceIndex(); | ||
|
||
return useAppSelector(state => | ||
index === null | ||
? false | ||
: state.opendtu.dtuStates[index]?.isConnected ?? false, | ||
); | ||
}; | ||
|
||
export default useIsConnected; |
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,7 +1,15 @@ | ||
import useDeviceIndex from '@/hooks/useDeviceIndex'; | ||
|
||
import { useAppSelector } from '@/store'; | ||
|
||
const useTriedToConnect = (): boolean => { | ||
return useAppSelector(state => state.opendtu.triedToConnect); | ||
const index = useDeviceIndex(); | ||
|
||
return useAppSelector(state => | ||
index === null | ||
? false | ||
: state.opendtu.dtuStates[index]?.triedToConnect ?? false, | ||
); | ||
}; | ||
|
||
export default useTriedToConnect; |
Oops, something went wrong.