mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
no ha_entitiy_config remove
This commit is contained in:
2171
interface/package-lock.json
generated
2171
interface/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -8,15 +8,15 @@
|
||||
"@emotion/styled": "^11.10.6",
|
||||
"@msgpack/msgpack": "^2.8.0",
|
||||
"@mui/icons-material": "^5.11.9",
|
||||
"@mui/material": "^5.11.9",
|
||||
"@table-library/react-table-library": "4.0.25",
|
||||
"@mui/material": "^5.11.10",
|
||||
"@table-library/react-table-library": "4.0.26",
|
||||
"@types/lodash": "^4.14.191",
|
||||
"@types/node": "^18.14.0",
|
||||
"@types/react": "^18.0.28",
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"async-validator": "^4.2.5",
|
||||
"axios": "^1.3.3",
|
||||
"axios": "^1.3.4",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"lodash": "^4.17.21",
|
||||
"notistack": "^2.0.8",
|
||||
|
||||
@@ -1642,23 +1642,6 @@ bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, c
|
||||
return has_values;
|
||||
}
|
||||
|
||||
// remove the Home Assistant configs for each device value/entity if its not visible or active or marked as read-only
|
||||
// this is called when an MQTT publish is done via an EMS Device in emsesp.cpp::publish_device_values()
|
||||
void EMSdevice::mqtt_ha_entity_config_remove() {
|
||||
for (auto & dv : devicevalues_) {
|
||||
if (dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED)
|
||||
&& ((dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE)) || (!dv.has_state(DeviceValueState::DV_ACTIVE)))) {
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_RECREATE);
|
||||
if (dv.short_name == FL_(climate)[0]) {
|
||||
Mqtt::publish_ha_climate_config(dv.tag, false, true); // delete topic (remove = true)
|
||||
} else {
|
||||
Mqtt::publish_ha_sensor_config(dv, "", "", true); // delete topic (remove = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create the Home Assistant configs for each device value / entity
|
||||
// this is called when an MQTT publish is done via an EMS Device in emsesp.cpp::publish_device_values()
|
||||
void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
@@ -1668,10 +1651,6 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
// create climate if roomtemp is visible
|
||||
// create the discovery topic if if hasn't already been created, not a command (like reset) and is active and visible
|
||||
for (auto & dv : devicevalues_) {
|
||||
if (dv.has_state(DeviceValueState::DV_HA_CONFIG_RECREATE)) {
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_RECREATE);
|
||||
}
|
||||
if ((dv.short_name == FL_(climate)[0]) && !dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE) && dv.has_state(DeviceValueState::DV_ACTIVE)) {
|
||||
if (*(int8_t *)(dv.value_p) == 1 && (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) || dv.has_state(DeviceValueState::DV_HA_CLIMATE_NO_RT))) {
|
||||
dv.remove_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
|
||||
@@ -1691,6 +1670,9 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
create_device_config = false; // only create the main config once
|
||||
}
|
||||
if (ESP.getFreeHeap() < (65 * 1024)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ha_config_done(!create_device_config);
|
||||
@@ -1699,10 +1681,7 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
// remove all config topics in HA
|
||||
void EMSdevice::ha_config_clear() {
|
||||
for (auto & dv : devicevalues_) {
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_RECREATE);
|
||||
if (ha_config_firstrun()) {
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED); // make sure it is removed if not active
|
||||
}
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
}
|
||||
|
||||
ha_config_done(false); // this will force the recreation of the main HA device config
|
||||
|
||||
@@ -289,7 +289,6 @@ class EMSdevice {
|
||||
void publish_all_values();
|
||||
|
||||
void mqtt_ha_entity_config_create();
|
||||
void mqtt_ha_entity_config_remove();
|
||||
|
||||
std::string telegram_type_name(std::shared_ptr<const Telegram> telegram) const;
|
||||
|
||||
@@ -306,13 +305,6 @@ class EMSdevice {
|
||||
ha_config_done_ = v;
|
||||
}
|
||||
|
||||
bool ha_config_firstrun() const {
|
||||
return ha_config_firstrun_;
|
||||
}
|
||||
void ha_config_firstrun(const bool v) {
|
||||
ha_config_firstrun_ = v;
|
||||
}
|
||||
|
||||
enum Brand : uint8_t {
|
||||
NO_BRAND = 0, // 0
|
||||
BOSCH, // 1
|
||||
@@ -432,7 +424,6 @@ class EMSdevice {
|
||||
|
||||
bool ha_config_done_ = false;
|
||||
bool has_update_ = false;
|
||||
bool ha_config_firstrun_ = true; // this means a first setup of HA is needed after a restart
|
||||
|
||||
struct TelegramFunction {
|
||||
uint16_t telegram_type_id_; // it's type_id
|
||||
|
||||
@@ -120,11 +120,10 @@ class DeviceValue {
|
||||
// states of a device value
|
||||
enum DeviceValueState : uint8_t {
|
||||
// low nibble active state of the device value
|
||||
DV_DEFAULT = 0, // 0 - does not yet have a value
|
||||
DV_ACTIVE = (1 << 0), // 1 - has a validated real value
|
||||
DV_HA_CONFIG_CREATED = (1 << 1), // 2 - set if the HA config topic has been created
|
||||
DV_HA_CLIMATE_NO_RT = (1 << 2), // 4 - climate created without roomTemp
|
||||
DV_HA_CONFIG_RECREATE = (1 << 3), // 8 - set on reconnect to recreate HA config topic
|
||||
DV_DEFAULT = 0, // 0 - does not yet have a value
|
||||
DV_ACTIVE = (1 << 0), // 1 - has a validated real value
|
||||
DV_HA_CONFIG_CREATED = (1 << 1), // 2 - set if the HA config topic has been created
|
||||
DV_HA_CLIMATE_NO_RT = (1 << 2), // 4 - climate created without roomTemp
|
||||
|
||||
// high nibble as mask for exclusions & special functions
|
||||
DV_WEB_EXCLUDE = (1 << 4), // 16 - not shown on web
|
||||
|
||||
@@ -535,24 +535,6 @@ void EMSESP::publish_device_values(uint8_t device_type) {
|
||||
bool nested = (Mqtt::is_nested());
|
||||
|
||||
// group by device type
|
||||
if (Mqtt::ha_enabled()) {
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
// specially for MQTT Discovery
|
||||
// we may have some RETAINED /config topics that reference fields in the data payloads that no longer exist
|
||||
// remove them immediately to prevent HA from complaining
|
||||
// we need to do this first before the data payload is published, and only done once!
|
||||
if (emsdevice->ha_config_firstrun()) {
|
||||
emsdevice->ha_config_clear();
|
||||
emsdevice->ha_config_firstrun(false);
|
||||
return;
|
||||
} else {
|
||||
// see if we need to delete and /config topics before adding the payloads
|
||||
emsdevice->mqtt_ha_entity_config_remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint8_t tag = DeviceValueTAG::TAG_BOILER_DATA_WW; tag <= DeviceValueTAG::TAG_HS16; tag++) {
|
||||
JsonObject json_hc = json;
|
||||
bool nest_created = false;
|
||||
|
||||
@@ -685,7 +685,7 @@ std::shared_ptr<const MqttMessage> Mqtt::queue_message(const uint8_t operation,
|
||||
#endif
|
||||
|
||||
// if the queue is full, make room but removing the last one
|
||||
if (mqtt_messages_.size() >= MAX_MQTT_MESSAGES) {
|
||||
if (mqtt_messages_.size() >= MAX_MQTT_MESSAGES || ESP.getFreeHeap() < (60 * 1024)) {
|
||||
mqtt_messages_.pop_front();
|
||||
LOG_WARNING("Queue overflow, removing one message");
|
||||
mqtt_publish_fails_++;
|
||||
@@ -1304,8 +1304,8 @@ void Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp,
|
||||
char hc_mode_s[30];
|
||||
char seltemp_s[30];
|
||||
char currtemp_s[30];
|
||||
char hc_mode_cond[70];
|
||||
char seltemp_cond[70];
|
||||
char hc_mode_cond[80];
|
||||
char seltemp_cond[80];
|
||||
char currtemp_cond[170];
|
||||
char mode_str_tpl[400];
|
||||
char name_s[10];
|
||||
@@ -1434,17 +1434,20 @@ void Mqtt::add_avty_to_doc(const char * state_t, const JsonObject & doc, const c
|
||||
snprintf(tpl, sizeof(tpl), tpl_draft, "value == 'online'");
|
||||
avty_json["val_tpl"] = tpl;
|
||||
avty.add(avty_json);
|
||||
avty.clear();
|
||||
|
||||
avty_json["t"] = state_t;
|
||||
snprintf(tpl, sizeof(tpl), tpl_draft, cond1 == nullptr ? "value is defined" : cond1);
|
||||
avty_json["val_tpl"] = tpl;
|
||||
avty.add(avty_json);
|
||||
if (cond2 != nullptr) {
|
||||
avty.clear();
|
||||
snprintf(tpl, sizeof(tpl), tpl_draft, cond2);
|
||||
avty_json["val_tpl"] = tpl;
|
||||
avty.add(avty_json);
|
||||
}
|
||||
if (negcond != nullptr) {
|
||||
avty.clear();
|
||||
snprintf(tpl, sizeof(tpl), "{{'offline' if %s else 'online'}}", negcond);
|
||||
avty_json["val_tpl"] = tpl;
|
||||
avty.add(avty_json);
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.5.1-dev.0"
|
||||
#define EMSESP_APP_VERSION "3.5.1-dev.1"
|
||||
|
||||
Reference in New Issue
Block a user