mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 09:19:51 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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>]")
|
||||
|
||||
// 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")
|
||||
|
||||
24
src/mqtt.cpp
24
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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<int8_t> data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user