mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
process telegram selection of device
This commit is contained in:
@@ -685,7 +685,7 @@ bool EMSESP::get_device_value_info(JsonObject root, const char * cmd, const int8
|
||||
return EMSESP::webSchedulerService.get_value_info(root, cmd);
|
||||
}
|
||||
|
||||
// own entities
|
||||
// custom entities
|
||||
if (devicetype == DeviceType::CUSTOM) {
|
||||
return EMSESP::webCustomEntityService.get_value_info(root, cmd);
|
||||
}
|
||||
@@ -721,7 +721,6 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
std::string dest_name("");
|
||||
std::string type_name("");
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice) {
|
||||
// get src & dest
|
||||
if (emsdevice->is_device_id(src)) {
|
||||
src_name = emsdevice->device_type_name();
|
||||
@@ -737,6 +736,13 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type_name.empty()) {
|
||||
// fallback, get the type name from src
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (telegram->operation != Telegram::Operation::RX_READ && emsdevice->is_device_id(src)) {
|
||||
type_name = emsdevice->telegram_type_name(telegram);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we can't find names for the devices, use their hex values
|
||||
@@ -919,16 +925,47 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
// calls the associated process function for that EMS device
|
||||
// returns false if the device_id doesn't recognize it
|
||||
// after the telegram has been processed, see if there have been values changed and we need to do a MQTT publish
|
||||
bool found = false;
|
||||
bool knowndevice = false;
|
||||
bool telegram_found = false;
|
||||
uint8_t device_found = 0;
|
||||
// broadcast or send to us
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice->is_device_id(telegram->src) && (telegram->dest == 0 || telegram->dest == EMSbus::ems_bus_id()|| telegram->dest == 0x10)) {
|
||||
knowndevice = true;
|
||||
found = emsdevice->handle_telegram(telegram);
|
||||
// if we correctly processed the telegram then follow up with sending it via MQTT (if enabled)
|
||||
if (found && Mqtt::connected()) {
|
||||
if ((mqtt_.get_publish_onchange(emsdevice->device_type()) && emsdevice->has_update())
|
||||
|| (telegram->type_id == publish_id_ && telegram->dest == EMSbus::ems_bus_id())) {
|
||||
if (emsdevice->is_device_id(telegram->src) && (telegram->dest == 0 || telegram->dest == EMSbus::ems_bus_id())) {
|
||||
telegram_found = emsdevice->handle_telegram(telegram);
|
||||
device_found = emsdevice->unique_id();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!telegram_found) {
|
||||
// check for command to the device
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice->is_device_id(telegram->dest) && telegram->src != EMSbus::ems_bus_id()) {
|
||||
telegram_found = emsdevice->handle_telegram(telegram);
|
||||
device_found = emsdevice->unique_id();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!telegram_found) {
|
||||
// check for sends to master thermostat
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice->is_device_id(telegram->src) && telegram->dest == 0x10) {
|
||||
telegram_found = emsdevice->handle_telegram(telegram);
|
||||
device_found = emsdevice->unique_id();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice->unique_id() == device_found) {
|
||||
if (telegram->message_length > 0) {
|
||||
emsdevice->add_handlers_ignored(telegram->type_id);
|
||||
}
|
||||
if (telegram->dest == 0 && telegram->offset == 0 && telegram->message_length > 0) {
|
||||
emsdevice->add_handlers_broadcasted(telegram->type_id);
|
||||
}
|
||||
if (Mqtt::connected() && telegram_found
|
||||
&& ((mqtt_.get_publish_onchange(emsdevice->device_type()) && emsdevice->has_update())
|
||||
|| (telegram->type_id == publish_id_ && telegram->dest == EMSbus::ems_bus_id()))) {
|
||||
if (telegram->type_id == publish_id_) {
|
||||
publish_id_ = 0;
|
||||
}
|
||||
@@ -937,31 +974,21 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
publish_device_values(emsdevice->device_type()); // publish to MQTT if we explicitly have too
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wait_validate_ == telegram->type_id) {
|
||||
wait_validate_ = 0;
|
||||
}
|
||||
if (!found && telegram->message_length > 0) {
|
||||
emsdevice->add_handlers_ignored(telegram->type_id);
|
||||
}
|
||||
break;
|
||||
} else if (emsdevice->is_device_id(telegram->dest) && telegram->src != EMSbus::ems_bus_id()) {
|
||||
emsdevice->handle_telegram(telegram);
|
||||
}
|
||||
}
|
||||
|
||||
// handle unknown broadcasted telegrams
|
||||
if (!found && telegram->dest == 0) {
|
||||
// handle unknown broadcasted telegrams (or send to us)
|
||||
if (!telegram_found && (telegram->dest == 0 || telegram->dest == EMSbus::ems_bus_id())) {
|
||||
LOG_DEBUG("No telegram type handler found for ID 0x%02X (src 0x%02X)", telegram->type_id, telegram->src);
|
||||
if (watch() == WATCH_UNKNOWN) {
|
||||
LOG_NOTICE("%s", pretty_telegram(telegram).c_str());
|
||||
}
|
||||
if (!wait_km_ && !knowndevice && (telegram->src != EMSbus::ems_bus_id()) && (telegram->message_length > 0)) {
|
||||
if (!wait_km_ && !device_found && (telegram->src != EMSbus::ems_bus_id()) && (telegram->message_length > 0)) {
|
||||
send_read_request(EMSdevice::EMS_TYPE_VERSION, telegram->src);
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
return telegram_found;
|
||||
}
|
||||
|
||||
// return true if we have this device already registered
|
||||
|
||||
Reference in New Issue
Block a user