diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 15791d283..209036bd4 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -27,6 +27,7 @@ - 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)] - 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 @@ -43,4 +44,5 @@ - reload page after restart button is pressed - analog/dallas values command as list like ems-devices - 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 diff --git a/factory_settings.ini b/factory_settings.ini index 12a99b948..106c29c62 100644 --- a/factory_settings.ini +++ b/factory_settings.ini @@ -7,8 +7,8 @@ build_flags = ; Access point settings -D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED - -D FACTORY_AP_SSID=\"ems-esp\" ; 1-64 characters - -D FACTORY_AP_PASSWORD=\"ems-esp-neo\" ; 8-64 characters + -D FACTORY_AP_SSID=\"ems-esp\" + -D FACTORY_AP_PASSWORD=\"ems-esp-neo\" -D FACTORY_AP_LOCAL_IP=\"192.168.4.1\" -D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\" -D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\" @@ -32,7 +32,7 @@ build_flags = ; MQTT settings -D FACTORY_MQTT_ENABLED=false - -D FACTORY_MQTT_HOST=\"test.mosquitto.org\" + -D FACTORY_MQTT_HOST=\"\" -D FACTORY_MQTT_PORT=1883 -D FACTORY_MQTT_USERNAME=\"\" -D FACTORY_MQTT_PASSWORD=\"\" diff --git a/interface/.typesafe-i18n.json b/interface/.typesafe-i18n.json index 13488b4d8..ae5842beb 100644 --- a/interface/.typesafe-i18n.json +++ b/interface/.typesafe-i18n.json @@ -1,5 +1,5 @@ { - "adapter": "react", - "baseLocale": "pl", - "$schema": "https://unpkg.com/typesafe-i18n@5.18.0/schema/typesafe-i18n.json" + "adapter": "react", + "baseLocale": "pl", + "$schema": "https://unpkg.com/typesafe-i18n@5.18.0/schema/typesafe-i18n.json" } diff --git a/interface/package-lock.json b/interface/package-lock.json index c2088200a..4eda56a78 100644 --- a/interface/package-lock.json +++ b/interface/package-lock.json @@ -17,7 +17,7 @@ "@types/lodash": "^4.14.191", "@types/node": "^18.11.17", "@types/react": "^18.0.26", - "@types/react-dom": "^18.0.9", + "@types/react-dom": "^18.0.10", "@types/react-router-dom": "^5.3.3", "async-validator": "^4.2.5", "axios": "^1.2.1", @@ -4065,9 +4065,9 @@ } }, "node_modules/@types/react-dom": { - "version": "18.0.9", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.9.tgz", - "integrity": "sha512-qnVvHxASt/H7i+XG1U1xMiY5t+IHcPGUK7TDMDzom08xa7e86eCeKOiLZezwCKVxJn6NEiiy2ekgX8aQssjIKg==", + "version": "18.0.10", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.10.tgz", + "integrity": "sha512-E42GW/JA4Qv15wQdqJq8DL4JhNpB3prJgjgapN3qJT9K2zO5IIAQh4VXvCEDupoqAwnz0cY4RlXeC/ajX5SFHg==", "dependencies": { "@types/react": "*" } @@ -20423,9 +20423,9 @@ } }, "@types/react-dom": { - "version": "18.0.9", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.9.tgz", - "integrity": "sha512-qnVvHxASt/H7i+XG1U1xMiY5t+IHcPGUK7TDMDzom08xa7e86eCeKOiLZezwCKVxJn6NEiiy2ekgX8aQssjIKg==", + "version": "18.0.10", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.10.tgz", + "integrity": "sha512-E42GW/JA4Qv15wQdqJq8DL4JhNpB3prJgjgapN3qJT9K2zO5IIAQh4VXvCEDupoqAwnz0cY4RlXeC/ajX5SFHg==", "requires": { "@types/react": "*" } diff --git a/interface/package.json b/interface/package.json index 89ff72c15..03b79d463 100644 --- a/interface/package.json +++ b/interface/package.json @@ -13,7 +13,7 @@ "@types/lodash": "^4.14.191", "@types/node": "^18.11.17", "@types/react": "^18.0.26", - "@types/react-dom": "^18.0.9", + "@types/react-dom": "^18.0.10", "@types/react-router-dom": "^5.3.3", "async-validator": "^4.2.5", "axios": "^1.2.1", diff --git a/interface/src/framework/mqtt/MqttSettingsForm.tsx b/interface/src/framework/mqtt/MqttSettingsForm.tsx index ebe7151f8..7c79251a7 100644 --- a/interface/src/framework/mqtt/MqttSettingsForm.tsx +++ b/interface/src/framework/mqtt/MqttSettingsForm.tsx @@ -4,7 +4,7 @@ import { ValidateFieldsError } from 'async-validator'; import { Button, Checkbox, MenuItem, Grid, Typography, InputAdornment } from '@mui/material'; import SaveIcon from '@mui/icons-material/Save'; -import { MQTT_SETTINGS_VALIDATOR, validate } from '../../validators'; +import { createMqttSettingsValidator, validate } from '../../validators'; import { BlockFormControlLabel, ButtonRow, @@ -39,7 +39,7 @@ const MqttSettingsForm: FC = () => { const validateAndSubmit = async () => { try { setFieldErrors(undefined); - await validate(MQTT_SETTINGS_VALIDATOR, data); + await validate(createMqttSettingsValidator(data), data); saveData(); } catch (errors: any) { setFieldErrors(errors); diff --git a/interface/src/i18n/de/index.ts b/interface/src/i18n/de/index.ts index babf748e9..cb08d4d01 100644 --- a/interface/src/i18n/de/index.ts +++ b/interface/src/i18n/de/index.ts @@ -70,7 +70,7 @@ const de: Translation = { TEMP_SENSOR: 'Temperatursensor', TEMP_SENSORS: 'Temperatursensoren', 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_SCANNING: 'Suche nach EMS Geräten...', CONNECTED: 'Verbunden', diff --git a/interface/src/i18n/fr/index.ts b/interface/src/i18n/fr/index.ts index 0ab81a625..5f83b2c01 100644 --- a/interface/src/i18n/fr/index.ts +++ b/interface/src/i18n/fr/index.ts @@ -69,8 +69,8 @@ const fr: Translation = { SENSOR: 'Capteur', TEMP_SENSOR: 'Capteur de température', TEMP_SENSORS: 'Capteurs de température', - WRITE_CMD_SENT: 'Envoyer la commande sent', - WRITE_CMD_FAILED: 'Envoyer la commande failed', + WRITE_CMD_SENT: 'Envoyer la commande sent', // TODO + 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_SCANNING: 'Scan des appareils EMS...', CONNECTED: 'Connecté', @@ -249,10 +249,10 @@ const fr: Translation = { MQTT_INT_HEARTBEAT: 'Battements', MQTT_QUEUE: 'Queue MQTT', DEFAULT: 'Défaut', - MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', - MQTT_ENTITY_FORMAT_1: 'Single instance, short name', - MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', + MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)',// TODO + MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO + MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO MQTT_CLEAN_SESSION: 'Flag Clean Session', MQTT_RETAIN_FLAG: 'Toujours activer le Retain Flag', INACTIVE: 'Inactif', diff --git a/interface/src/i18n/nl/index.ts b/interface/src/i18n/nl/index.ts index d3c992a11..0ce16719c 100644 --- a/interface/src/i18n/nl/index.ts +++ b/interface/src/i18n/nl/index.ts @@ -69,8 +69,8 @@ const nl: Translation = { SENSOR: 'Sensor', TEMP_SENSOR: 'Temperatuur sensor', TEMP_SENSORS: 'Temperatuur Sensoren', - WRITE_CMD_SENT: 'Schrijf commando sent', - WRITE_CMD_FAILED: 'Schrijf commando failed', + WRITE_CMD_SENT: 'Schrijf commando sent', // TODO + 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_SCANNING: 'Scannen naar EMS apparaten...', CONNECTED: 'Verbonden', @@ -249,10 +249,10 @@ const nl: Translation = { MQTT_INT_HEARTBEAT: 'Heartbeat', MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Default', - MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', - MQTT_ENTITY_FORMAT_1: 'Single instance, short name', - MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', + MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', // TODO + MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO + MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO MQTT_CLEAN_SESSION: 'Clean Session aan', MQTT_RETAIN_FLAG: 'Retain flag aan', INACTIVE: 'Inactief', diff --git a/interface/src/i18n/no/index.ts b/interface/src/i18n/no/index.ts index 4151a3128..2f5aedee6 100644 --- a/interface/src/i18n/no/index.ts +++ b/interface/src/i18n/no/index.ts @@ -69,8 +69,8 @@ const no: Translation = { SENSOR: 'Sensor', TEMP_SENSOR: 'Temperatursensor', TEMP_SENSORS: 'Temperaturesensorer', - WRITE_CMD_SENT: 'Skriv kommando sent', - WRITE_CMD_FAILED: 'Skriv kommandofailed', + WRITE_CMD_SENT: 'Skriv kommando sent', // TODO + 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_SCANNING: 'Søker etter EMS enheter...', CONNECTED: 'Tilkoblet', @@ -249,10 +249,10 @@ const no: Translation = { MQTT_INT_HEARTBEAT: 'Heartbeat', MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Standard', - MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', - MQTT_ENTITY_FORMAT_1: 'Single instance, short name', - MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', + MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', // TODO + MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO + MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO MQTT_CLEAN_SESSION: 'Benytt Clean Session', MQTT_RETAIN_FLAG: 'Alltid sett Retain flag', INACTIVE: 'Innaktiv', diff --git a/interface/src/i18n/se/index.ts b/interface/src/i18n/se/index.ts index a175273be..800c9ace9 100644 --- a/interface/src/i18n/se/index.ts +++ b/interface/src/i18n/se/index.ts @@ -69,8 +69,8 @@ const se: Translation = { SENSOR: 'Sensor', TEMP_SENSOR: 'Temperatursensor', TEMP_SENSORS: 'Temperatursensorer', - WRITE_CMD_SENT: 'Skrivkommando sent', - WRITE_CMD_FAILED: 'Skrivkommando failed', + WRITE_CMD_SENT: 'Skrivkommando sent', // TODO + 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_SCANNING: 'Söker efter EMS-enheter...', CONNECTED: 'Ansluten', @@ -249,10 +249,10 @@ const se: Translation = { MQTT_INT_HEARTBEAT: 'Heartbeat', MQTT_QUEUE: 'MQTT Queue', DEFAULT: 'Standard', - MQTT_ENTITY_FORMAT: 'Entity ID format', - MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', - MQTT_ENTITY_FORMAT_1: 'Single instance, short name', - MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', + MQTT_ENTITY_FORMAT: 'Entity ID format', // TODO + MQTT_ENTITY_FORMAT_0: 'Single instance, long name (v3.4)', // TODO + MQTT_ENTITY_FORMAT_1: 'Single instance, short name', // TODO + MQTT_ENTITY_FORMAT_2: 'Multiple instances, short name', // TODO MQTT_CLEAN_SESSION: 'Använd "Clean Session"-flaggan', MQTT_RETAIN_FLAG: 'Använd "Always Retain"-flaggan', INACTIVE: 'Inaktiv', diff --git a/interface/src/validators/mqtt.ts b/interface/src/validators/mqtt.ts index a38e2d8a0..817c9b610 100644 --- a/interface/src/validators/mqtt.ts +++ b/interface/src/validators/mqtt.ts @@ -1,19 +1,23 @@ import Schema from 'async-validator'; +import { MqttSettings } from '../types'; import { IP_OR_HOSTNAME_VALIDATOR } from './shared'; -export const MQTT_SETTINGS_VALIDATOR = new Schema({ - host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR], - base: { required: true, message: 'Base is required' }, - port: [ - { required: true, message: 'Port is required' }, - { type: 'number', min: 0, max: 65535, message: 'Invalid Port' } - ], - keep_alive: [ - { required: true, message: 'Keep alive is required' }, - { type: 'number', min: 1, max: 86400, message: 'Keep alive must be between 1 and 86400' } - ], - publish_time_heartbeat: [ - { required: true, message: 'Heartbeat is required' }, - { type: 'number', min: 10, max: 86400, message: 'Heartbeat must be between 10 and 86400' } - ] -}); +export const createMqttSettingsValidator = (mqttSettings: MqttSettings) => + new Schema({ + ...(mqttSettings.enabled && { + host: [{ required: true, message: 'Host is required' }, IP_OR_HOSTNAME_VALIDATOR], + base: { required: true, message: 'Base is required' }, + port: [ + { required: true, message: 'Port is required' }, + { type: 'number', min: 0, max: 65535, message: 'Invalid Port' } + ], + keep_alive: [ + { required: true, message: 'Keep alive is required' }, + { type: 'number', min: 1, max: 86400, message: 'Keep alive must be between 1 and 86400' } + ], + publish_time_heartbeat: [ + { required: true, message: 'Heartbeat is required' }, + { type: 'number', min: 10, max: 86400, message: 'Heartbeat must be between 10 and 86400' } + ] + }) + }); diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index f54372578..7491691c5 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -125,8 +125,8 @@ void MqttSettingsService::configureMqtt() { // disconnect if connected _mqttClient.disconnect(); // only connect if WiFi is connected and MQTT is enabled - if (_state.enabled && emsesp::EMSESP::system_.network_connected()) { - // emsesp::EMSESP::logger().info("Configuring Mqtt client"); + if (_state.enabled && emsesp::EMSESP::system_.network_connected() && !_state.host.isEmpty()) { + // emsesp::EMSESP::logger().info("Configuring MQTT client"); _mqttClient.setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port); if (_state.username.length() > 0) { _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.connect(); // } else { - // emsesp::EMSESP::logger().info("Error configuring Mqtt client"); + // emsesp::EMSESP::logger().info("Error configuring MQTT client"); } } diff --git a/lib/framework/MqttSettingsService.h b/lib/framework/MqttSettingsService.h index ab6766b35..d4ec575cc 100644 --- a/lib/framework/MqttSettingsService.h +++ b/lib/framework/MqttSettingsService.h @@ -19,7 +19,7 @@ #endif #ifndef FACTORY_MQTT_HOST -#define FACTORY_MQTT_HOST "test.mosquitto.org" +#define FACTORY_MQTT_HOST "" // is blank #endif #ifndef FACTORY_MQTT_PORT diff --git a/lib_standalone/ESP8266React.h b/lib_standalone/ESP8266React.h index b8c599862..e469cc380 100644 --- a/lib_standalone/ESP8266React.h +++ b/lib_standalone/ESP8266React.h @@ -26,42 +26,43 @@ class DummySettings { public: - String locale = "en"; - uint8_t tx_mode = 1; - uint8_t ems_bus_id = 0x0B; - bool syslog_enabled = false; - int8_t syslog_level = 3; // uuid::log::Level - uint32_t syslog_mark_interval = 0; - String syslog_host = "192.168.1.4"; - uint16_t syslog_port = 514; - bool shower_timer = true; - bool shower_alert = false; - uint8_t shower_alert_coldshot = 10; - uint8_t shower_alert_trigger = 7; - bool hide_led = false; - bool notoken_api = false; - bool readonly_mode = false; - uint8_t bool_format = 1; // using "on" and "off" - uint8_t bool_dashboard = 1; - uint8_t enum_format = 1; - bool nosleep = false; - bool fahrenheit = false; - bool bandwidth20 = false; - bool telnet_enabled = false; - String board_profile = "CUSTOM"; - bool trace_raw = false; - bool analog_enabled = true; // analog is enabled - int8_t weblog_level = 1; - uint8_t weblog_buffer = 50; - bool weblog_compact = true; - uint8_t rx_gpio = 0; - uint8_t tx_gpio = 0; - uint8_t dallas_gpio = 16; // to ensure its enabled - bool dallas_parasite = false; - uint8_t led_gpio = 0; - bool low_clock = false; - uint8_t pbutton_gpio = false; - uint8_t solar_maxflow = 30; + std::string version{"poerp"}; + String locale = "en"; + uint8_t tx_mode = 1; + uint8_t ems_bus_id = 0x0B; + bool syslog_enabled = false; + int8_t syslog_level = 3; // uuid::log::Level + uint32_t syslog_mark_interval = 0; + String syslog_host = "192.168.1.4"; + uint16_t syslog_port = 514; + bool shower_timer = true; + bool shower_alert = false; + uint8_t shower_alert_coldshot = 10; + uint8_t shower_alert_trigger = 7; + bool hide_led = false; + bool notoken_api = false; + bool readonly_mode = false; + uint8_t bool_format = 1; // using "on" and "off" + uint8_t bool_dashboard = 1; + uint8_t enum_format = 1; + bool nosleep = false; + bool fahrenheit = false; + bool bandwidth20 = false; + bool telnet_enabled = false; + String board_profile = "CUSTOM"; + bool trace_raw = false; + bool analog_enabled = true; // analog is enabled + int8_t weblog_level = 1; + uint8_t weblog_buffer = 50; + bool weblog_compact = true; + uint8_t rx_gpio = 0; + uint8_t tx_gpio = 0; + uint8_t dallas_gpio = 16; // to ensure its enabled + bool dallas_parasite = false; + uint8_t led_gpio = 0; + bool low_clock = false; + uint8_t pbutton_gpio = false; + uint8_t solar_maxflow = 30; // MQTT uint16_t publish_time = 10; diff --git a/lib_standalone/FSPersistence.h b/lib_standalone/FSPersistence.h index 345e9b8ae..a547b26f8 100644 --- a/lib_standalone/FSPersistence.h +++ b/lib_standalone/FSPersistence.h @@ -24,6 +24,7 @@ class FSPersistence { } void readFromFS() { + Serial.println(); Serial.print("Fake reading file "); Serial.println(_filePath); applyDefaults(); diff --git a/src/emsdevicevalue.h b/src/emsdevicevalue.h index 42e93e2ee..918570a8a 100644 --- a/src/emsdevicevalue.h +++ b/src/emsdevicevalue.h @@ -48,28 +48,28 @@ class DeviceValue { // also used with HA as uom enum DeviceValueUOM : uint8_t { NONE = 0, // 0 - DEGREES, // 1 - DEGREES_R, // 2 - relative temperature - PERCENT, // 3 + DEGREES, // 1 - °C + DEGREES_R, // 2 - °C (relative temperature) + PERCENT, // 3 - % LMIN, // 4 - l/min KWH, // 5 - kWh WH, // 6 - Wh - HOURS, // 7 - MINUTES, // 8 + HOURS, // 7 - h + MINUTES, // 8 - m UA, // 9 - µA - BAR, // 10 + BAR, // 10 - bar KW, // 11 - kW - W, // 12 - KB, // 13 - SECONDS, // 14 + W, // 12 - W + KB, // 13 - kB + SECONDS, // 14 - s DBM, // 15 - dBm - FAHRENHEIT, // 16 + FAHRENHEIT, // 16 - °F MV, // 17 - mV - SQM, // 18 - square meter - M3, // 19 - cubic meter - L, // 20 - liter - KMIN, // 21 - Kelvin * minutes - K, // 22 - Kelvin + SQM, // 18 - m² + M3, // 19 - m³ + L, // 20 - L + KMIN, // 21 - K*min + K, // 22 - K CONNECTIVITY // 23 - used in HA }; diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 3fe710cd5..fee5d5bc4 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -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()); - // do any system upgrades - if (system_.check_upgrade()) { - LOG_INFO("System needs a restart to apply new settings. Please wait."); + // see if we're restoring a settings file + if (system_.check_restore()) { + LOG_WARNING("System needs a restart to apply new settings. Please wait."); + system_.system_restart(); + }; + + 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(); }; - webSettingsService.begin(); // load EMS-ESP Application settings... system_.reload_settings(); // ... and store some of the settings locally webCustomizationService.begin(); // load the customizations diff --git a/src/locale_common.h b/src/locale_common.h index ce4d79603..2b757d513 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -197,7 +197,7 @@ MAKE_PSTR_LIST(tpl_input, "Format: [[]") // 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_percent, "%") MAKE_PSTR(uom_degrees, "°C") diff --git a/src/mqtt.cpp b/src/mqtt.cpp index bfb350a6c..c034f7a74 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -66,16 +66,10 @@ MAKE_PSTR_WORD(measurement) MAKE_PSTR_WORD(total_increasing) MAKE_PSTR(icondegrees, "mdi:coolant-temperature") // DeviceValueUOM::DEGREES 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(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(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(icondevice, "mdi:home-automation") // for devices in HA +MAKE_PSTR(iconua, "mdi:lightning-bolt-circle") // DeviceValueUOM::UA +MAKE_PSTR(iconnum, "mdi:counter") // DeviceValueUOM::NONE 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[sc_ha] = F_(measurement); } else { - // always set the uom - if (uom != DeviceValueUOM::NONE) { + // always set the uom, using the standards except for hours/minutes/seconds + // 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); } } @@ -1196,12 +1198,12 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev case DeviceValueUOM::SECONDS: case DeviceValueUOM::MINUTES: case DeviceValueUOM::HOURS: - doc[ic_ha] = F_(icontime); if (type == DeviceValueType::TIME) { doc[sc_ha] = F_(total_increasing); } else { doc[sc_ha] = F_(measurement); } + doc[dc_ha] = "duration"; // https://github.com/emsesp/EMS-ESP32/issues/822 break; case DeviceValueUOM::KB: doc[ic_ha] = F_(iconkb); diff --git a/src/system.cpp b/src/system.cpp index 78cf34789..256d35fd9 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -290,6 +290,8 @@ void System::syslog_init() { // read some specific system settings to store locally for faster access void System::reload_settings() { EMSESP::webSettingsService.read([&](WebSettings & settings) { + version_ = settings.version; + pbutton_gpio_ = settings.pbutton_gpio; analog_enabled_ = settings.analog_enabled; low_clock_ = settings.low_clock; @@ -969,10 +971,8 @@ void System::show_system(uuid::console::Shell & shell) { #endif } -// handle upgrades from previous versions -// or managing an uploaded files to replace settings files -// returns true if we need a reboot -bool System::check_upgrade() { +// see if there is a restore of an older settings file that needs to be applied +bool System::check_restore() { bool reboot_required = false; #ifndef EMSESP_STANDALONE @@ -1012,6 +1012,50 @@ bool System::check_upgrade() { 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 bool System::command_commands(const char * value, const int8_t id, JsonObject & output) { return Command::list(EMSdevice::DeviceType::SYSTEM, output); diff --git a/src/system.h b/src/system.h index 3f4169306..789de9018 100644 --- a/src/system.h +++ b/src/system.h @@ -75,6 +75,7 @@ class System { void wifi_tweak(); void syslog_init(); bool check_upgrade(); + bool check_restore(); bool heartbeat_json(JsonObject & output); void send_heartbeat(); void send_info_mqtt(const char * event_str, bool send_ntp = false); @@ -294,6 +295,7 @@ class System { uint8_t bool_format_; uint8_t enum_format_; bool readonly_mode_; + std::string version_; // ethernet uint8_t phy_type_; diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index b17963680..5923a0a97 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -80,6 +80,10 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) { // call on initialization and also when settings are updated via web or console 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 std::vector data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode #if CONFIG_IDF_TARGET_ESP32C3 diff --git a/src/web/WebSettingsService.h b/src/web/WebSettingsService.h index a20e10c9a..2addbb4cb 100644 --- a/src/web/WebSettingsService.h +++ b/src/web/WebSettingsService.h @@ -29,40 +29,41 @@ namespace emsesp { class WebSettings { public: - String locale; - uint8_t tx_mode; - uint8_t ems_bus_id; - bool shower_timer; - bool shower_alert; - uint8_t shower_alert_trigger; - uint8_t shower_alert_coldshot; - bool syslog_enabled; - int8_t syslog_level; // uuid::log::Level - uint32_t syslog_mark_interval; - String syslog_host; - uint16_t syslog_port; - bool trace_raw; - uint8_t rx_gpio; - uint8_t tx_gpio; - uint8_t dallas_gpio; - bool dallas_parasite; - uint8_t led_gpio; - bool hide_led; - bool low_clock; - bool telnet_enabled; - bool notoken_api; - bool readonly_mode; - bool analog_enabled; - uint8_t pbutton_gpio; - uint8_t solar_maxflow; - String board_profile; - uint8_t bool_format; - uint8_t bool_dashboard; - uint8_t enum_format; - int8_t weblog_level; - uint8_t weblog_buffer; - bool weblog_compact; - bool fahrenheit; + std::string version; + String locale; + uint8_t tx_mode; + uint8_t ems_bus_id; + bool shower_timer; + bool shower_alert; + uint8_t shower_alert_trigger; + uint8_t shower_alert_coldshot; + bool syslog_enabled; + int8_t syslog_level; // uuid::log::Level + uint32_t syslog_mark_interval; + String syslog_host; + uint16_t syslog_port; + bool trace_raw; + uint8_t rx_gpio; + uint8_t tx_gpio; + uint8_t dallas_gpio; + bool dallas_parasite; + uint8_t led_gpio; + bool hide_led; + bool low_clock; + bool telnet_enabled; + bool notoken_api; + bool readonly_mode; + bool analog_enabled; + uint8_t pbutton_gpio; + uint8_t solar_maxflow; + String board_profile; + uint8_t bool_format; + uint8_t bool_dashboard; + uint8_t enum_format; + int8_t weblog_level; + uint8_t weblog_buffer; + bool weblog_compact; + bool fahrenheit; uint8_t phy_type; int8_t eth_power; // -1 means disabled