diff --git a/CHANGELOG.md b/CHANGELOG.md index 9456e4be6..841f9bb9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Power entities - Optional input of BSSID for AP connection -- Return empty json if no entries in scheduler/custom/analogsnesor/temperaturesensor +- Return empty json if no entries in scheduler/custom/analogsensor/temperaturesensor ## Fixed diff --git a/interface/src/contexts/authentication/Authentication.tsx b/interface/src/contexts/authentication/Authentication.tsx index bf9e05bae..bc972aaa1 100644 --- a/interface/src/contexts/authentication/Authentication.tsx +++ b/interface/src/contexts/authentication/Authentication.tsx @@ -1,6 +1,6 @@ import { useRequest } from 'alova'; import { useCallback, useEffect, useState } from 'react'; -import { useNavigate } from 'react-router-dom'; +import { redirect } from 'react-router-dom'; import { toast } from 'react-toastify'; import { AuthenticationContext } from './context'; import type { FC } from 'react'; @@ -15,8 +15,6 @@ import { useI18nContext } from 'i18n/i18n-react'; const Authentication: FC = ({ children }) => { const { LL } = useI18nContext(); - const navigate = useNavigate(); - const [initialized, setInitialized] = useState(false); const [me, setMe] = useState(); @@ -36,11 +34,12 @@ const Authentication: FC = ({ children }) => { } }; - const signOut = (redirect: boolean) => { + const signOut = (doRedirect: boolean) => { AuthenticationApi.clearAccessToken(); setMe(undefined); - if (redirect) { - navigate('/'); + if (doRedirect) { + // navigate('/'); + redirect('/'); } }; diff --git a/interface/src/project/DashboardDevices.tsx b/interface/src/project/DashboardDevices.tsx index acf4f1fbc..3d00c1d9c 100644 --- a/interface/src/project/DashboardDevices.tsx +++ b/interface/src/project/DashboardDevices.tsx @@ -1,6 +1,7 @@ import CommentsDisabledOutlinedIcon from '@mui/icons-material/CommentsDisabledOutlined'; import EditIcon from '@mui/icons-material/Edit'; import EditOffOutlinedIcon from '@mui/icons-material/EditOffOutlined'; +import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered'; import DownloadIcon from '@mui/icons-material/GetApp'; import HighlightOffIcon from '@mui/icons-material/HighlightOff'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; @@ -35,6 +36,7 @@ import { useRequest } from 'alova'; import { useState, useContext, useEffect, useCallback, useLayoutEffect } from 'react'; import { IconContext } from 'react-icons'; +import { useNavigate } from 'react-router-dom'; import { toast } from 'react-toastify'; import DashboardDevicesDialog from './DashboardDevicesDialog'; import DeviceIcon from './DeviceIcon'; @@ -62,6 +64,8 @@ const DashboardDevices: FC = () => { const [showDeviceInfo, setShowDeviceInfo] = useState(false); const [selectedDevice, setSelectedDevice] = useState(); + const navigate = useNavigate(); + const { data: coreData, send: readCoreData } = useRequest(() => EMSESP.readCoreData(), { initialData: { connected: true, @@ -264,13 +268,16 @@ const DashboardDevices: FC = () => { }, [escFunction]); const refreshData = () => { - if (deviceValueDialogOpen) { - return; + if (!deviceValueDialogOpen) { + selectedDevice ? void readDeviceData(selectedDevice) : void readCoreData(); } - if (selectedDevice) { - void readDeviceData(selectedDevice); + }; + + const customize = () => { + if (selectedDevice == 99) { + navigate('/settings/customentities'); } else { - void readCoreData(); + navigate('/settings/customization', { state: selectedDevice }); } }; @@ -496,10 +503,19 @@ const DashboardDevices: FC = () => { - {shown_data.length + ' ' + LL.ENTITIES(shown_data.length)} + {LL.SHOWING() + + ' ' + + shown_data.length + + '/' + + coreData.devices[deviceIndex].e + + ' ' + + LL.ENTITIES(shown_data.length)} setShowDeviceInfo(true)}> + + + diff --git a/interface/src/project/SettingsCustomization.tsx b/interface/src/project/SettingsCustomization.tsx index 110535f34..183d32778 100644 --- a/interface/src/project/SettingsCustomization.tsx +++ b/interface/src/project/SettingsCustomization.tsx @@ -23,7 +23,7 @@ import { Table, Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-li import { useTheme } from '@table-library/react-table-library/theme'; import { useRequest } from 'alova'; import { useState, useEffect, useCallback } from 'react'; -import { unstable_useBlocker as useBlocker } from 'react-router-dom'; +import { unstable_useBlocker as useBlocker, useLocation } from 'react-router-dom'; import { toast } from 'react-toastify'; import EntityMaskToggle from './EntityMaskToggle'; @@ -52,19 +52,23 @@ const SettingsCustomization: FC = () => { const [restarting, setRestarting] = useState(false); const [restartNeeded, setRestartNeeded] = useState(false); const [deviceEntities, setDeviceEntities] = useState([]); - const [selectedDevice, setSelectedDevice] = useState(-1); const [confirmReset, setConfirmReset] = useState(false); const [selectedFilters, setSelectedFilters] = useState(0); const [search, setSearch] = useState(''); const [selectedDeviceEntity, setSelectedDeviceEntity] = useState(); const [dialogOpen, setDialogOpen] = useState(false); + // fetch devices first + const { data: devices } = useRequest(EMSESP.readDevices); + + // const { state } = useLocation(); + const [selectedDevice, setSelectedDevice] = useState(useLocation().state || -1); + const [selectedDeviceName, setSelectedDeviceName] = useState(''); + const { send: resetCustomizations } = useRequest(EMSESP.resetCustomizations(), { immediate: false }); - const { data: devices } = useRequest(EMSESP.readDevices); - const { send: writeCustomizationEntities } = useRequest((data) => EMSESP.writeCustomizationEntities(data), { immediate: false }); @@ -176,6 +180,22 @@ const SettingsCustomization: FC = () => { } }, [deviceEntities]); + useEffect(() => { + if (devices && selectedDevice !== -1) { + void readDeviceEntities(selectedDevice); + const id = devices.devices.findIndex((d) => d.i === selectedDevice); + if (id === -1) { + setSelectedDevice(-1); + setSelectedDeviceName(''); + } else { + setSelectedDeviceName(devices.devices[id].tn || ''); + setNumChanges(0); + setRestartNeeded(false); + } + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [devices, selectedDevice]); + const restart = async () => { await restartCommand().catch((error) => { toast.error(error.message); @@ -246,16 +266,6 @@ const SettingsCustomization: FC = () => { ); }; - const changeSelectedDevice = (event: React.ChangeEvent) => { - if (devices) { - const selected_device = parseInt(event.target.value, 10); - setSelectedDevice(selected_device); - setNumChanges(0); - void readDeviceEntities(devices?.devices[selected_device].i); - setRestartNeeded(false); - } - }; - const resetCustomization = async () => { try { await resetCustomizations(); @@ -314,30 +324,21 @@ const SettingsCustomization: FC = () => { return; } - await writeCustomizationEntities({ id: devices?.devices[selectedDevice].i, entity_ids: masked_entities }).catch( - (error) => { - if (error.message === 'Reboot required') { - setRestartNeeded(true); - } else { - toast.error(error.message); - } + await writeCustomizationEntities({ id: selectedDevice, entity_ids: masked_entities }).catch((error) => { + if (error.message === 'Reboot required') { + setRestartNeeded(true); + } else { + toast.error(error.message); } - ); + }); setOriginalSettings(deviceEntities); } }; const renderDeviceList = () => ( <> - + {LL.CUSTOMIZATIONS_HELP_1()}. - - ={LL.CUSTOMIZATIONS_HELP_2()}   - ={LL.CUSTOMIZATIONS_HELP_3()}   - ={LL.CUSTOMIZATIONS_HELP_4()}   - ={LL.CUSTOMIZATIONS_HELP_5()}   - ={LL.CUSTOMIZATIONS_HELP_6()} - { fullWidth value={selectedDevice} disabled={numChanges !== 0} - onChange={changeSelectedDevice} + onChange={(e) => setSelectedDevice(parseInt(e.target.value))} margin="normal" select > {LL.SELECT_DEVICE()}... - {devices.devices.map((device: DeviceShort, index) => ( - + {devices.devices.map((device: DeviceShort) => ( + {device.s} ))} @@ -363,14 +364,19 @@ const SettingsCustomization: FC = () => { ); const renderDeviceData = () => { - if (deviceEntities.length === 0) { - return; - } - const shown_data = deviceEntities.filter((de) => filter_entity(de)); return ( <> + + + ={LL.CUSTOMIZATIONS_HELP_2()}   + ={LL.CUSTOMIZATIONS_HELP_3()}   + ={LL.CUSTOMIZATIONS_HELP_4()}   + ={LL.CUSTOMIZATIONS_HELP_5()}   + ={LL.CUSTOMIZATIONS_HELP_6()} + + { - {LL.SHOWING()} {shown_data.length}/{deviceEntities.length} + {LL.SHOWING()} {shown_data.length}/{deviceEntities.length} {LL.ENTITIES(deviceEntities.length)} @@ -467,7 +473,7 @@ const SettingsCustomization: FC = () => { {formatName(de, false)} ( - + {de.id} ) @@ -506,7 +512,7 @@ const SettingsCustomization: FC = () => { {LL.DEVICE_ENTITIES()} {devices && renderDeviceList()} - {renderDeviceData()} + {deviceEntities && renderDeviceData()} {restartNeeded && ( diff --git a/lib/AsyncTCP/src/AsyncTCP.cpp b/lib/AsyncTCP/src/AsyncTCP.cpp index 868bc4984..00bab60ad 100644 --- a/lib/AsyncTCP/src/AsyncTCP.cpp +++ b/lib/AsyncTCP/src/AsyncTCP.cpp @@ -85,7 +85,7 @@ typedef struct { } lwip_event_packet_t; static QueueHandle_t _async_queue; -static TaskHandle_t _async_service_task_handle = NULL; +static TaskHandle_t _async_service_task_handle = NULL; SemaphoreHandle_t _slots_lock; @@ -1084,13 +1084,13 @@ bool AsyncClient::getNoDelay() { return tcp_nagle_disabled(_pcb); } -void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt){ - if(ms!=0) { +void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt) { + if (ms != 0) { _pcb->so_options |= SOF_KEEPALIVE; //Turn on TCP Keepalive for the given pcb // Set the time between keepalive messages in milli-seconds - _pcb->keep_idle = ms; + _pcb->keep_idle = ms; _pcb->keep_intvl = ms; - _pcb->keep_cnt = cnt; //The number of unanswered probes required to force closure of the socket + _pcb->keep_cnt = cnt; //The number of unanswered probes required to force closure of the socket } else { _pcb->so_options &= ~SOF_KEEPALIVE; //Turn off TCP Keepalive for the given pcb } diff --git a/mock-api/server.js b/mock-api/server.js index 82fc53438..b5e96205e 100644 --- a/mock-api/server.js +++ b/mock-api/server.js @@ -1816,7 +1816,7 @@ const emsesp_devicedata_99 = { }; // CUSTOM ENTITIES -let emsesp_entities = { +let emsesp_customentities = { // entities: [] entities: [ { @@ -1876,10 +1876,10 @@ let emsesp_schedule = { }; // CUSTOMIZATIONS -const emsesp_deviceentities_1 = [{}]; -const emsesp_deviceentities_3 = [{}]; -const emsesp_deviceentities_5 = [{}]; -const emsesp_deviceentities_6 = [{}]; +const emsesp_deviceentities_1 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; +const emsesp_deviceentities_3 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; +const emsesp_deviceentities_5 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; +const emsesp_deviceentities_6 = [{ v: 'dummy value', n: 'dummy name', id: 'dummy', m: 0, w: false }]; const emsesp_deviceentities_2 = [ { @@ -2205,6 +2205,7 @@ rest_server.get(EMSESP_SENSOR_DATA_ENDPOINT, (req, res) => { res.json(emsesp_sensordata); }); rest_server.get(EMSESP_DEVICES_ENDPOINT, (req, res) => { + console.log('send back list of devices...'); res.json(emsesp_devices); }); rest_server.post(EMSESP_SCANDEVICES_ENDPOINT, (req, res) => { @@ -2398,7 +2399,7 @@ rest_server.post(EMSESP_WRITE_SCHEDULE_ENDPOINT, (req, res) => { rest_server.post(EMSESP_WRITE_ENTITIES_ENDPOINT, (req, res) => { console.log('write entities'); console.log(req.body); - emsesp_entities = req.body; + emsesp_customentities = req.body; res.sendStatus(200); }); @@ -2730,7 +2731,7 @@ rest_server.get(GET_CUSTOMIZATIONS_ENDPOINT, (req, res) => { const GET_ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'getEntities'; rest_server.get(GET_ENTITIES_ENDPOINT, (req, res) => { console.log('getEntities'); - res.json(emsesp_entities); + res.json(emsesp_customentities); }); const GET_SCHEDULE_ENDPOINT = REST_ENDPOINT_ROOT + 'getSchedule'; @@ -2745,10 +2746,10 @@ rest_server.get(SCHEDULE_ENDPOINT, (req, res) => { res.json(emsesp_schedule); }); -const ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'entities'; +const ENTITIES_ENDPOINT = REST_ENDPOINT_ROOT + 'customentities'; rest_server.get(ENTITIES_ENDPOINT, (req, res) => { console.log('Sending Custom Entities data'); - res.json(emsesp_entities); + res.json(emsesp_customentities); }); // start server diff --git a/src/console.cpp b/src/console.cpp index 8d8ad0190..0ec31f3e5 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -360,7 +360,7 @@ static void setup_commands(std::shared_ptr & commands) { commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, - string_vector{F_(scan), F_(devices)}, + string_vector{F_(scan)}, string_vector{F_(deep_optional)}, [](Shell & shell, const std::vector & arguments) { if (arguments.size() == 0) { @@ -368,29 +368,11 @@ static void setup_commands(std::shared_ptr & commands) { } else { shell.printfln("Performing a deep scan..."); to_app(shell).clear_all_devices(); - std::vector Device_Ids; - - Device_Ids.push_back(0x08); // Boilers - 0x08 - Device_Ids.push_back(0x38); // HeatPump - 0x38 - Device_Ids.push_back(0x30); // Solar Module - 0x30 - Device_Ids.push_back(0x09); // Controllers - 0x09 - Device_Ids.push_back(0x02); // Connect - 0x02 - Device_Ids.push_back(0x48); // Gateway - 0x48 - Device_Ids.push_back(0x20); // Mixer Devices - 0x20 - Device_Ids.push_back(0x21); // Mixer Devices - 0x21 - Device_Ids.push_back(0x22); // Mixer Devices - 0x22 - Device_Ids.push_back(0x23); // Mixer Devices - 0x23 - Device_Ids.push_back(0x28); // Mixer Devices WW- 0x28 - Device_Ids.push_back(0x29); // Mixer Devices WW- 0x29 - Device_Ids.push_back(0x10); // Thermostats - 0x10 - Device_Ids.push_back(0x17); // Thermostats - 0x17 - Device_Ids.push_back(0x18); // Thermostat remote - 0x18 - Device_Ids.push_back(0x19); // Thermostat remote - 0x19 - Device_Ids.push_back(0x1A); // Thermostat remote - 0x1A - Device_Ids.push_back(0x1B); // Thermostat remote - 0x1B - Device_Ids.push_back(0x11); // Switches - 0x11 - + // device IDs taken from device_library.h // send the read command with Version command + const std::vector Device_Ids = {0x02, 0x08, 0x09, 0x10, 0x11, 0x12, 0x15, 0x17, 0x18, 0x19, 0x1A, + 0x1B, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x2A, 0x30, 0x38, 0x40, 0x41, 0x48, 0x50, 0x51, 0x60}; for (const uint8_t device_id : Device_Ids) { to_app(shell).send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id); } diff --git a/src/device_library.h b/src/device_library.h index e9556ccea..eeaa03f3f 100644 --- a/src/device_library.h +++ b/src/device_library.h @@ -101,7 +101,7 @@ {215, DeviceType::THERMOSTAT, "Comfort RF", DeviceFlags::EMS_DEVICE_FLAG_CRF | DeviceFlags::EMS_DEVICE_FLAG_NO_WRITE}, // 0x18 {216, DeviceType::THERMOSTAT, "CRF200S", DeviceFlags::EMS_DEVICE_FLAG_CRF | DeviceFlags::EMS_DEVICE_FLAG_NO_WRITE}, // 0x18 {246, DeviceType::THERMOSTAT, "Comfort+2RF", DeviceFlags::EMS_DEVICE_FLAG_CRF | DeviceFlags::EMS_DEVICE_FLAG_NO_WRITE}, // 0x18 -{253, DeviceType::THERMOSTAT, "Rego 3000/UI800/BC400", DeviceFlags::EMS_DEVICE_FLAG_RC300}, // 0x10 +{253, DeviceType::THERMOSTAT, "Rego 3000/UI800/WSW196i/BC400", DeviceFlags::EMS_DEVICE_FLAG_RC300}, // 0x10 // Thermostat - Sieger - 0x10 / 0x17 { 66, DeviceType::THERMOSTAT, "ES72/RC20", DeviceFlags::EMS_DEVICE_FLAG_RC20_N}, // 0x17 or remote diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index bfd3e3b6e..8d975e8b4 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -102,8 +102,18 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const FL_(setReturnTemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_returnTemp)); - register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &cwFlowRate_, DeviceValueType::USHORT, DeviceValueNumOp::DV_NUMOP_DIV10, FL_(cwFlowRate), DeviceValueUOM::LMIN); - register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &netFlowTemp_, DeviceValueType::USHORT, DeviceValueNumOp::DV_NUMOP_DIV10, FL_(netFlowTemp), DeviceValueUOM::DEGREES); + register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, + &cwFlowRate_, + DeviceValueType::USHORT, + DeviceValueNumOp::DV_NUMOP_DIV10, + FL_(cwFlowRate), + DeviceValueUOM::LMIN); + register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, + &netFlowTemp_, + DeviceValueType::USHORT, + DeviceValueNumOp::DV_NUMOP_DIV10, + FL_(netFlowTemp), + DeviceValueUOM::DEGREES); } /* @@ -985,7 +995,7 @@ void Boiler::check_active() { static uint32_t lastSendHeatingOff = 0; if (forceHeatingOff_ == EMS_VALUE_BOOL_ON && (uuid::get_uptime_sec() - lastSendHeatingOff) >= 60) { lastSendHeatingOff = uuid::get_uptime_sec(); - uint8_t data[] = {0, 0, 0, 0}; + uint8_t data[] = {0, 0, 0, 0}; write_command(EMS_TYPE_UBASetPoints, 0, data, sizeof(data), 0); } diff --git a/src/mqtt.cpp b/src/mqtt.cpp index fc4de3619..3248dfb24 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -633,10 +633,12 @@ bool Mqtt::queue_message(const uint8_t operation, const std::string & topic, con packet_id = mqttClient_->unsubscribe(fulltopic); LOG_DEBUG("Unsubscribing to topic '%s', pid %d", fulltopic, packet_id); } +#ifndef EMSESP_STANDALONE if (packet_id == 0) { LOG_WARNING("%s failed: %s", operation == Operation::PUBLISH ? "Publish" : operation == Operation::SUBSCRIBE ? "Subscribe" : "Unsubscribe", fulltopic); mqtt_publish_fails_++; } +#endif return (packet_id != 0); }