Update SodistoreMax battery view in frontend

Also, fixed sessions for SodistoreMax
This commit is contained in:
Noe 2025-04-29 16:05:33 +02:00
parent 2cb15d6478
commit 8db16313e9
5 changed files with 117 additions and 66 deletions

View File

@ -30,8 +30,12 @@ function App() {
const navigate = useNavigate(); const navigate = useNavigate();
const searchParams = new URLSearchParams(location.search); const searchParams = new URLSearchParams(location.search);
const username = searchParams.get('username'); const username = searchParams.get('username');
const { setAccessToSalimax, setAccessToSalidomo, setAccessToSodiohome } = const {
useContext(ProductIdContext); setAccessToSalimax,
setAccessToSalidomo,
setAccessToSodiohome,
setAccessToSodistore
} = useContext(ProductIdContext);
const [language, setLanguage] = useState('en'); const [language, setLanguage] = useState('en');
const getTranslations = () => { const getTranslations = () => {
@ -73,10 +77,13 @@ function App() {
setAccessToSalimax(response.data.accessToSalimax); setAccessToSalimax(response.data.accessToSalimax);
setAccessToSalidomo(response.data.accessToSalidomo); setAccessToSalidomo(response.data.accessToSalidomo);
setAccessToSodiohome(response.data.accessToSodiohome); setAccessToSodiohome(response.data.accessToSodiohome);
setAccessToSodistore(response.data.accessToSodistoreMax);
if (response.data.accessToSalimax) { if (response.data.accessToSalimax) {
navigate(routes.installations); navigate(routes.installations);
} else if (response.data.accessToSalidomo) { } else if (response.data.accessToSalidomo) {
navigate(routes.salidomo_installations); navigate(routes.salidomo_installations);
} else if (response.data.accessToSodistoreMax) {
navigate(routes.sodistore_installations);
} else { } else {
navigate(routes.sodiohome_installations); navigate(routes.sodiohome_installations);
} }

View File

@ -36,8 +36,12 @@ function Login() {
const theme = useTheme(); const theme = useTheme();
const context = useContext(UserContext); const context = useContext(UserContext);
const { setAccessToSalimax, setAccessToSalidomo,setAccessToSodiohome } = const {
useContext(ProductIdContext); setAccessToSalimax,
setAccessToSalidomo,
setAccessToSodiohome,
setAccessToSodistore
} = useContext(ProductIdContext);
const navigate = useNavigate(); const navigate = useNavigate();
if (!context) { if (!context) {
@ -79,6 +83,7 @@ function Login() {
setAccessToSalimax(response.data.accessToSalimax); setAccessToSalimax(response.data.accessToSalimax);
setAccessToSalidomo(response.data.accessToSalidomo); setAccessToSalidomo(response.data.accessToSalidomo);
setAccessToSodiohome(response.data.accessToSodioHome); setAccessToSodiohome(response.data.accessToSodioHome);
setAccessToSodistore(response.data.accessToSodistoreMax);
if (rememberMe) { if (rememberMe) {
cookies.set('rememberedUsername', username, { path: '/' }); cookies.set('rememberedUsername', username, { path: '/' });
@ -86,9 +91,9 @@ function Login() {
} }
if (response.data.accessToSalimax) { if (response.data.accessToSalimax) {
navigate(routes.installations); navigate(routes.installations);
} else if(response.data.accessToSalidomo){ } else if (response.data.accessToSalidomo) {
navigate(routes.salidomo_installations); navigate(routes.salidomo_installations);
} else{ } else {
navigate(routes.sodiohome_installations); navigate(routes.sodiohome_installations);
} }
} }

View File

@ -39,6 +39,7 @@ function BatteryView(props: BatteryViewProps) {
if (props.values === null && props.connected == true) { if (props.values === null && props.connected == true) {
return null; return null;
} }
const currentLocation = useLocation(); const currentLocation = useLocation();
const navigate = useNavigate(); const navigate = useNavigate();
const sortedBatteryView = const sortedBatteryView =
@ -215,8 +216,16 @@ function BatteryView(props: BatteryViewProps) {
<TableCell align="center">Voltage</TableCell> <TableCell align="center">Voltage</TableCell>
<TableCell align="center">SoC</TableCell> <TableCell align="center">SoC</TableCell>
<TableCell align="center">Temperature</TableCell> <TableCell align="center">Temperature</TableCell>
<TableCell align="center">Warnings</TableCell> {product === 0 ? (
<TableCell align="center">Alarms</TableCell> <TableCell align="center">Warnings</TableCell>
) : (
<TableCell align="center">Min Cell Voltage</TableCell>
)}
{product === 0 ? (
<TableCell align="center">Alarms</TableCell>
) : (
<TableCell align="center">Max Cell Voltage</TableCell>
)}
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
@ -248,7 +257,7 @@ function BatteryView(props: BatteryViewProps) {
> >
{product == 0 {product == 0
? battery.FwVersion ? battery.FwVersion
: battery.BatteryDeligreenDataRecord.FwVersion} : battery.BatteryDeligreenDataRecord.FwVersion + '.0'}
</TableCell> </TableCell>
<TableCell <TableCell
sx={{ sx={{
@ -271,9 +280,9 @@ function BatteryView(props: BatteryViewProps) {
? '#FF033E' ? '#FF033E'
: '#32CD32' : '#32CD32'
: battery.BatteryDeligreenDataRecord : battery.BatteryDeligreenDataRecord
.TotalBatteryVoltage < 44 || .TotalBatteryVoltage < 32 ||
battery.BatteryDeligreenDataRecord battery.BatteryDeligreenDataRecord
.TotalBatteryVoltage > 57 .TotalBatteryVoltage > 63
? '#FF033E' ? '#FF033E'
: '#32CD32', : '#32CD32',
color: color:
@ -305,7 +314,7 @@ function BatteryView(props: BatteryViewProps) {
: battery.Soc < 50 : battery.Soc < 50
? '#ffbf00' ? '#ffbf00'
: '#32CD32' : '#32CD32'
: battery.BatteryDeligreenDataRecord.Soc < 20 : battery.BatteryDeligreenDataRecord.Soc <= 10
? '#FF033E' ? '#FF033E'
: battery.BatteryDeligreenDataRecord.Soc < 50 : battery.BatteryDeligreenDataRecord.Soc < 50
? '#ffbf00' ? '#ffbf00'
@ -341,27 +350,15 @@ function BatteryView(props: BatteryViewProps) {
: '#32CD32' : '#32CD32'
}; };
} else { } else {
const avg =
(battery.BatteryDeligreenDataRecord.TemperaturesList
.CellTemperature1 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature2 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature3 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature4) /
4;
return { return {
width: '10%', width: '10%',
textAlign: 'center', textAlign: 'center',
backgroundColor: backgroundColor:
avg > 300 battery.BatteryDeligreenDataRecord
.TemperaturesList.EnvironmentTemperature > 50 ||
battery.BatteryDeligreenDataRecord
.TemperaturesList.EnvironmentTemperature < 0
? '#FF033E' ? '#FF033E'
: avg > 280
? '#ffbf00'
: avg < 245
? '#008FFB'
: '#32CD32' : '#32CD32'
}; };
} }
@ -369,17 +366,8 @@ function BatteryView(props: BatteryViewProps) {
> >
{product === 0 {product === 0
? battery.Temperatures.Cells.Average + ' °C' ? battery.Temperatures.Cells.Average + ' °C'
: ( : battery.BatteryDeligreenDataRecord.TemperaturesList
(battery.BatteryDeligreenDataRecord.TemperaturesList .EnvironmentTemperature + ' °C'}
.CellTemperature1 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature2 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature3 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature4) /
4
).toFixed(1) + ' °C'}
</TableCell> </TableCell>
{product === 0 && ( {product === 0 && (
@ -452,6 +440,61 @@ function BatteryView(props: BatteryViewProps) {
</TableCell> </TableCell>
</> </>
)} )}
{product === 3 && (
<>
{(() => {
const cellVoltagesString =
battery.BatteryDeligreenDataRecord.CellVoltage ||
'';
const cellVoltagesArray: number[] = cellVoltagesString
.split(',')
.map((v) => parseFloat(v.trim()))
.filter((v) => !isNaN(v)); // Filter invalid numbers
const minVoltage = Math.min(...cellVoltagesArray);
const maxVoltage = Math.max(...cellVoltagesArray);
return (
<>
<TableCell
sx={{
width: '20%',
textAlign: 'center',
padding: '8px',
backgroundColor:
minVoltage < 1.82 || minVoltage > 3.94
? '#FF033E'
: minVoltage < 2 || minVoltage > 3.8
? '#ffbf00'
: '#32CD32',
color: minVoltage != 0 ? 'black' : 'white'
}}
>
{minVoltage.toFixed(3)} V{' '}
</TableCell>
<TableCell
sx={{
width: '20%',
textAlign: 'center',
padding: '8px',
backgroundColor:
maxVoltage < 1.82 || maxVoltage > 3.94
? '#FF033E'
: maxVoltage < 2 || maxVoltage > 3.8
? '#ffbf00'
: '#32CD32',
color: maxVoltage != 0 ? 'black' : 'white'
}}
>
{maxVoltage.toFixed(3)} V{' '}
</TableCell>
</>
);
})()}
</>
)}
</TableRow> </TableRow>
))} ))}
</TableBody> </TableBody>

View File

@ -148,14 +148,6 @@ function Installation(props: singleInstallationProps) {
console.log(res[timestamp]); console.log(res[timestamp]);
setValues(res[timestamp]); setValues(res[timestamp]);
// Set values asynchronously with delay
// setValues(
// extractValues({
// time: UnixTime.fromTicks(parseInt(timestamp, 10)),
// value: res[timestamp]
// })
// );
// Wait for 2 seconds before processing next timestamp
await timeout(2000); await timeout(2000);
} }
@ -182,6 +174,9 @@ function Installation(props: singleInstallationProps) {
} }
timestampToFetch = timestampToFetch.later(TimeSpan.fromSeconds(1)); timestampToFetch = timestampToFetch.later(TimeSpan.fromSeconds(1));
} }
if (i == 30) {
return false;
}
} }
}; };
useEffect(() => { useEffect(() => {

View File

@ -200,25 +200,26 @@ function SidebarMenu() {
</ListItem> </ListItem>
</List> </List>
)} )}
{accessToSodistore && (
<List component="div"> <List component="div">
<ListItem component="div"> <ListItem component="div">
<Button <Button
disableRipple disableRipple
component={RouterLink} component={RouterLink}
onClick={closeSidebar} onClick={closeSidebar}
to="/sodistore_installations" to="/sodistore_installations"
startIcon={<BrightnessLowTwoToneIcon />} startIcon={<BrightnessLowTwoToneIcon />}
> >
<Box sx={{ marginTop: '3px' }}> <Box sx={{ marginTop: '3px' }}>
<FormattedMessage <FormattedMessage
id="sodistore" id="sodistore"
defaultMessage="Sodistore" defaultMessage="Sodistore"
/> />
</Box> </Box>
</Button> </Button>
</ListItem> </ListItem>
</List> </List>
)}
{accessToSalidomo && ( {accessToSalidomo && (
<List component="div"> <List component="div">