From a218c7a781fd9c4c6f914f4f3350727fe8371f86 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 5 Dec 2024 18:41:41 +0100 Subject: [PATCH] Add "duplicate" option to Custom Entities #2266 --- CHANGELOG_LATEST.md | 2 + interface/package.json | 10 +- interface/src/app/main/CustomEntities.tsx | 24 +- .../src/app/main/CustomEntitiesDialog.tsx | 87 +++++-- interface/src/app/main/deviceValue.ts | 2 +- interface/src/app/main/types.ts | 4 +- interface/src/app/main/validators.ts | 3 +- interface/src/i18n/cz/index.ts | 1 + interface/src/i18n/de/index.ts | 3 +- interface/src/i18n/en/index.ts | 1 + interface/src/i18n/fr/index.ts | 1 + interface/src/i18n/it/index.ts | 1 + interface/src/i18n/nl/index.ts | 1 + interface/src/i18n/no/index.ts | 1 + interface/src/i18n/pl/index.ts | 1 + interface/src/i18n/sk/index.ts | 1 + interface/src/i18n/sv/index.ts | 1 + interface/src/i18n/tr/index.ts | 1 + interface/yarn.lock | 225 +++++++----------- src/web/WebCustomEntityService.cpp | 16 +- 20 files changed, 213 insertions(+), 173 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 2a1a406bf..e606ac0e0 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -9,6 +9,8 @@ For more details go to [docs.emsesp.org](https://docs.emsesp.org/). - change enum_heatingtype for remote control [#2268](https://github.com/emsesp/EMS-ESP32/issues/2268) - system service commands [#2182](https://github.com/emsesp/EMS-ESP32/issues/2282) - read 0x02A5 for thermostat CT200 [#2277](https://github.com/emsesp/EMS-ESP32/issues/2277) +- Add "duplicate" option to Custom Entities [#2266](https://github.com/emsesp/EMS-ESP32/discussion/2266) +- Mask bits for bool custom entities ## Fixed diff --git a/interface/package.json b/interface/package.json index b2ffa02a9..398bb26db 100644 --- a/interface/package.json +++ b/interface/package.json @@ -32,8 +32,8 @@ "jwt-decode": "^4.0.0", "mime-types": "^2.1.35", "preact": "^10.25.1", - "react": "^18.3.1", - "react-dom": "^18.3.1", + "react": "^19.0.0", + "react-dom": "^19.0.0", "react-icons": "^5.4.0", "react-router": "^7.0.2", "react-toastify": "^10.0.6", @@ -45,7 +45,7 @@ "@eslint/js": "^9.16.0", "@preact/compat": "^18.3.1", "@preact/preset-vite": "^2.9.2", - "@trivago/prettier-plugin-sort-imports": "^4.3.0", + "@trivago/prettier-plugin-sort-imports": "^5.0.1", "@types/formidable": "^3", "@types/node": "^22.10.1", "@types/react": "^18.3.13", @@ -56,9 +56,9 @@ "formidable": "^3.5.2", "prettier": "^3.4.2", "rollup-plugin-visualizer": "^5.12.0", - "terser": "^5.36.0", + "terser": "^5.37.0", "typescript-eslint": "8.17.0", - "vite": "^6.0.2", + "vite": "^6.0.3", "vite-plugin-imagemin": "^0.6.1", "vite-tsconfig-paths": "^5.1.3" }, diff --git a/interface/src/app/main/CustomEntities.tsx b/interface/src/app/main/CustomEntities.tsx index 4c725bb0f..bbc3f3938 100644 --- a/interface/src/app/main/CustomEntities.tsx +++ b/interface/src/app/main/CustomEntities.tsx @@ -83,7 +83,7 @@ const CustomEntities = () => { const entity_theme = useTheme({ Table: ` - --data-table-library_grid-template-columns: repeat(1, minmax(60px, 1fr)) minmax(80px, auto) 80px 80px 80px 90px; + --data-table-library_grid-template-columns: repeat(1, minmax(60px, 1fr)) minmax(80px, auto) 80px 80px 80px 120px; `, BaseRow: ` font-size: 14px; @@ -195,6 +195,25 @@ const CustomEntities = () => { }); }; + const onDialogDup = (item: EntityItem) => { + setCreating(true); + setSelectedEntityItem({ + id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100), + name: item.name + '_', + ram: item.ram, + device_id: item.device_id, + type_id: item.type_id, + offset: item.offset, + factor: item.factor, + uom: item.uom, + value_type: item.value_type, + writeable: item.writeable, + deleted: false, + value: item.value + }); + setDialogOpen(true); + }; + const addEntityItem = () => { setCreating(true); setSelectedEntityItem({ @@ -220,7 +239,7 @@ const CustomEntities = () => { : typeof value === 'number' ? new Intl.NumberFormat().format(value) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]) - : (value as string); + : (value as string) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]); } function showHex(value: number, digit: number) { @@ -296,6 +315,7 @@ const CustomEntities = () => { creating={creating} onClose={onDialogClose} onSave={onDialogSave} + onDup={onDialogDup} selectedItem={selectedEntityItem} validator={entityItemValidation(entities, selectedEntityItem)} /> diff --git a/interface/src/app/main/CustomEntitiesDialog.tsx b/interface/src/app/main/CustomEntitiesDialog.tsx index becc5f65d..0e08c6d14 100644 --- a/interface/src/app/main/CustomEntitiesDialog.tsx +++ b/interface/src/app/main/CustomEntitiesDialog.tsx @@ -34,6 +34,7 @@ interface CustomEntitiesDialogProps { creating: boolean; onClose: () => void; onSave: (ei: EntityItem) => void; + onDup: (ei: EntityItem) => void; selectedItem: EntityItem; validator: Schema; } @@ -43,6 +44,7 @@ const CustomEntitiesDialog = ({ creating, onClose, onSave, + onDup, selectedItem, validator }: CustomEntitiesDialogProps) => { @@ -91,6 +93,10 @@ const CustomEntitiesDialog = ({ onSave(editItem); }; + const dup = () => { + onDup(editItem); + }; + return ( @@ -128,18 +134,36 @@ const CustomEntitiesDialog = ({ {editItem.ram === 1 && ( - - - + <> + + + + + + {DeviceValueUOM_s.map((val, i) => ( + + {val} + + ))} + + + )} {editItem.ram === 0 && ( <> @@ -255,7 +279,7 @@ const CustomEntitiesDialog = ({ )} + {editItem.value_type === DeviceValueType.BOOL && ( + + 0x + ) + }, + htmlInput: { style: { textTransform: 'uppercase' } } + }} + /> + + )} )} @@ -316,6 +366,15 @@ const CustomEntitiesDialog = ({ > {LL.REMOVE()} + )}