Skip to content

Commit

Permalink
Merge pull request #1558 from proddy/dev
Browse files Browse the repository at this point in the history
renamed Web custom entity TSX class, remove bogus URI handler from Web customization, added icon to Custom table
  • Loading branch information
proddy authored Jan 14, 2024
2 parents bbfdb0f + 7760726 commit ded7b54
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 69 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
- changed HA name and grouping to be consistent [#1528](https://github.com/emsesp/EMS-ESP32/issues/1528)
- MQTT autodiscovery in Domoticz not working [#1360](https://github.com/emsesp/EMS-ESP32/issues/1528)
- dhw comfort for new ems+, [#1495](https://github.com/emsesp/EMS-ESP32/issues/1495)
- added writeable icon to Web's Custom Entity page for each entity shown in the table

## Changed

- HA don't set entity_category to Diagnostic/Configuration for EMS entities [#1459](https://github.com/emsesp/EMS-ESP32/discussions/1459)
- Upgraded ArduinoJson to 7.0.0 #1538
- upgraded ArduinoJson to 7.0.0 #1538 and then 7.0.1
2 changes: 1 addition & 1 deletion interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"preact": "^10.19.3",
"prettier": "^3.2.1",
"prettier": "^3.2.2",
"rollup-plugin-visualizer": "^5.12.0",
"terser": "^5.26.0",
"vite": "^5.0.11",
Expand Down
4 changes: 2 additions & 2 deletions interface/src/project/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Tab } from '@mui/material';
import { Navigate, Route, Routes } from 'react-router-dom';

import SettingsApplication from './SettingsApplication';
import SettingsCustomEntities from './SettingsCustomEntities';
import SettingsCustomization from './SettingsCustomization';
import SettingsEntities from './SettingsEntities';
import SettingsScheduler from './SettingsScheduler';
import type { FC } from 'react';
import { RouterTabs, useRouterTab, useLayoutTitle } from 'components';
Expand All @@ -27,7 +27,7 @@ const Settings: FC = () => {
<Route path="application" element={<SettingsApplication />} />
<Route path="customization" element={<SettingsCustomization />} />
<Route path="scheduler" element={<SettingsScheduler />} />
<Route path="customentities" element={<SettingsEntities />} />
<Route path="customentities" element={<SettingsCustomEntities />} />
<Route path="*" element={<Navigate replace to="/settings/application" />} />
</Routes>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AddIcon from '@mui/icons-material/Add';
import CancelIcon from '@mui/icons-material/Cancel';
import EditOutlinedIcon from '@mui/icons-material/EditOutlined';
import WarningIcon from '@mui/icons-material/Warning';
import { Button, Typography, Box } from '@mui/material';
import { Table, Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-library/react-table-library/table';
Expand All @@ -11,7 +12,7 @@ import { useBlocker } from 'react-router-dom';

import { toast } from 'react-toastify';

import SettingsEntitiesDialog from './SettingsEntitiesDialog';
import SettingsCustomEntitiesDialog from './SettingsCustomEntitiesDialog';
import * as EMSESP from './api';
import { DeviceValueTypeNames, DeviceValueUOM_s } from './types';
import { entityItemValidation } from './validators';
Expand All @@ -21,7 +22,7 @@ import { ButtonRow, FormLoader, SectionContent, BlockNavigation } from 'componen

import { useI18nContext } from 'i18n/i18n-react';

const SettingsEntities: FC = () => {
const SettingsCustomEntities: FC = () => {
const { LL } = useI18nContext();
const [numChanges, setNumChanges] = useState<number>(0);
const blocker = useBlocker(numChanges !== 0);
Expand Down Expand Up @@ -219,7 +220,10 @@ const SettingsEntities: FC = () => {
<Body>
{tableList.map((ei: EntityItem) => (
<Row key={ei.name} item={ei} onClick={() => editEntityItem(ei)}>
<Cell>{ei.name}</Cell>
<Cell>
{ei.name}&nbsp;
{ei.writeable && <EditOutlinedIcon color="primary" sx={{ fontSize: 12 }} />}
</Cell>
<Cell>{showHex(ei.device_id as number, 2)}</Cell>
<Cell>{showHex(ei.type_id as number, 3)}</Cell>
<Cell>{ei.offset}</Cell>
Expand All @@ -244,7 +248,7 @@ const SettingsEntities: FC = () => {
{renderEntity()}

{selectedEntityItem && (
<SettingsEntitiesDialog
<SettingsCustomEntitiesDialog
open={dialogOpen}
creating={creating}
onClose={onDialogClose}
Expand Down Expand Up @@ -284,4 +288,4 @@ const SettingsEntities: FC = () => {
);
};

export default SettingsEntities;
export default SettingsCustomEntities;
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { useI18nContext } from 'i18n/i18n-react';
import { updateValue } from 'utils';
import { validate } from 'validators';

type SettingsEntitiesDialogProps = {
type SettingsCustomEntitiesDialogProps = {
open: boolean;
creating: boolean;
onClose: () => void;
Expand All @@ -39,14 +39,14 @@ type SettingsEntitiesDialogProps = {
validator: Schema;
};

const SettingsEntitiesDialog = ({
const SettingsCustomEntitiesDialog = ({
open,
creating,
onClose,
onSave,
selectedItem,
validator
}: SettingsEntitiesDialogProps) => {
}: SettingsCustomEntitiesDialogProps) => {
const { LL } = useI18nContext();
const [editItem, setEditItem] = useState<EntityItem>(selectedItem);
const [fieldErrors, setFieldErrors] = useState<ValidateFieldsError>();
Expand Down Expand Up @@ -249,4 +249,4 @@ const SettingsEntitiesDialog = ({
);
};

export default SettingsEntitiesDialog;
export default SettingsCustomEntitiesDialog;
4 changes: 2 additions & 2 deletions interface/src/project/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const writeSchedule = (data: any) => alovaInstance.Post('/rest/schedule',

// SettingsEntities
export const readCustomEntities = () =>
alovaInstance.Get<EntityItem[]>('/rest/customentities', {
alovaInstance.Get<EntityItem[]>('/rest/customEntities', {
name: 'entities',
transformData(data: any) {
return data.entities.map((ei: EntityItem) => ({
Expand All @@ -106,4 +106,4 @@ export const readCustomEntities = () =>
}));
}
});
export const writeCustomEntities = (data: any) => alovaInstance.Post('/rest/customentities', data);
export const writeCustomEntities = (data: any) => alovaInstance.Post('/rest/customEntities', data);
10 changes: 5 additions & 5 deletions interface/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ __metadata:
lodash-es: "npm:^4.17.21"
mime-types: "npm:^2.1.35"
preact: "npm:^10.19.3"
prettier: "npm:^3.2.1"
prettier: "npm:^3.2.2"
react: "npm:latest"
react-dom: "npm:latest"
react-dropzone: "npm:^14.2.3"
Expand Down Expand Up @@ -7091,12 +7091,12 @@ __metadata:
languageName: node
linkType: hard

"prettier@npm:^3.2.1":
version: 3.2.1
resolution: "prettier@npm:3.2.1"
"prettier@npm:^3.2.2":
version: 3.2.2
resolution: "prettier@npm:3.2.2"
bin:
prettier: bin/prettier.cjs
checksum: a26d26a74ba5cbf23a9741074ceef4f53a08ced03c42449dc9615ecd08ada9d19d5247ad2b0dfb15b2c8e57ec9f516074627b85b9f03270b08c184c64e7d8f64
checksum: ab9470ff6cfd19f28bc424f22e58f2fc4a488d148b9384f6c3739235017c8350cae82b3697392c23d9b098b9d8dfaa1cc9ff4ef25fd45f54c97b95f9cc7a1f7d
languageName: node
linkType: hard

Expand Down
109 changes: 73 additions & 36 deletions mock-api/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,28 +414,35 @@ const signin = {
};
const generate_token = { token: '1234' };

//
// EMS-ESP Project specific
//
const EMSESP_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'settings';
const EMSESP_CORE_DATA_ENDPOINT = REST_ENDPOINT_ROOT + 'coreData';
const EMSESP_SENSOR_DATA_ENDPOINT = REST_ENDPOINT_ROOT + 'sensorData';
const EMSESP_DEVICES_ENDPOINT = REST_ENDPOINT_ROOT + 'devices';
const EMSESP_SCANDEVICES_ENDPOINT = REST_ENDPOINT_ROOT + 'scanDevices';

// const EMSESP_DEVICEDATA_ENDPOINT = REST_ENDPOINT_ROOT + 'deviceData/:id';
// const EMSESP_DEVICEENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'deviceEntities/:id';

const EMSESP_DEVICEDATA_ENDPOINT = REST_ENDPOINT_ROOT + 'deviceData';
const EMSESP_DEVICEENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'deviceEntities';

const EMSESP_STATUS_ENDPOINT = REST_ENDPOINT_ROOT + 'status';
const EMSESP_BOARDPROFILE_ENDPOINT = REST_ENDPOINT_ROOT + 'boardProfile';
const EMSESP_WRITE_VALUE_ENDPOINT = REST_ENDPOINT_ROOT + 'writeDeviceValue';
const EMSESP_WRITE_SENSOR_ENDPOINT = REST_ENDPOINT_ROOT + 'writeTemperatureSensor';
const EMSESP_WRITE_ANALOG_ENDPOINT = REST_ENDPOINT_ROOT + 'writeAnalogSensor';
const EMSESP_WRITE_DEVICEVALUE_ENDPOINT = REST_ENDPOINT_ROOT + 'writeDeviceValue';
const EMSESP_WRITE_TEMPSENSOR_ENDPOINT = REST_ENDPOINT_ROOT + 'writeTemperatureSensor';
const EMSESP_WRITE_ANALOGSENSOR_ENDPOINT = REST_ENDPOINT_ROOT + 'writeAnalogSensor';
const EMSESP_CUSTOMIZATION_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'customizationEntities';
const EMSESP_RESET_CUSTOMIZATIONS_ENDPOINT = REST_ENDPOINT_ROOT + 'resetCustomizations';
const EMSESP_WRITE_SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'schedule';
const EMSESP_WRITE_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'entities';

const EMSESP_SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'schedule';
const EMSESP_CUSTOMENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'customEntities';

const EMSESP_GET_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'getSettings';
const EMSESP_GET_CUSTOMIZATIONS_ENDPOINT = REST_ENDPOINT_ROOT + 'getCustomizations';
const EMSESP_GET_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'getEntities';
const EMSESP_GET_SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'getSchedule';

const EMSESP_SYSTEM_INFO_ENDPOINT = API_ENDPOINT_ROOT + 'system/info';

const emsesp_info = {
System: {
Expand Down Expand Up @@ -742,7 +749,7 @@ const emsesp_coredata = {
d: 1,
p: 1,
v: '',
e: 1
e: 2
}
]
};
Expand Down Expand Up @@ -788,7 +795,7 @@ const status = {
// 1 - RC35 thermo
// 2 - RC20 thermo
// 3 - Buderus GB125 boiler
// 4 - RC100 themo
// 4 - RC100 thermostat
// 5 - Mixer MM10
// 6 - Solar SM10
// 7 - Nefit Trendline boiler
Expand Down Expand Up @@ -2048,6 +2055,11 @@ const emsesp_devicedata_99 = {
u: 1,
id: '00boiler_flowtemp',
c: 'boiler_flowtemp'
},
{
v: 0,
u: 0,
id: '00wwExtra1'
}
]
};
Expand All @@ -2065,7 +2077,20 @@ let emsesp_customentities = {
name: 'boiler_flowtemp',
uom: 1,
value_type: 1,
writeable: true
writeable: true,
value: 30
},
{
id: 1,
device_id: 16,
type_id: 797,
offset: 0,
factor: 1,
name: 'wwExtra1',
uom: 0,
value_type: 0,
writeable: false,
value: 0
}
]
};
Expand Down Expand Up @@ -2458,15 +2483,16 @@ router
// EMS-ESP Project stuff
//
router
.post(EMSESP_RESET_CUSTOMIZATIONS_ENDPOINT, async (request: any) => {
return new Response('OK', { status: 200 });
})

// EMS-ESP Settings
.get(EMSESP_SETTINGS_ENDPOINT, () => new Response(JSON.stringify(settings), { headers }))
.post(EMSESP_SETTINGS_ENDPOINT, async (request: any) => {
settings = await request.json();
return new Response('OK', { status: 200 }); // no restart needed
// return new Response('OK', { status: 205 }); // restart needed
})

// Device Dashboard Data
.get(EMSESP_CORE_DATA_ENDPOINT, () => new Response(JSON.stringify(emsesp_coredata), { headers }))
.get(EMSESP_SENSOR_DATA_ENDPOINT, () => new Response(JSON.stringify(emsesp_sensordata), { headers }))
.get(EMSESP_DEVICES_ENDPOINT, () => new Response(JSON.stringify(emsesp_devices), { headers }))
Expand Down Expand Up @@ -2527,6 +2553,8 @@ router
return new Response(encoder.encode(emsesp_deviceentities_7), { headers });
}
})

// Customization
.post(EMSESP_CUSTOMIZATION_ENTITIES_ENDPOINT, async (request: any) => {
const content = await request.json();
const id = content.id;
Expand All @@ -2549,17 +2577,28 @@ router
}
return new Response('OK', { status: 200 });
})
.post(EMSESP_WRITE_SCHEDULE_ENDPOINT, async (request: any) => {
.post(EMSESP_RESET_CUSTOMIZATIONS_ENDPOINT, async (request: any) => {
return new Response('OK', { status: 200 });
})

// Scheduler
.post(EMSESP_SCHEDULE_ENDPOINT, async (request: any) => {
const content = await request.json();
emsesp_schedule = content;
return new Response('OK', { status: 200 });
})
.post(EMSESP_WRITE_ENTITIES_ENDPOINT, async (request: any) => {
.get(EMSESP_SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers }))

// Custom Entities
.post(EMSESP_CUSTOMENTITIES_ENDPOINT, async (request: any) => {
const content = await request.json();
emsesp_customentities = content;
return new Response('OK', { status: 200 });
})
.post(EMSESP_WRITE_VALUE_ENDPOINT, async (request: any) => {
.get(EMSESP_CUSTOMENTITIES_ENDPOINT, () => new Response(JSON.stringify(emsesp_customentities), { headers }))

// Device Dashboard
.post(EMSESP_WRITE_DEVICEVALUE_ENDPOINT, async (request: any) => {
const content = await request.json();
const command = content.c;
const value = content.v;
Expand Down Expand Up @@ -2603,7 +2642,9 @@ router
await delay(1000); // wait to show spinner
return new Response('OK', { status: 200 }); // or 400 for bad request
})
.post(EMSESP_WRITE_SENSOR_ENDPOINT, async (request: any) => {

// Temperature & Analog Sensors
.post(EMSESP_WRITE_TEMPSENSOR_ENDPOINT, async (request: any) => {
const ts = await request.json();
var objIndex = emsesp_sensordata.ts.findIndex((obj) => obj.id == ts.id_str);
if (objIndex !== -1) {
Expand All @@ -2612,7 +2653,7 @@ router
}
return new Response('OK', { status: 200 });
})
.post(EMSESP_WRITE_ANALOG_ENDPOINT, async (request: any) => {
.post(EMSESP_WRITE_ANALOGSENSOR_ENDPOINT, async (request: any) => {
const as = await request.json();
var objIndex = emsesp_sensordata.as.findIndex((obj) => obj.g == as.gpio);
if (objIndex === -1) {
Expand Down Expand Up @@ -2645,6 +2686,8 @@ router

return new Response('OK', { status: 200 });
})

// Settings - board profile
.post(EMSESP_BOARDPROFILE_ENDPOINT, async (request: any) => {
const content = await request.json();
const board_profile = content.code;
Expand Down Expand Up @@ -2774,26 +2817,18 @@ router
}

return new Response(JSON.stringify(data), { headers });
});
})

// API and calls
const SYSTEM_INFO_ENDPOINT = API_ENDPOINT_ROOT + 'system/info';
const GET_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'getSettings';
const GET_CUSTOMIZATIONS_ENDPOINT = REST_ENDPOINT_ROOT + 'getCustomizations';
const GET_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'getEntities';
const GET_SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'getSchedule';
const SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'schedule';
const ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'customentities';
// Download Settings
.get(EMSESP_GET_SETTINGS_ENDPOINT, () => new Response(JSON.stringify(emsesp_info), { headers }))
.get(EMSESP_GET_CUSTOMIZATIONS_ENDPOINT, () => new Response(JSON.stringify(emsesp_deviceentities_1), { headers }))
.get(EMSESP_GET_ENTITIES_ENDPOINT, () => new Response(JSON.stringify(emsesp_customentities), { headers }))
.get(EMSESP_GET_SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers }));

// API which are usually POST for security
router
.post(SYSTEM_INFO_ENDPOINT, () => new Response(JSON.stringify(emsesp_info), { headers }))
.get(SYSTEM_INFO_ENDPOINT, () => new Response(JSON.stringify(emsesp_info), { headers }))
.get(GET_SETTINGS_ENDPOINT, () => new Response(JSON.stringify(emsesp_info), { headers }))
.get(GET_CUSTOMIZATIONS_ENDPOINT, () => new Response(JSON.stringify(emsesp_deviceentities_1), { headers }))
.get(GET_ENTITIES_ENDPOINT, () => new Response(JSON.stringify(emsesp_customentities), { headers }))
.get(GET_SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers }))
.get(SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers }))
.get(ENTITIES_ENDPOINT, () => new Response(JSON.stringify(emsesp_customentities), { headers }))
.post(EMSESP_SYSTEM_INFO_ENDPOINT, () => new Response(JSON.stringify(emsesp_info), { headers }))
.get(EMSESP_SYSTEM_INFO_ENDPOINT, () => new Response(JSON.stringify(emsesp_info), { headers }))
.post(API_ENDPOINT_ROOT, async (request: any) => {
const data = await request.json();
if (data.device === 'system') {
Expand All @@ -2807,7 +2842,9 @@ router
return new Response('Not Found', { status: 404 });
});

//
// Event Source // TODO fix event source later
//

// const data = {
// t: '000+00:00:00.000',
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.6.5-dev.8"
#define EMSESP_APP_VERSION "3.6.5-dev.9"
Loading

0 comments on commit ded7b54

Please sign in to comment.