From 9c809f0e11ba7884ff00a28dc2c371b63f1e272f Mon Sep 17 00:00:00 2001 From: Thierry DUVERNOY Date: Thu, 16 Jan 2025 08:33:03 +0100 Subject: [PATCH] Solve clang-tidy script errors --- esphome/components/dallas_pio/binary_sensor.cpp | 6 ------ esphome/components/dallas_pio/dallas_pio.cpp | 17 ++++++++++++++++- esphome/components/dallas_pio/switch.cpp | 6 ------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/esphome/components/dallas_pio/binary_sensor.cpp b/esphome/components/dallas_pio/binary_sensor.cpp index 71b686cf07..99df2efa62 100644 --- a/esphome/components/dallas_pio/binary_sensor.cpp +++ b/esphome/components/dallas_pio/binary_sensor.cpp @@ -66,12 +66,6 @@ void DallasPioBinarySensor::update() { if (!this->dallas_pio_->read_state(state, this->pin_)) { return; } - } else if (this->reference_ == "DS2406") { - // Action pour DS2406 - } else if (this->reference_ == "DS2408") { - // Action pour DS2408 - } else { - // Action par défaut } if (this->pin_inverted_) { diff --git a/esphome/components/dallas_pio/dallas_pio.cpp b/esphome/components/dallas_pio/dallas_pio.cpp index 499fdbec09..4a213966cf 100644 --- a/esphome/components/dallas_pio/dallas_pio.cpp +++ b/esphome/components/dallas_pio/dallas_pio.cpp @@ -123,6 +123,11 @@ bool DallasPio::ds2413_get_state_(uint8_t &state) { results = this->bus_->read8(); } ok = (~results & 0x0F) == (results >> 4); + if (!ok) { + ESP_LOGW(TAG, "One-Wire checksum error."); + this->status_set_warning(); + return false; + } // ESP_LOGD(TAG, "results1=%02x", results); results &= 0x0F; // ESP_LOGD(TAG, "results2=%02x", results); @@ -255,7 +260,7 @@ bool DallasPio::ds2406_get_state_(uint8_t &state, bool use_crc = false) { } if (use_crc) { ESP_LOGD(TAG, "CRC for Channel Info Byte: 0x%04X", use_crc); - if (!this->ds2406_verify_crc_(channel_control_byte_1, channel_control_byte_2, channel_info_byte, use_crc)) { + if (!this->ds2406_verify_crc_(channel_control_byte_1, channel_control_byte_2, channel_info_byte, received_crc)) { ESP_LOGW(TAG, "CRC verification failed!"); this->status_set_warning(); return false; @@ -273,6 +278,16 @@ bool DallasPio::ds2406_get_state_(uint8_t &state, bool use_crc = false) { bool pio_activity_latch; const bool has_channel_b = channel_info_byte & 0x40; const bool has_supply = channel_info_byte & 0x80; + if (!has_supply) { + ESP_LOGW(TAG, "DS2406 has no supply"); + this->status_set_warning(); + return false; + } + if ((this->pin_ == 0x02) && (!has_channel_b)) { + ESP_LOGW(TAG, "DS2406 has no channel PIOB"); + this->status_set_warning(); + return false; + } switch (this->pin_) { case 0x01: // PIOA pio_flipflop = channel_info_byte & 0x01; diff --git a/esphome/components/dallas_pio/switch.cpp b/esphome/components/dallas_pio/switch.cpp index db7c07f4e9..02e48bf14a 100644 --- a/esphome/components/dallas_pio/switch.cpp +++ b/esphome/components/dallas_pio/switch.cpp @@ -67,12 +67,6 @@ void DallasPioSwitch::write_state(bool state) { if (!this->dallas_pio_->write_state(state, this->pin_, this->pin_inverted_)) { return; } - } else if (this->reference_ == "DS2406") { - // Action pour DS2406 - } else if (this->reference_ == "DS2408") { - // Action pour DS2408 - } else { - // Action par défaut } this->publish_state(state); // Set state in ESPHome }