mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
check device active for fetching values
This commit is contained in:
@@ -323,6 +323,9 @@ std::string EMSdevice::to_string_short() {
|
|||||||
|
|
||||||
// for each telegram that has the fetch value set (true) do a read request
|
// for each telegram that has the fetch value set (true) do a read request
|
||||||
void EMSdevice::fetch_values() {
|
void EMSdevice::fetch_values() {
|
||||||
|
if (!active_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
EMSESP::logger().debug("Fetching values for deviceID 0x%02X", device_id());
|
EMSESP::logger().debug("Fetching values for deviceID 0x%02X", device_id());
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -111,6 +111,10 @@ class EMSdevice {
|
|||||||
return brand_;
|
return brand_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void active(bool active) {
|
||||||
|
active_ = active;
|
||||||
|
}
|
||||||
|
|
||||||
// set custom device name
|
// set custom device name
|
||||||
inline void custom_name(std::string const & custom_name) {
|
inline void custom_name(std::string const & custom_name) {
|
||||||
custom_name_ = custom_name;
|
custom_name_ = custom_name;
|
||||||
@@ -487,6 +491,7 @@ class EMSdevice {
|
|||||||
std::string custom_name_ = ""; // custom name
|
std::string custom_name_ = ""; // custom name
|
||||||
uint8_t flags_ = 0;
|
uint8_t flags_ = 0;
|
||||||
uint8_t brand_ = Brand::NO_BRAND;
|
uint8_t brand_ = Brand::NO_BRAND;
|
||||||
|
bool active_ = true;
|
||||||
|
|
||||||
bool ha_config_done_ = false;
|
bool ha_config_done_ = false;
|
||||||
bool has_update_ = false;
|
bool has_update_ = false;
|
||||||
|
|||||||
@@ -943,20 +943,18 @@ void EMSESP::process_UBADevices(std::shared_ptr<const Telegram> telegram) {
|
|||||||
// for each byte, check the bits and determine the device_id
|
// for each byte, check the bits and determine the device_id
|
||||||
for (uint8_t data_byte = 0; data_byte < telegram->message_length; data_byte++) {
|
for (uint8_t data_byte = 0; data_byte < telegram->message_length; data_byte++) {
|
||||||
uint8_t next_byte = telegram->message_data[data_byte];
|
uint8_t next_byte = telegram->message_data[data_byte];
|
||||||
|
for (uint8_t bit = 0; bit < 8; bit++) {
|
||||||
if (next_byte) {
|
uint8_t device_id = ((data_byte + 1) * 8) + bit;
|
||||||
for (uint8_t bit = 0; bit < 8; bit++) {
|
EMSESP::device_active(device_id, next_byte & 0x01);
|
||||||
if (next_byte & 0x01) {
|
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)
|
||||||
// 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
|
||||||
// when the version info is received, it will automagically add the device
|
if ((device_id != EMSbus::ems_bus_id()) && !(EMSESP::device_exists(device_id))) {
|
||||||
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);
|
||||||
LOG_DEBUG("New EMS device detected with ID 0x%02X. Requesting version information.", device_id);
|
send_read_request(EMSdevice::EMS_TYPE_VERSION, 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
|
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
|
// for each associated EMS device go and get its system information
|
||||||
void EMSESP::show_devices(uuid::console::Shell & shell) {
|
void EMSESP::show_devices(uuid::console::Shell & shell) {
|
||||||
if (emsdevices.empty()) {
|
if (emsdevices.empty()) {
|
||||||
|
|||||||
@@ -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 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 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 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);
|
static uint8_t device_id_from_cmd(const uint8_t device_type, const char * cmd, const int8_t id);
|
||||||
|
|||||||
Reference in New Issue
Block a user