From 3ffa9ee5acc558f4115b5e4ff108818c2c3b842b Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 14 Nov 2020 00:08:05 +0100 Subject: [PATCH] move device unique_id count into constructor --- src/emsdevice.h | 3 ++- src/emsesp.cpp | 11 ++++++----- src/emsesp.h | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/emsdevice.h b/src/emsdevice.h index 81ac08c44..a4a9fe2a1 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -43,6 +43,7 @@ class EMSdevice { , name_(name) , flags_(flags) , brand_(brand) { + unique_id_++; } virtual ~EMSdevice() = default; // destructor of base class must always be virtual because it's a polymorphic class @@ -270,7 +271,7 @@ class EMSdevice { static constexpr uint8_t EMS_DEVICE_FLAG_JUNKERS_2 = (1 << 6); // 6th bit set if older models, like FR120, FR100 private: - uint8_t unique_id_; + uint8_t unique_id_ = 0; uint8_t device_type_ = DeviceType::SYSTEM; uint8_t device_id_ = 0; uint8_t product_id_ = 0; diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 91b30df71..ad6273945 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -63,7 +63,6 @@ bool EMSESP::read_next_ = false; uint16_t EMSESP::publish_id_ = 0; bool EMSESP::tap_water_active_ = false; // for when Boiler states we having running warm water. used in Shower() uint32_t EMSESP::last_fetch_ = 0; -uint8_t EMSESP::unique_id_count_ = 0; // for a specific EMS device go and request data values // or if device_id is 0 it will fetch from all our known and active devices @@ -722,17 +721,19 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std:: return false; // not found } - std::string name = uuid::read_flash_string(device_p->name); - emsdevices.push_back(EMSFactory::add(device_p->device_type, device_id, device_p->product_id, version, name, device_p->flags, brand)); - emsdevices.back()->unique_id(++unique_id_count_); + auto name = uuid::read_flash_string(device_p->name); + auto device_type = device_p->device_type; + auto flags = device_p->flags; LOG_DEBUG(F("Adding new device %s (device ID 0x%02X, product ID %d, version %s)"), name.c_str(), device_id, product_id, version.c_str()); + emsdevices.push_back(EMSFactory::add(device_type, device_id, product_id, version, name, flags, brand)); + fetch_device_values(device_id); // go and fetch its data // add info command, but not for all devices - uint8_t device_type = device_p->device_type; if ((device_type == DeviceType::CONNECT) || (device_type == DeviceType::CONTROLLER) || (device_type == DeviceType::GATEWAY)) { return true; } + Command::add_with_json(device_type, F_(info), [device_type](const char * value, const int8_t id, JsonObject & json) { return command_info(device_type, json); }); diff --git a/src/emsesp.h b/src/emsesp.h index 0fd6d976a..5b6e95052 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -206,7 +206,6 @@ class EMSESP { static bool read_next_; static uint16_t publish_id_; static bool tap_water_active_; - static uint8_t unique_id_count_; }; } // namespace emsesp