From cd4d0f5abe75fbcd21e3a10826217e3e7cbf1eb6 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 3 Oct 2024 13:23:19 +0200 Subject: [PATCH] check device active for fetching values --- src/emsdevice.cpp | 3 +++ src/emsdevice.h | 5 +++++ src/emsesp.cpp | 31 +++++++++++++++++++------------ src/emsesp.h | 1 + 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 9fda392c5..c3a12e875 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -323,6 +323,9 @@ std::string EMSdevice::to_string_short() { // for each telegram that has the fetch value set (true) do a read request void EMSdevice::fetch_values() { + if (!active_) { + return; + } #if defined(EMSESP_DEBUG) EMSESP::logger().debug("Fetching values for deviceID 0x%02X", device_id()); #endif diff --git a/src/emsdevice.h b/src/emsdevice.h index cb7716ed9..a20e244fe 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -111,6 +111,10 @@ class EMSdevice { return brand_; } + inline void active(bool active) { + active_ = active; + } + // set custom device name inline void custom_name(std::string const & custom_name) { custom_name_ = custom_name; @@ -487,6 +491,7 @@ class EMSdevice { std::string custom_name_ = ""; // custom name uint8_t flags_ = 0; uint8_t brand_ = Brand::NO_BRAND; + bool active_ = true; bool ha_config_done_ = false; bool has_update_ = false; diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 12a515590..98edf78f2 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -943,20 +943,18 @@ void EMSESP::process_UBADevices(std::shared_ptr telegram) { // for each byte, check the bits and determine the device_id for (uint8_t data_byte = 0; data_byte < telegram->message_length; data_byte++) { uint8_t next_byte = telegram->message_data[data_byte]; - - if (next_byte) { - for (uint8_t bit = 0; bit < 8; bit++) { - if (next_byte & 0x01) { - uint8_t device_id = ((data_byte + 1) * 8) + bit; - // if we haven't already detected this device, request it's version details, unless its us (EMS-ESP) - // when the version info is received, it will automagically add the device - if ((device_id != EMSbus::ems_bus_id()) && !(EMSESP::device_exists(device_id))) { - LOG_DEBUG("New EMS device detected with ID 0x%02X. Requesting version information.", device_id); - send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id); - } + for (uint8_t bit = 0; bit < 8; bit++) { + uint8_t device_id = ((data_byte + 1) * 8) + bit; + EMSESP::device_active(device_id, next_byte & 0x01); + if (next_byte & 0x01) { + // if we haven't already detected this device, request it's version details, unless its us (EMS-ESP) + // when the version info is received, it will automagically add the device + if ((device_id != EMSbus::ems_bus_id()) && !(EMSESP::device_exists(device_id))) { + LOG_DEBUG("New EMS device detected with ID 0x%02X. Requesting version information.", device_id); + send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id); } - next_byte = next_byte >> 1; // advance 1 bit } + next_byte = next_byte >> 1; // advance 1 bit } } } @@ -1141,6 +1139,15 @@ bool EMSESP::device_exists(const uint8_t device_id) { return false; // not found } +void EMSESP::device_active(const uint8_t device_id, const bool active) { + for (auto & emsdevice : emsdevices) { + if (emsdevice && emsdevice->is_device_id(device_id)) { + emsdevice->active(active); + return; + } + } +} + // for each associated EMS device go and get its system information void EMSESP::show_devices(uuid::console::Shell & shell) { if (emsdevices.empty()) { diff --git a/src/emsesp.h b/src/emsesp.h index 9f1ba1efd..214304bf8 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -125,6 +125,7 @@ class EMSESP { static void send_write_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t value, const uint16_t validate_typeid); static bool device_exists(const uint8_t device_id); + static void device_active(const uint8_t device_id, const bool active); static bool cmd_is_readonly(const uint8_t device_type, const uint8_t device_id, const char * cmd, const int8_t id); static uint8_t device_id_from_cmd(const uint8_t device_type, const char * cmd, const int8_t id);