This commit is contained in:
MichaelDvP
2022-12-24 12:15:49 +01:00
24 changed files with 235 additions and 167 deletions

View File

@@ -27,6 +27,7 @@
- Support for multiple EMS-ESPs with MQTT and HA [[#759](https://github.com/emsesp/EMS-ESP32/issues/759)] - Support for multiple EMS-ESPs with MQTT and HA [[#759](https://github.com/emsesp/EMS-ESP32/issues/759)]
- Settings for heatpump silent mode and additional heater [[#802](https://github.com/emsesp/EMS-ESP32/issues/802)] [[#803](https://github.com/emsesp/EMS-ESP32/issues/803)] - Settings for heatpump silent mode and additional heater [[#802](https://github.com/emsesp/EMS-ESP32/issues/802)] [[#803](https://github.com/emsesp/EMS-ESP32/issues/803)]
- Zone module MZ100 [#826](https://github.com/emsesp/EMS-ESP32/issues/826) - Zone module MZ100 [#826](https://github.com/emsesp/EMS-ESP32/issues/826)
- Default MQTT hostname is blank [#829](https://github.com/emsesp/EMS-ESP32/issues/829)
## Fixed ## Fixed
@@ -43,4 +44,5 @@
- reload page after restart button is pressed - reload page after restart button is pressed
- analog/dallas values command as list like ems-devices - analog/dallas values command as list like ems-devices
- analog/dallas HA-entities based on id - analog/dallas HA-entities based on id
- MQTT Base is a mandatory field. Removed MQTT topic length from settings. - MQTT Base is a mandatory field. Removed MQTT topic length from settings
- HA duration class for time entities [[#822](https://github.com/emsesp/EMS-ESP32/issues/822

View File

@@ -7,8 +7,8 @@ build_flags =
; Access point settings ; Access point settings
-D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED -D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED
-D FACTORY_AP_SSID=\"ems-esp\" ; 1-64 characters -D FACTORY_AP_SSID=\"ems-esp\"
-D FACTORY_AP_PASSWORD=\"ems-esp-neo\" ; 8-64 characters -D FACTORY_AP_PASSWORD=\"ems-esp-neo\"
-D FACTORY_AP_LOCAL_IP=\"192.168.4.1\" -D FACTORY_AP_LOCAL_IP=\"192.168.4.1\"
-D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\" -D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\"
-D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\" -D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\"
@@ -32,7 +32,7 @@ build_flags =
; MQTT settings ; MQTT settings
-D FACTORY_MQTT_ENABLED=false -D FACTORY_MQTT_ENABLED=false
-D FACTORY_MQTT_HOST=\"test.mosquitto.org\" -D FACTORY_MQTT_HOST=\"\"
-D FACTORY_MQTT_PORT=1883 -D FACTORY_MQTT_PORT=1883
-D FACTORY_MQTT_USERNAME=\"\" -D FACTORY_MQTT_USERNAME=\"\"
-D FACTORY_MQTT_PASSWORD=\"\" -D FACTORY_MQTT_PASSWORD=\"\"

View File

@@ -17,7 +17,7 @@
"@types/lodash": "^4.14.191", "@types/lodash": "^4.14.191",
"@types/node": "^18.11.17", "@types/node": "^18.11.17",
"@types/react": "^18.0.26", "@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9", "@types/react-dom": "^18.0.10",
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"async-validator": "^4.2.5", "async-validator": "^4.2.5",
"axios": "^1.2.1", "axios": "^1.2.1",
@@ -4065,9 +4065,9 @@
} }
}, },
"node_modules/@types/react-dom": { "node_modules/@types/react-dom": {
"version": "18.0.9", "version": "18.0.10",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.9.tgz", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.10.tgz",
"integrity": "sha512-qnVvHxASt/H7i+XG1U1xMiY5t+IHcPGUK7TDMDzom08xa7e86eCeKOiLZezwCKVxJn6NEiiy2ekgX8aQssjIKg==", "integrity": "sha512-E42GW/JA4Qv15wQdqJq8DL4JhNpB3prJgjgapN3qJT9K2zO5IIAQh4VXvCEDupoqAwnz0cY4RlXeC/ajX5SFHg==",
"dependencies": { "dependencies": {
"@types/react": "*" "@types/react": "*"
} }
@@ -20423,9 +20423,9 @@
} }
}, },
"@types/react-dom": { "@types/react-dom": {
"version": "18.0.9", "version": "18.0.10",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.9.tgz", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.10.tgz",
"integrity": "sha512-qnVvHxASt/H7i+XG1U1xMiY5t+IHcPGUK7TDMDzom08xa7e86eCeKOiLZezwCKVxJn6NEiiy2ekgX8aQssjIKg==", "integrity": "sha512-E42GW/JA4Qv15wQdqJq8DL4JhNpB3prJgjgapN3qJT9K2zO5IIAQh4VXvCEDupoqAwnz0cY4RlXeC/ajX5SFHg==",
"requires": { "requires": {
"@types/react": "*" "@types/react": "*"
} }

View File

@@ -13,7 +13,7 @@
"@types/lodash": "^4.14.191", "@types/lodash": "^4.14.191",
"@types/node": "^18.11.17", "@types/node": "^18.11.17",
"@types/react": "^18.0.26", "@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9", "@types/react-dom": "^18.0.10",
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"async-validator": "^4.2.5", "async-validator": "^4.2.5",
"axios": "^1.2.1", "axios": "^1.2.1",

View File

@@ -4,7 +4,7 @@ import { ValidateFieldsError } from 'async-validator';
import { Button, Checkbox, MenuItem, Grid, Typography, InputAdornment } from '@mui/material'; import { Button, Checkbox, MenuItem, Grid, Typography, InputAdornment } from '@mui/material';
import SaveIcon from '@mui/icons-material/Save'; import SaveIcon from '@mui/icons-material/Save';
import { MQTT_SETTINGS_VALIDATOR, validate } from '../../validators'; import { createMqttSettingsValidator, validate } from '../../validators';
import { import {
BlockFormControlLabel, BlockFormControlLabel,
ButtonRow, ButtonRow,
@@ -39,7 +39,7 @@ const MqttSettingsForm: FC = () => {
const validateAndSubmit = async () => { const validateAndSubmit = async () => {
try { try {
setFieldErrors(undefined); setFieldErrors(undefined);
await validate(MQTT_SETTINGS_VALIDATOR, data); await validate(createMqttSettingsValidator(data), data);
saveData(); saveData();
} catch (errors: any) { } catch (errors: any) {
setFieldErrors(errors); setFieldErrors(errors);

View File

@@ -70,7 +70,7 @@ const de: Translation = {
TEMP_SENSOR: 'Temperatursensor', TEMP_SENSOR: 'Temperatursensor',
TEMP_SENSORS: 'Temperatursensoren', TEMP_SENSORS: 'Temperatursensoren',
WRITE_CMD_SENT: 'Befehl schreiben wurde gesendet', WRITE_CMD_SENT: 'Befehl schreiben wurde gesendet',
WRITE_CMD_FAILED: 'Befehl schreiben failed', WRITE_CMD_FAILED: 'Befehl schreiben failed', // TODO
EMS_BUS_WARNING: 'EMS-Bus getrennt. Wenn diese Warnung nach einigen Sekunden immer noch besteht, überprüfen Sie bitte die Einstellungen und das Board-Profil', EMS_BUS_WARNING: 'EMS-Bus getrennt. Wenn diese Warnung nach einigen Sekunden immer noch besteht, überprüfen Sie bitte die Einstellungen und das Board-Profil',
EMS_BUS_SCANNING: 'Suche nach EMS Geräten...', EMS_BUS_SCANNING: 'Suche nach EMS Geräten...',
CONNECTED: 'Verbunden', CONNECTED: 'Verbunden',

View File

@@ -69,8 +69,8 @@ const fr: Translation = {
SENSOR: 'Capteur', SENSOR: 'Capteur',
TEMP_SENSOR: 'Capteur de température', TEMP_SENSOR: 'Capteur de température',
TEMP_SENSORS: 'Capteurs de température', TEMP_SENSORS: 'Capteurs de température',
WRITE_CMD_SENT: 'Envoyer la commande sent', WRITE_CMD_SENT: 'Envoyer la commande sent', // TODO
WRITE_CMD_FAILED: 'Envoyer la commande failed', WRITE_CMD_FAILED: 'Envoyer la commande failed', // TODO
EMS_BUS_WARNING: 'Bus EMS déconnecté. Si ce message persiste après quelques secondes, vérifiez les paramètres et la configuration de la carte.', EMS_BUS_WARNING: 'Bus EMS déconnecté. Si ce message persiste après quelques secondes, vérifiez les paramètres et la configuration de la carte.',
EMS_BUS_SCANNING: 'Scan des appareils EMS...', EMS_BUS_SCANNING: 'Scan des appareils EMS...',
CONNECTED: 'Connecté', CONNECTED: 'Connecté',
@@ -249,10 +249,10 @@ const fr: Translation = {
MQTT_INT_HEARTBEAT: 'Battements', MQTT_INT_HEARTBEAT: 'Battements',
MQTT_QUEUE: 'Queue MQTT', MQTT_QUEUE: 'Queue MQTT',
DEFAULT: 'Défaut', DEFAULT: 'Défaut',
MQTT_ENTITY_FORMAT: 'Entity ID format', MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',// TODO
MQTT_ENTITY_FORMAT_1: 'Single instance, short name', MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO
MQTT_CLEAN_SESSION: 'Flag Clean Session', MQTT_CLEAN_SESSION: 'Flag Clean Session',
MQTT_RETAIN_FLAG: 'Toujours activer le Retain Flag', MQTT_RETAIN_FLAG: 'Toujours activer le Retain Flag',
INACTIVE: 'Inactif', INACTIVE: 'Inactif',

View File

@@ -69,8 +69,8 @@ const nl: Translation = {
SENSOR: 'Sensor', SENSOR: 'Sensor',
TEMP_SENSOR: 'Temperatuur sensor', TEMP_SENSOR: 'Temperatuur sensor',
TEMP_SENSORS: 'Temperatuur Sensoren', TEMP_SENSORS: 'Temperatuur Sensoren',
WRITE_CMD_SENT: 'Schrijf commando sent', WRITE_CMD_SENT: 'Schrijf commando sent', // TODO
WRITE_CMD_FAILED: 'Schrijf commando failed', WRITE_CMD_FAILED: 'Schrijf commando failed', // TODO
EMS_BUS_WARNING: 'EMS bus niet gevonden. Als deze waarschuwing blijft staan na een paar seconden dan loop de instellingen na en in het bijzonder het apparaat type profiel na.', EMS_BUS_WARNING: 'EMS bus niet gevonden. Als deze waarschuwing blijft staan na een paar seconden dan loop de instellingen na en in het bijzonder het apparaat type profiel na.',
EMS_BUS_SCANNING: 'Scannen naar EMS apparaten...', EMS_BUS_SCANNING: 'Scannen naar EMS apparaten...',
CONNECTED: 'Verbonden', CONNECTED: 'Verbonden',
@@ -249,10 +249,10 @@ const nl: Translation = {
MQTT_INT_HEARTBEAT: 'Heartbeat', MQTT_INT_HEARTBEAT: 'Heartbeat',
MQTT_QUEUE: 'MQTT Queue', MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Default', DEFAULT: 'Default',
MQTT_ENTITY_FORMAT: 'Entity ID format', MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', // TODO
MQTT_ENTITY_FORMAT_1: 'Single instance, short name', MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO
MQTT_CLEAN_SESSION: 'Clean Session aan', MQTT_CLEAN_SESSION: 'Clean Session aan',
MQTT_RETAIN_FLAG: 'Retain flag aan', MQTT_RETAIN_FLAG: 'Retain flag aan',
INACTIVE: 'Inactief', INACTIVE: 'Inactief',

View File

@@ -69,8 +69,8 @@ const no: Translation = {
SENSOR: 'Sensor', SENSOR: 'Sensor',
TEMP_SENSOR: 'Temperatursensor', TEMP_SENSOR: 'Temperatursensor',
TEMP_SENSORS: 'Temperaturesensorer', TEMP_SENSORS: 'Temperaturesensorer',
WRITE_CMD_SENT: 'Skriv kommando sent', WRITE_CMD_SENT: 'Skriv kommando sent', // TODO
WRITE_CMD_FAILED: 'Skriv kommandofailed', WRITE_CMD_FAILED: 'Skriv kommando failed', // TODO
EMS_BUS_WARNING: 'EMS bussen koblet ned. Hvis denne advarselen fortsetter etter noen f¨sekunder sjekk instillinger og prosessorkort', EMS_BUS_WARNING: 'EMS bussen koblet ned. Hvis denne advarselen fortsetter etter noen f¨sekunder sjekk instillinger og prosessorkort',
EMS_BUS_SCANNING: 'Søker etter EMS enheter...', EMS_BUS_SCANNING: 'Søker etter EMS enheter...',
CONNECTED: 'Tilkoblet', CONNECTED: 'Tilkoblet',
@@ -249,10 +249,10 @@ const no: Translation = {
MQTT_INT_HEARTBEAT: 'Heartbeat', MQTT_INT_HEARTBEAT: 'Heartbeat',
MQTT_QUEUE: 'MQTT Queue', MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Standard', DEFAULT: 'Standard',
MQTT_ENTITY_FORMAT: 'Entity ID format', MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', // TODO
MQTT_ENTITY_FORMAT_1: 'Single instance, short name', MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO
MQTT_CLEAN_SESSION: 'Benytt Clean Session', MQTT_CLEAN_SESSION: 'Benytt Clean Session',
MQTT_RETAIN_FLAG: 'Alltid sett Retain flag', MQTT_RETAIN_FLAG: 'Alltid sett Retain flag',
INACTIVE: 'Innaktiv', INACTIVE: 'Innaktiv',

View File

@@ -69,8 +69,8 @@ const se: Translation = {
SENSOR: 'Sensor', SENSOR: 'Sensor',
TEMP_SENSOR: 'Temperatursensor', TEMP_SENSOR: 'Temperatursensor',
TEMP_SENSORS: 'Temperatursensorer', TEMP_SENSORS: 'Temperatursensorer',
WRITE_CMD_SENT: 'Skrivkommando sent', WRITE_CMD_SENT: 'Skrivkommando sent', // TODO
WRITE_CMD_FAILED: 'Skrivkommando failed', WRITE_CMD_FAILED: 'Skrivkommando failed', // TODO
EMS_BUS_WARNING: 'EMS-buss nedkopplad. Om denna varning kvarstår efter några sekunder, kontrollera inställningar och enhets-profil.', EMS_BUS_WARNING: 'EMS-buss nedkopplad. Om denna varning kvarstår efter några sekunder, kontrollera inställningar och enhets-profil.',
EMS_BUS_SCANNING: 'Söker efter EMS-enheter...', EMS_BUS_SCANNING: 'Söker efter EMS-enheter...',
CONNECTED: 'Ansluten', CONNECTED: 'Ansluten',
@@ -249,10 +249,10 @@ const se: Translation = {
MQTT_INT_HEARTBEAT: 'Heartbeat', MQTT_INT_HEARTBEAT: 'Heartbeat',
MQTT_QUEUE: 'MQTT Queue', MQTT_QUEUE: 'MQTT Queue',
DEFAULT: 'Standard', DEFAULT: 'Standard',
MQTT_ENTITY_FORMAT: 'Entity ID format', MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO
MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', // TODO
MQTT_ENTITY_FORMAT_1: 'Single instance, short name', MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO
MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO
MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan', MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan',
MQTT_RETAIN_FLAG: 'Använd "Always Retain"-flaggan', MQTT_RETAIN_FLAG: 'Använd "Always Retain"-flaggan',
INACTIVE: 'Inaktiv', INACTIVE: 'Inaktiv',

View File

@@ -1,7 +1,10 @@
import Schema from 'async-validator'; import Schema from 'async-validator';
import { MqttSettings } from '../types';
import { IP_OR_HOSTNAME_VALIDATOR } from './shared'; import { IP_OR_HOSTNAME_VALIDATOR } from './shared';
export const MQTT_SETTINGS_VALIDATOR = new Schema({ export const createMqttSettingsValidator = (mqttSettings: MqttSettings) =>
new Schema({
...(mqttSettings.enabled && {
host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR], host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR],
base: { required: true, message: 'Base is required' }, base: { required: true, message: 'Base is required' },
port: [ port: [
@@ -16,4 +19,5 @@ export const MQTT_SETTINGS_VALIDATOR = new Schema({
{ required: true, message: 'Heartbeat is required' }, { required: true, message: 'Heartbeat is required' },
{ type: 'number', min: 10, max: 86400, message: 'Heartbeat must be between 10 and 86400' } { type: 'number', min: 10, max: 86400, message: 'Heartbeat must be between 10 and 86400' }
] ]
})
}); });

View File

@@ -125,8 +125,8 @@ void MqttSettingsService::configureMqtt() {
// disconnect if connected // disconnect if connected
_mqttClient.disconnect(); _mqttClient.disconnect();
// only connect if WiFi is connected and MQTT is enabled // only connect if WiFi is connected and MQTT is enabled
if (_state.enabled && emsesp::EMSESP::system_.network_connected()) { if (_state.enabled && emsesp::EMSESP::system_.network_connected() && !_state.host.isEmpty()) {
// emsesp::EMSESP::logger().info("Configuring Mqtt client"); // emsesp::EMSESP::logger().info("Configuring MQTT client");
_mqttClient.setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port); _mqttClient.setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port);
if (_state.username.length() > 0) { if (_state.username.length() > 0) {
_mqttClient.setCredentials(retainCstr(_state.username.c_str(), &_retainedUsername), _mqttClient.setCredentials(retainCstr(_state.username.c_str(), &_retainedUsername),
@@ -140,7 +140,7 @@ void MqttSettingsService::configureMqtt() {
_mqttClient.setMaxTopicLength(FACTORY_MQTT_MAX_TOPIC_LENGTH); // hardcode. We don't take this from the settings anymore. _mqttClient.setMaxTopicLength(FACTORY_MQTT_MAX_TOPIC_LENGTH); // hardcode. We don't take this from the settings anymore.
_mqttClient.connect(); _mqttClient.connect();
// } else { // } else {
// emsesp::EMSESP::logger().info("Error configuring Mqtt client"); // emsesp::EMSESP::logger().info("Error configuring MQTT client");
} }
} }

View File

@@ -19,7 +19,7 @@
#endif #endif
#ifndef FACTORY_MQTT_HOST #ifndef FACTORY_MQTT_HOST
#define FACTORY_MQTT_HOST "test.mosquitto.org" #define FACTORY_MQTT_HOST "" // is blank
#endif #endif
#ifndef FACTORY_MQTT_PORT #ifndef FACTORY_MQTT_PORT

View File

@@ -26,6 +26,7 @@
class DummySettings { class DummySettings {
public: public:
std::string version{"poerp"};
String locale = "en"; String locale = "en";
uint8_t tx_mode = 1; uint8_t tx_mode = 1;
uint8_t ems_bus_id = 0x0B; uint8_t ems_bus_id = 0x0B;

View File

@@ -24,6 +24,7 @@ class FSPersistence {
} }
void readFromFS() { void readFromFS() {
Serial.println();
Serial.print("Fake reading file "); Serial.print("Fake reading file ");
Serial.println(_filePath); Serial.println(_filePath);
applyDefaults(); applyDefaults();

View File

@@ -48,28 +48,28 @@ class DeviceValue {
// also used with HA as uom // also used with HA as uom
enum DeviceValueUOM : uint8_t { enum DeviceValueUOM : uint8_t {
NONE = 0, // 0 NONE = 0, // 0
DEGREES, // 1 DEGREES, // 1 - °C
DEGREES_R, // 2 - relative temperature DEGREES_R, // 2 - °C (relative temperature)
PERCENT, // 3 PERCENT, // 3 - %
LMIN, // 4 - l/min LMIN, // 4 - l/min
KWH, // 5 - kWh KWH, // 5 - kWh
WH, // 6 - Wh WH, // 6 - Wh
HOURS, // 7 HOURS, // 7 - h
MINUTES, // 8 MINUTES, // 8 - m
UA, // 9 - µA UA, // 9 - µA
BAR, // 10 BAR, // 10 - bar
KW, // 11 - kW KW, // 11 - kW
W, // 12 W, // 12 - W
KB, // 13 KB, // 13 - kB
SECONDS, // 14 SECONDS, // 14 - s
DBM, // 15 - dBm DBM, // 15 - dBm
FAHRENHEIT, // 16 FAHRENHEIT, // 16 - °F
MV, // 17 - mV MV, // 17 - mV
SQM, // 18 - square meter SQM, // 18 -
M3, // 19 - cubic meter M3, // 19 -
L, // 20 - liter L, // 20 - L
KMIN, // 21 - Kelvin * minutes KMIN, // 21 - K*min
K, // 22 - Kelvin K, // 22 - K
CONNECTIVITY // 23 - used in HA CONNECTIVITY // 23 - used in HA
}; };

View File

@@ -1302,13 +1302,20 @@ void EMSESP::start() {
LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str()); LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
// do any system upgrades // see if we're restoring a settings file
if (system_.check_upgrade()) { if (system_.check_restore()) {
LOG_INFO("System needs a restart to apply new settings. Please wait."); LOG_WARNING("System needs a restart to apply new settings. Please wait.");
system_.system_restart(); system_.system_restart();
}; };
webSettingsService.begin(); // load EMS-ESP Application settings... webSettingsService.begin(); // load EMS-ESP Application settings...
// do any system upgrades
if (system_.check_upgrade()) {
LOG_WARNING("System needs a restart to apply new settings. Please wait.");
system_.system_restart();
};
system_.reload_settings(); // ... and store some of the settings locally system_.reload_settings(); // ... and store some of the settings locally
webCustomizationService.begin(); // load the customizations webCustomizationService.begin(); // load the customizations

View File

@@ -197,7 +197,7 @@ MAKE_PSTR_LIST(tpl_input, "Format: <inv>[<evu1><evu2><evu3><comp><aux><cool><hea
MAKE_PSTR_LIST(tpl_input4, "Format: <inv>[<comp><aux><cool><heat><dhw><pv>]") MAKE_PSTR_LIST(tpl_input4, "Format: <inv>[<comp><aux><cool><heat><dhw><pv>]")
// Unit Of Measurement mapping - maps to DeviceValueUOM_s in emsdevice.cpp // Unit Of Measurement mapping - maps to DeviceValueUOM_s in emsdevice.cpp
// Translating hours/minute/seconds in emsdevice.cpp // Translating hours/minute/seconds are done in emsdevice.cpp (uom_to_string())
MAKE_PSTR(uom_blank, " ") MAKE_PSTR(uom_blank, " ")
MAKE_PSTR(uom_percent, "%") MAKE_PSTR(uom_percent, "%")
MAKE_PSTR(uom_degrees, "°C") MAKE_PSTR(uom_degrees, "°C")

View File

@@ -66,16 +66,10 @@ MAKE_PSTR_WORD(measurement)
MAKE_PSTR_WORD(total_increasing) MAKE_PSTR_WORD(total_increasing)
MAKE_PSTR(icondegrees, "mdi:coolant-temperature") // DeviceValueUOM::DEGREES MAKE_PSTR(icondegrees, "mdi:coolant-temperature") // DeviceValueUOM::DEGREES
MAKE_PSTR(iconpercent, "mdi:percent-outline") // DeviceValueUOM::PERCENT MAKE_PSTR(iconpercent, "mdi:percent-outline") // DeviceValueUOM::PERCENT
MAKE_PSTR(icontime, "mdi:clock-outline") // DeviceValueUOM::SECONDS MINUTES & HOURS
MAKE_PSTR(iconkb, "mdi:memory") // DeviceValueUOM::KB MAKE_PSTR(iconkb, "mdi:memory") // DeviceValueUOM::KB
MAKE_PSTR(iconlmin, "mdi:water-boiler") // DeviceValueUOM::LMIN MAKE_PSTR(iconlmin, "mdi:water-boiler") // DeviceValueUOM::LMIN
// MAKE_PSTR(iconkwh, "mdi:transmission-tower") // DeviceValueUOM::KWH & WH
MAKE_PSTR(iconua, "mdi:lightning-bolt-circle") // DeviceValueUOM::UA MAKE_PSTR(iconua, "mdi:lightning-bolt-circle") // DeviceValueUOM::UA
// MAKE_PSTR(iconbar, "mdi:gauge") // DeviceValueUOM::BAR
// MAKE_PSTR(iconkw, "mdi:omega") // DeviceValueUOM::KW & W
// MAKE_PSTR(icondbm, "mdi:wifi-strength-2") // DeviceValueUOM::DBM
MAKE_PSTR(iconnum, "mdi:counter") // DeviceValueUOM::NONE MAKE_PSTR(iconnum, "mdi:counter") // DeviceValueUOM::NONE
// MAKE_PSTR(icondevice, "mdi:home-automation") // for devices in HA
uuid::log::Logger Mqtt::logger_{F_(mqtt), uuid::log::Facility::DAEMON}; uuid::log::Logger Mqtt::logger_{F_(mqtt), uuid::log::Facility::DAEMON};
@@ -1171,8 +1165,16 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
doc["payload_off"] = Helpers::render_boolean(result, false); doc["payload_off"] = Helpers::render_boolean(result, false);
doc[sc_ha] = F_(measurement); doc[sc_ha] = F_(measurement);
} else { } else {
// always set the uom // always set the uom, using the standards except for hours/minutes/seconds
if (uom != DeviceValueUOM::NONE) { // using HA specific codes from https://github.com/home-assistant/core/blob/dev/homeassistant/const.py
if (uom == DeviceValueUOM::HOURS) {
doc[uom_ha] = "h";
} else if (uom == DeviceValueUOM::MINUTES) {
doc[uom_ha] = "min";
} else if (uom == DeviceValueUOM::SECONDS) {
doc[uom_ha] = "s";
} else if (uom != DeviceValueUOM::NONE) {
// default
doc[uom_ha] = EMSdevice::uom_to_string(uom); doc[uom_ha] = EMSdevice::uom_to_string(uom);
} }
} }
@@ -1196,12 +1198,12 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
case DeviceValueUOM::SECONDS: case DeviceValueUOM::SECONDS:
case DeviceValueUOM::MINUTES: case DeviceValueUOM::MINUTES:
case DeviceValueUOM::HOURS: case DeviceValueUOM::HOURS:
doc[ic_ha] = F_(icontime);
if (type == DeviceValueType::TIME) { if (type == DeviceValueType::TIME) {
doc[sc_ha] = F_(total_increasing); doc[sc_ha] = F_(total_increasing);
} else { } else {
doc[sc_ha] = F_(measurement); doc[sc_ha] = F_(measurement);
} }
doc[dc_ha] = "duration"; // https://github.com/emsesp/EMS-ESP32/issues/822
break; break;
case DeviceValueUOM::KB: case DeviceValueUOM::KB:
doc[ic_ha] = F_(iconkb); doc[ic_ha] = F_(iconkb);

View File

@@ -290,6 +290,8 @@ void System::syslog_init() {
// read some specific system settings to store locally for faster access // read some specific system settings to store locally for faster access
void System::reload_settings() { void System::reload_settings() {
EMSESP::webSettingsService.read([&](WebSettings & settings) { EMSESP::webSettingsService.read([&](WebSettings & settings) {
version_ = settings.version;
pbutton_gpio_ = settings.pbutton_gpio; pbutton_gpio_ = settings.pbutton_gpio;
analog_enabled_ = settings.analog_enabled; analog_enabled_ = settings.analog_enabled;
low_clock_ = settings.low_clock; low_clock_ = settings.low_clock;
@@ -969,10 +971,8 @@ void System::show_system(uuid::console::Shell & shell) {
#endif #endif
} }
// handle upgrades from previous versions // see if there is a restore of an older settings file that needs to be applied
// or managing an uploaded files to replace settings files bool System::check_restore() {
// returns true if we need a reboot
bool System::check_upgrade() {
bool reboot_required = false; bool reboot_required = false;
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
@@ -1012,6 +1012,50 @@ bool System::check_upgrade() {
return reboot_required; return reboot_required;
} }
// handle upgrades from previous versions
// returns true if we need a reboot
bool System::check_upgrade() {
std::string old_version;
// TODO fix
if (version_ != EMSESP_APP_VERSION) {
if (version_.empty()) {
LOG_DEBUG("No version, presuming fresh install. Setting to %s", EMSESP_APP_VERSION);
old_version = EMSESP_APP_VERSION;
} else {
LOG_DEBUG("Going from version %s to %s", version_, EMSESP_APP_VERSION);
old_version = version_;
}
// save the new version
version_ = EMSESP_APP_VERSION;
EMSESP::webSettingsService.update(
[&](WebSettings & settings) {
settings.version = EMSESP_APP_VERSION;
return StateUpdateResult::CHANGED;
},
"local");
}
if (old_version == EMSESP_APP_VERSION) {
return false; // no upgrades or reboot needed. we're on the latest
}
LOG_DEBUG("Doing upgrade..."); // TODO remove
// check variations between versions
// get major version
// get minor version
// get patch version (ignore alphanumerics)
bool reboot_required = false;
return reboot_required;
}
// list commands // list commands
bool System::command_commands(const char * value, const int8_t id, JsonObject & output) { bool System::command_commands(const char * value, const int8_t id, JsonObject & output) {
return Command::list(EMSdevice::DeviceType::SYSTEM, output); return Command::list(EMSdevice::DeviceType::SYSTEM, output);

View File

@@ -75,6 +75,7 @@ class System {
void wifi_tweak(); void wifi_tweak();
void syslog_init(); void syslog_init();
bool check_upgrade(); bool check_upgrade();
bool check_restore();
bool heartbeat_json(JsonObject & output); bool heartbeat_json(JsonObject & output);
void send_heartbeat(); void send_heartbeat();
void send_info_mqtt(const char * event_str, bool send_ntp = false); void send_info_mqtt(const char * event_str, bool send_ntp = false);
@@ -294,6 +295,7 @@ class System {
uint8_t bool_format_; uint8_t bool_format_;
uint8_t enum_format_; uint8_t enum_format_;
bool readonly_mode_; bool readonly_mode_;
std::string version_;
// ethernet // ethernet
uint8_t phy_type_; uint8_t phy_type_;

View File

@@ -80,6 +80,10 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
// call on initialization and also when settings are updated via web or console // call on initialization and also when settings are updated via web or console
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) { StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
// load the version of the settings
// will be picked up in System::check_upgrade()
settings.version = root["version"] || "";
// load default GPIO configuration based on board profile // load default GPIO configuration based on board profile
std::vector<int8_t> data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode std::vector<int8_t> data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
#if CONFIG_IDF_TARGET_ESP32C3 #if CONFIG_IDF_TARGET_ESP32C3

View File

@@ -29,6 +29,7 @@ namespace emsesp {
class WebSettings { class WebSettings {
public: public:
std::string version;
String locale; String locale;
uint8_t tx_mode; uint8_t tx_mode;
uint8_t ems_bus_id; uint8_t ems_bus_id;