Skip to content

Commit 190cb25

Browse files
Huge refactoring; Implement inverter info
1 parent 99b2f0b commit 190cb25

File tree

102 files changed

+3203
-713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3203
-713
lines changed

src/App.tsx

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
1-
import { NavigationContainer } from '@react-navigation/native';
2-
import moment from 'moment';
3-
import { PersistGate as ReduxPersistGate } from 'redux-persist/integration/react';
4-
51
import type { FC } from 'react';
62
import { StrictMode, useEffect, useMemo, useState } from 'react';
73
import { useTranslation } from 'react-i18next';
8-
import { StatusBar, useColorScheme } from 'react-native';
94
import type { MD3Theme } from 'react-native-paper';
105
import {
116
adaptNavigationTheme,
127
MD3DarkTheme,
138
MD3LightTheme,
149
PaperProvider,
1510
} from 'react-native-paper';
11+
import type { TranslationsType } from 'react-native-paper-dates';
1612
import { registerTranslation } from 'react-native-paper-dates';
1713
import { SafeAreaProvider } from 'react-native-safe-area-context';
1814
import SplashScreen from 'react-native-splash-screen';
1915
import { Provider as ReduxProvider } from 'react-redux';
2016

17+
import { StatusBar, useColorScheme } from 'react-native';
18+
19+
import moment from 'moment';
20+
import { PersistGate as ReduxPersistGate } from 'redux-persist/integration/react';
21+
22+
import { setLanguage } from '@/slices/settings';
23+
2124
import AppOfflineModal from '@/components/modals/AppOfflineModal';
2225
import EnableAppUpdatesModal from '@/components/modals/EnableAppUpdatesModal';
2326
import EnableFetchOpenDtuUpdatesModal from '@/components/modals/EnableFetchOpenDtuUpdatesModal';
2427

25-
import { rootLogger } from '@/utils/log';
28+
import { rootLogging } from '@/utils/log';
2629

2730
import ApiProvider from '@/api/ApiHandler';
2831
import DatabaseProvider from '@/database';
2932
import GithubProvider from '@/github';
3033
import FetchHandler from '@/github/FetchHandler';
31-
import { store, persistor, useAppSelector, useAppDispatch } from '@/store';
34+
import { persistor, store, useAppDispatch, useAppSelector } from '@/store';
3235
import { ReactNavigationDarkTheme, ReactNavigationLightTheme } from '@/style';
36+
import type { SupportedLanguage } from '@/translations';
3337
import NavigationStack from '@/views/navigation/NavigationStack';
34-
import type { TranslationsType } from 'react-native-paper-dates';
38+
3539
import RNLanguageDetector from '@os-team/i18next-react-native-language-detector';
36-
import { setLanguage } from '@/slices/settings';
37-
import type { SupportedLanguage } from '@/translations';
3840
import { useMaterial3Theme } from '@pchmn/expo-material3-theme';
41+
import { NavigationContainer } from '@react-navigation/native';
3942

40-
const log = rootLogger.extend('App');
43+
const log = rootLogging.extend('App');
4144

4245
const App = () => {
4346
/*const onBeforeLift = useCallback(() => {
@@ -178,6 +181,9 @@ const _App: FC = () => {
178181
const { theme: m3theme } = useMaterial3Theme();
179182

180183
const appTheme = useAppSelector(state => state.settings.appTheme);
184+
const allowMaterialYou = useAppSelector(
185+
state => state.settings.allowMaterialYou,
186+
);
181187

182188
const systemModeWantsDark = colorScheme === 'dark';
183189

@@ -194,12 +200,22 @@ const _App: FC = () => {
194200
const theme = useMemo(() => {
195201
if (darkMode) {
196202
log.debug('darkMode');
197-
return { ...DarkTheme, colors: m3theme.dark };
203+
204+
if (allowMaterialYou) {
205+
return { ...DarkTheme, colors: m3theme.dark };
206+
} else {
207+
return DarkTheme;
208+
}
198209
}
199210

200211
log.debug('lightMode');
201-
return { ...LightTheme, colors: m3theme.light };
202-
}, [darkMode, m3theme.dark, m3theme.light]);
212+
213+
if (allowMaterialYou) {
214+
return { ...LightTheme, colors: m3theme.light };
215+
} else {
216+
return LightTheme;
217+
}
218+
}, [allowMaterialYou, darkMode, m3theme.dark, m3theme.light]);
203219

204220
const navigationTheme = useMemo(() => {
205221
if (darkMode) return AdaptedNavigationDarkTheme;

src/api/ApiHandler.tsx

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import {
55
clearOpenDtuState,
66
setDeviceState,
77
setEventLog,
8+
setGridProfile,
9+
setInverterDevice,
810
setInverters,
911
setIsConnected,
12+
setLimitStatus,
13+
setLiveDataFromStatus,
1014
setLiveDataFromWebsocket,
1115
setMqttStatus,
1216
setNetworkStatus,
1317
setNtpStatus,
18+
setPowerStatus,
1419
setSystemStatus,
1520
setTriedToConnect,
1621
} from '@/slices/opendtu';
@@ -22,13 +27,14 @@ import {
2227

2328
import { DeviceState } from '@/types/opendtu/state';
2429

25-
import { rootLogger } from '@/utils/log';
30+
import useAppLanguage from '@/hooks/useAppLanguage';
31+
32+
import { rootLogging } from '@/utils/log';
2633

2734
import OpenDtuApi from '@/api/opendtuapi';
2835
import { useAppDispatch, useAppSelector } from '@/store';
29-
import useAppLanguage from '@/hooks/useAppLanguage';
3036

31-
const log = rootLogger.extend('ApiHandler');
37+
const log = rootLogging.extend('ApiHandler');
3238

3339
// create context for the api handler
3440
export const ApiContext = createContext<OpenDtuApi | undefined>(undefined);
@@ -94,6 +100,14 @@ export const ApiProvider: FC<PropsWithChildren> = ({ children }) => {
94100
dispatch(setDeviceState({ deviceState: DeviceState.Connected, index }));
95101
});
96102

103+
api.registerLiveDataFromStatusHandler((data, valid, index) => {
104+
dispatch(
105+
setTriedToConnect({ triedToConnect: true, index: configIndex }),
106+
);
107+
dispatch(setLiveDataFromStatus({ data, valid, index: configIndex }));
108+
dispatch(setDeviceState({ deviceState: DeviceState.Connected, index }));
109+
});
110+
97111
api.registerHttpStatusHandler(
98112
(
99113
{ systemStatus, networkStatus, ntpStatus, mqttStatus, inverters },
@@ -146,9 +160,27 @@ export const ApiProvider: FC<PropsWithChildren> = ({ children }) => {
146160
dispatch(setEventLog({ data, index, inverterSerial }));
147161
});
148162

163+
api.registerOnPowerStatusHandler((data, index) => {
164+
dispatch(setPowerStatus({ data, index }));
165+
});
166+
167+
api.registerOnLimitStatusHandler((data, index) => {
168+
dispatch(setLimitStatus({ data, index }));
169+
});
170+
171+
api.registerOnInverterDeviceHandler((data, index, inverterSerial) => {
172+
dispatch(setInverterDevice({ data, index, inverterSerial }));
173+
});
174+
175+
api.registerOnGridProfileHandler((data, index, inverterSerial) => {
176+
dispatch(setGridProfile({ data, index, inverterSerial }));
177+
});
178+
149179
log.debug('Connecting API Handler');
150180

151181
api.connect();
182+
183+
api.getLiveData();
152184
} else {
153185
log.debug('Disconnecting API Handler');
154186

@@ -163,6 +195,22 @@ export const ApiProvider: FC<PropsWithChildren> = ({ children }) => {
163195
};
164196
}, [currentConfiguration, configIndex, dispatch, api]);
165197

198+
useEffect(() => {
199+
const func = (): void => {
200+
if (configIndex === null) {
201+
return;
202+
}
203+
204+
api.handle();
205+
};
206+
207+
const interval = setInterval(func, 5000);
208+
209+
return () => {
210+
clearInterval(interval);
211+
};
212+
}, [api, configIndex]);
213+
166214
return <ApiContext.Provider value={api}>{children}</ApiContext.Provider>;
167215
};
168216

0 commit comments

Comments
 (0)