Merge pull request #1289 from MichaelDvP/dev

Fixes from testbuild
This commit is contained in:
Proddy
2023-09-09 12:32:57 +02:00
committed by GitHub
6 changed files with 30 additions and 6 deletions

View File

@@ -1767,6 +1767,11 @@ const char * EMSdevice::telegram_type_name(std::shared_ptr<const Telegram> teleg
bool EMSdevice::handle_telegram(std::shared_ptr<const Telegram> telegram) { bool EMSdevice::handle_telegram(std::shared_ptr<const Telegram> telegram) {
for (auto & tf : telegram_functions_) { for (auto & tf : telegram_functions_) {
if (tf.telegram_type_id_ == telegram->type_id) { if (tf.telegram_type_id_ == telegram->type_id) {
// for telegram desitnation only read telegram
if (telegram->dest == device_id_ && telegram->message_length > 0) {
tf.process_function_(telegram);
return true;
}
// if the data block is empty and we have not received data before, assume that this telegram // if the data block is empty and we have not received data before, assume that this telegram
// is not recognized by the bus master. So remove it from the automatic fetch list // is not recognized by the bus master. So remove it from the automatic fetch list
if (telegram->message_length == 0 && telegram->offset == 0 && !tf.received_) { if (telegram->message_length == 0 && telegram->offset == 0 && !tf.received_) {

View File

@@ -939,6 +939,8 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
emsdevice->add_handlers_ignored(telegram->type_id); emsdevice->add_handlers_ignored(telegram->type_id);
} }
break; break;
} else if (emsdevice->is_device_id(telegram->dest)) {
emsdevice->handle_telegram(telegram);
} }
} }

View File

@@ -61,6 +61,7 @@ StateUpdateResult WebEntity::update(JsonObject & root, WebEntity & webEntity) {
Command::erase_command(EMSdevice::DeviceType::CUSTOM, entityItem.name.c_str()); Command::erase_command(EMSdevice::DeviceType::CUSTOM, entityItem.name.c_str());
} }
webEntity.entityItems.clear(); webEntity.entityItems.clear();
EMSESP::webEntityService.ha_reset();
if (root["entities"].is<JsonArray>()) { if (root["entities"].is<JsonArray>()) {
for (const JsonObject ei : root["entities"].as<JsonArray>()) { for (const JsonObject ei : root["entities"].as<JsonArray>()) {
@@ -319,7 +320,8 @@ void WebEntityService::publish(const bool force) {
} }
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE); DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE);
JsonObject output = doc.to<JsonObject>(); JsonObject output = doc.to<JsonObject>();
bool ha_created = ha_registered_;
for (const EntityItem & entityItem : *entityItems) { for (const EntityItem & entityItem : *entityItems) {
render_value(output, entityItem); render_value(output, entityItem);
// create HA config // create HA config
@@ -383,11 +385,10 @@ void WebEntityService::publish(const bool force) {
// add "availability" section // add "availability" section
Mqtt::add_avty_to_doc(stat_t, config.as<JsonObject>(), val_cond); Mqtt::add_avty_to_doc(stat_t, config.as<JsonObject>(), val_cond);
if (Mqtt::queue_ha(topic, config.as<JsonObject>())) { ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
ha_registered_ = true;
}
} }
} }
ha_registered_ = ha_created;
if (output.size() > 0) { if (output.size() > 0) {
Mqtt::queue_publish("custom_data", output); Mqtt::queue_publish("custom_data", output);
} }

View File

@@ -63,6 +63,9 @@ class WebEntityService : public StatefulService<WebEntity> {
uint8_t count_entities(); uint8_t count_entities();
uint8_t has_commands(); uint8_t has_commands();
void generate_value_web(JsonObject & output); void generate_value_web(JsonObject & output);
void ha_reset() {
ha_registered_ = false;
}
private: private:

View File

@@ -71,6 +71,7 @@ StateUpdateResult WebScheduler::update(JsonObject & root, WebScheduler & webSche
Command::erase_command(EMSdevice::DeviceType::SCHEDULER, scheduleItem.name.c_str()); Command::erase_command(EMSdevice::DeviceType::SCHEDULER, scheduleItem.name.c_str());
} }
webScheduler.scheduleItems.clear(); webScheduler.scheduleItems.clear();
EMSESP::webSchedulerService.ha_reset();
if (root["schedule"].is<JsonArray>()) { if (root["schedule"].is<JsonArray>()) {
for (const JsonObject schedule : root["schedule"].as<JsonArray>()) { for (const JsonObject schedule : root["schedule"].as<JsonArray>()) {
@@ -219,6 +220,12 @@ void WebSchedulerService::publish_single(const char * name, const bool state) {
// publish to Mqtt // publish to Mqtt
void WebSchedulerService::publish(const bool force) { void WebSchedulerService::publish(const bool force) {
if (force) {
ha_registered_ = false;
}
if (!Mqtt::enabled()) {
return;
}
EMSESP::webSchedulerService.read([&](WebScheduler & webScheduler) { scheduleItems = &webScheduler.scheduleItems; }); EMSESP::webSchedulerService.read([&](WebScheduler & webScheduler) { scheduleItems = &webScheduler.scheduleItems; });
if (scheduleItems->size() == 0) { if (scheduleItems->size() == 0) {
return; return;
@@ -230,6 +237,7 @@ void WebSchedulerService::publish(const bool force) {
} }
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE); DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE);
bool ha_created = ha_registered_;
for (const ScheduleItem & scheduleItem : *scheduleItems) { for (const ScheduleItem & scheduleItem : *scheduleItems) {
if (!scheduleItem.name.empty() && !doc.containsKey(scheduleItem.name)) { if (!scheduleItem.name.empty() && !doc.containsKey(scheduleItem.name)) {
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) { if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
@@ -242,7 +250,7 @@ void WebSchedulerService::publish(const bool force) {
} }
// create HA config // create HA config
if (Mqtt::ha_enabled() && force) { if (Mqtt::ha_enabled() && !ha_registered_) {
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config; StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config;
char stat_t[50]; char stat_t[50];
snprintf(stat_t, sizeof(stat_t), "%s/scheduler_data", Mqtt::basename().c_str()); snprintf(stat_t, sizeof(stat_t), "%s/scheduler_data", Mqtt::basename().c_str());
@@ -284,10 +292,11 @@ void WebSchedulerService::publish(const bool force) {
// add "availability" section // add "availability" section
Mqtt::add_avty_to_doc(stat_t, config.as<JsonObject>(), val_cond); Mqtt::add_avty_to_doc(stat_t, config.as<JsonObject>(), val_cond);
Mqtt::queue_ha(topic, config.as<JsonObject>()); ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
} }
} }
} }
ha_registered_ = ha_created;
if (doc.size() > 0) { if (doc.size() > 0) {
Mqtt::queue_publish("scheduler_data", doc.as<JsonObject>()); Mqtt::queue_publish("scheduler_data", doc.as<JsonObject>());
} }

View File

@@ -58,6 +58,9 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
bool has_commands(); bool has_commands();
bool command_setvalue(const char * value, const std::string name); bool command_setvalue(const char * value, const std::string name);
bool get_value_info(JsonObject & output, const char * cmd); bool get_value_info(JsonObject & output, const char * cmd);
void ha_reset() {
ha_registered_ = false;
}
// make all functions public so we can test in the debug and standalone mode // make all functions public so we can test in the debug and standalone mode
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
@@ -69,6 +72,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
FSPersistence<WebScheduler> _fsPersistence; FSPersistence<WebScheduler> _fsPersistence;
std::list<ScheduleItem> * scheduleItems; // pointer to the list of schedule events std::list<ScheduleItem> * scheduleItems; // pointer to the list of schedule events
bool ha_registered_ = false;
}; };
} // namespace emsesp } // namespace emsesp