Skip to content

Commit

Permalink
set default link timout at 30s and improve config log (m3_victron_ble…
Browse files Browse the repository at this point in the history
…_ir)
  • Loading branch information
krahabb committed Sep 25, 2024
1 parent 7243024 commit 6d2584b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion esphome/components/m3_victron_ble_ir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def validate_auto_create_entities(value):
cv.Required(CONF_BINDKEY): bind_key_array,
cv.Optional(CONF_AUTO_CREATE_ENTITIES): validate_auto_create_entities,
cv.Optional(
CONF_LINK_CONNECTED_TIMEOUT, default="20s"
CONF_LINK_CONNECTED_TIMEOUT, default="30s"
): cv.positive_time_period_seconds,
cv.Optional(CONF_ON_MESSAGE): automation.validate_automation(
{
Expand Down
17 changes: 10 additions & 7 deletions esphome/components/m3_victron_ble_ir/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ static const char *const TAG = "m3_victron_ble_ir";

void Manager::dump_config() {
ESP_LOGCONFIG(TAG, "Victron BLE:");
ESP_LOGCONFIG(TAG, " Address: %s", this->address_str());
ESP_LOGCONFIG(TAG, " address: %s", this->address_str());
ESP_LOGCONFIG(TAG, " auto_create_entities: %s", TRUEFALSE(this->auto_create_entities_));
ESP_LOGCONFIG(TAG, " auto_create_type: %i", this->auto_create_type_);
ESP_LOGCONFIG(TAG, " link_connected_timeout: %i s", this->link_connected_timeout_ / 1000);
}

void Manager::setup() {
Expand Down Expand Up @@ -210,6 +213,11 @@ bool Manager::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
return false;
}

if (this->link_connected_) {
this->link_connected_->publish_state(true);
this->set_timeout("link_connected", this->link_connected_timeout_, [this]() { this->timeout_link_connected_(); });
}

// Filter out duplicate messages
if (victron_data->header.data_counter == this->record_.header.data_counter) {
return false;
Expand All @@ -229,7 +237,7 @@ bool Manager::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {

auto status = esp_aes_crypt_ctr(&this->aes_ctx_, crypted_len, &nc_offset, nonce_counter, stream_block,
victron_data->data.raw, this->record_.data.raw);
if (status != 0) {
if (status) {
ESP_LOGE(TAG, "[%s] Error during esp_aes_crypt_ctr operation (%i).", this->address_str(), status);
return false;
}
Expand All @@ -251,11 +259,6 @@ bool Manager::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
entity->parse(&this->record_);
}

if (this->link_connected_) {
this->link_connected_->publish_state(true);
this->set_timeout("link_connected", this->link_connected_timeout_, [this]() { this->timeout_link_connected_(); });
}

return true;
}
#endif
Expand Down

0 comments on commit 6d2584b

Please sign in to comment.