Merge pull request #1791 from proddy/feat_modules

Feat modules
This commit is contained in:
Proddy
2024-06-08 16:01:40 +02:00
committed by GitHub
14 changed files with 51 additions and 85 deletions

View File

@@ -327,7 +327,7 @@ const de: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware', // TODO translate
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -327,7 +327,7 @@ const en: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware',
MODULES: 'Modules',
MODULES_UPDATED: 'Modules updated',
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules',
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules',
MODULES_NONE: 'No external modules detected'
};

View File

@@ -327,7 +327,7 @@ const fr: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware', // TODO translate
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -327,7 +327,7 @@ const it: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware', // TODO translate
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -327,7 +327,7 @@ const no: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware', // TODO translate
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -327,7 +327,7 @@ const pl: BaseTranslation = {
UPLOAD_DOWNLOAD_1: 'Wysyłanie/pobieranie ustawień i firmware',
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -327,7 +327,7 @@ const sk: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware', // TODO translate
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -327,7 +327,7 @@ const sv: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware', // TODO translate
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -327,7 +327,7 @@ const tr: Translation = {
UPLOAD_DOWNLOAD_1: 'Upload/Download Settings and Firmware', // TODO translate
MODULES: 'Module', // TODO translate
MODULES_UPDATED: 'Modules updated', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to Activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_DESCRIPTION: 'Click on the Module to activate or de-activate EMS-ESP library modules', // TODO translate
MODULES_NONE: 'No external modules detected' // TODO translate
};

View File

@@ -5,12 +5,9 @@ import { toast } from 'react-toastify';
import CancelIcon from '@mui/icons-material/Cancel';
import CircleIcon from '@mui/icons-material/Circle';
import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew';
import WarningIcon from '@mui/icons-material/Warning';
import { Box, Button, Typography } from '@mui/material';
import * as SystemApi from 'api/system';
import {
Body,
Cell,
@@ -26,11 +23,9 @@ import {
BlockNavigation,
ButtonRow,
FormLoader,
MessageBox,
SectionContent,
useLayoutTitle
} from 'components';
import RestartMonitor from 'framework/system/RestartMonitor';
import { useI18nContext } from 'i18n/i18n-react';
import * as EMSESP from './api';
@@ -40,13 +35,10 @@ import type { ModuleItem, Modules } from './types';
const Modules: FC = () => {
const { LL } = useI18nContext();
const [numChanges, setNumChanges] = useState<number>(0);
const [licenseChanges, setLicenseChanges] = useState<number>(0);
const blocker = useBlocker(numChanges !== 0);
const [selectedModuleItem, setSelectedModuleItem] = useState<ModuleItem>();
const [dialogOpen, setDialogOpen] = useState<boolean>(false);
const [restarting, setRestarting] = useState<boolean>(false);
const [restartNeeded, setRestartNeeded] = useState<boolean>(false);
const {
data: modules,
@@ -56,17 +48,6 @@ const Modules: FC = () => {
initialData: []
});
const { send: restartCommand } = useRequest(SystemApi.restart(), {
immediate: false
});
const restart = async () => {
await restartCommand().catch((error: Error) => {
toast.error(error.message);
});
setRestarting(true);
};
const { send: writeModules } = useRequest(
(data: Modules) => EMSESP.writeModules(data),
{
@@ -140,17 +121,12 @@ const Modules: FC = () => {
return mi.enabled !== mi.o_enabled || mi.license !== mi.o_license;
}
function hasModuleLicenseChanged(mi: ModuleItem) {
return mi.license !== mi.o_license;
}
const updateModuleItem = (updatedItem: ModuleItem) => {
updateState('modules', (data: ModuleItem[]) => {
const new_data = data.map((mi) =>
mi.id === updatedItem.id ? { ...mi, ...updatedItem } : mi
);
setNumChanges(new_data.filter((mi) => hasModulesChanged(mi)).length);
setLicenseChanges(new_data.filter((mi) => hasModuleLicenseChanged(mi)).length);
return new_data;
});
};
@@ -172,7 +148,6 @@ const Modules: FC = () => {
.finally(() => {
setNumChanges(0);
});
setRestartNeeded(licenseChanges > 0);
};
const renderContent = () => {
@@ -213,8 +188,10 @@ const Modules: FC = () => {
<HeaderRow>
<HeaderCell />
<HeaderCell>{LL.NAME(0)}</HeaderCell>
{/* TODO translate */}
<HeaderCell>Author</HeaderCell>
<HeaderCell>{LL.VERSION()}</HeaderCell>
{/* TODO translate */}
<HeaderCell>Message</HeaderCell>
<HeaderCell>{LL.STATUS_OF('')}</HeaderCell>
</HeaderRow>
@@ -247,43 +224,30 @@ const Modules: FC = () => {
)}
</Table>
{restartNeeded ? (
<MessageBox my={2} level="warning" message={LL.RESTART_TEXT(0)}>
<Button
startIcon={<PowerSettingsNewIcon />}
variant="contained"
color="error"
onClick={restart}
>
{LL.RESTART()}
</Button>
</MessageBox>
) : (
<Box mt={1} display="flex" flexWrap="wrap">
<Box flexGrow={1}>
{numChanges !== 0 && (
<ButtonRow>
<Button
startIcon={<CancelIcon />}
variant="outlined"
onClick={onCancel}
color="secondary"
>
{LL.CANCEL()}
</Button>
<Button
startIcon={<WarningIcon color="warning" />}
variant="contained"
color="info"
onClick={saveModules}
>
{LL.APPLY_CHANGES(numChanges)}
</Button>
</ButtonRow>
)}
</Box>
<Box mt={1} display="flex" flexWrap="wrap">
<Box flexGrow={1}>
{numChanges !== 0 && (
<ButtonRow>
<Button
startIcon={<CancelIcon />}
variant="outlined"
onClick={onCancel}
color="secondary"
>
{LL.CANCEL()}
</Button>
<Button
startIcon={<WarningIcon color="warning" />}
variant="contained"
color="info"
onClick={saveModules}
>
{LL.APPLY_CHANGES(numChanges)}
</Button>
</ButtonRow>
)}
</Box>
)}
</Box>
</>
);
};
@@ -291,7 +255,7 @@ const Modules: FC = () => {
return (
<SectionContent>
{blocker ? <BlockNavigation blocker={blocker} /> : null}
{restarting ? <RestartMonitor /> : renderContent()}
{renderContent()}
{selectedModuleItem && (
<ModulesDialog
open={dialogOpen}

View File

@@ -55,9 +55,7 @@ const ModulesDialog = ({
return (
<Dialog sx={dialogStyle} open={open} onClose={onClose}>
<DialogTitle>
{LL.EDIT() + ' ' + LL.MODULES() + ' : ' + editItem.key}
</DialogTitle>
<DialogTitle>{LL.EDIT() + ' ' + editItem.key}</DialogTitle>
<DialogContent dividers>
<Grid container>
<BlockFormControlLabel

View File

@@ -11,13 +11,13 @@
; -DEMSESP_DE_ONLY ; only DE translated entity names
; -DEMSESP_EN_ONLY ; only EN translated entity names
; -DEMSESP_PINGTEST ; send log message every 1/2 second
; my_build_flags = -DEMSESP_TEST
my_build_flags = -DEMSESP_TEST
; my_build_flags = -DEMSESP_DEBUG -DEMSESP_TEST
; my_build_flags = -DEMSESP_DEBUG -DEMSESP_TEST -DEMSESP_PINGTEST
[platformio]
default_envs = esp32_4M
; default_envs = esp32_16M
; default_envs = esp32_4M
default_envs = esp32_16M
; default_envs = lolin_s3
; default_envs = native
; default_envs = debug
@@ -26,10 +26,10 @@ default_envs = esp32_4M
[env]
; upload settings
; for USB
; upload_protocol = esptool
; upload_port = /dev/ttyUSB*
; for OTA
upload_protocol = custom
upload_protocol = esptool
upload_port = /dev/ttyUSB*
; for OTA add scripts/upload.py to extra_scripts
; upload_protocol = custom
custom_emsesp_ip = 10.10.10.173
; custom_emsesp_ip = ems-esp.local
custom_username = admin
@@ -39,7 +39,6 @@ custom_password = admin
lib_deps =
file://../../modules/EMS-ESP-Modules
bblanchon/ArduinoJson@^7.0.4
https://github.com/mathieucarbou/AsyncTCP.git ; based on ESPHome
[env:native]
extra_scripts =
@@ -54,10 +53,16 @@ extra_scripts =
[env:lolin_s3]
extra_scripts =
; pre:scripts/build_interface.py ; comment out if you don't want to re-build the WebUI each time
pre:scripts/build_interface.py ; comment out if you don't want to re-build the WebUI each time
scripts/rename_fw.py
scripts/upload.py
[env:esp32_16M]
extra_scripts =
; pre:scripts/build_interface.py ; comment out if you don't want to re-build the WebUI each time
scripts/rename_fw.py
; scripts/upload.py
[env:custom]
; use for basic ESP boards with 4MB flash
; make sure -D TASMOTA_SDK is also enabled

View File

@@ -218,7 +218,7 @@
#endif
#ifndef EMSESP_DEFAULT_ENTITY_FORMAT
#define EMSESP_DEFAULT_ENTITY_FORMAT 1 // in MQTT discovery, use shortnames and not multiple (prefixed with base)
#define EMSESP_DEFAULT_ENTITY_FORMAT 3 // in MQTT discovery, single instance, shortname, v3.6
#endif
// matches Web UI settings

View File

@@ -50,7 +50,6 @@ void WebModulesService::loop() {
// it adds data to an empty 'root' json object
// and also calls when the Modules web page is refreshed/loaded
void WebModules::read(WebModules & webModules, JsonObject root) {
emsesp_->logger().err("debug: in WebModules::read()"); // TODO remove
JsonDocument doc_modules;
JsonObject root_modules = doc_modules.to<JsonObject>();
moduleLibrary.list(root_modules); // get list the external library modules, put in a json object