Refactor SEN0590Component setup and update methods for improved readability and maintainability, while preserving functionality.

This commit is contained in:
sredfern committed 2025-05-05 22:41:46 +10:00
1 parent ec18b8c223
commit 966ce1f25d
1 file changed
+3 -6
+3 -6
View File
@@ -14,9 +14,7 @@ static const uint8_t DATA_REG_HIGH = 0x01;
static const uint8_t DATA_REG_LOW = 0x02; static const uint8_t DATA_REG_LOW = 0x02;
static const uint8_t MEASURE_COMMAND = 0xB0; static const uint8_t MEASURE_COMMAND = 0xB0;
class SEN0590Component : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice { void SEN0590Component::setup() {
public:
void setup() override {
ESP_LOGD(TAG, "Setting up SEN0590 laser distance sensor..."); ESP_LOGD(TAG, "Setting up SEN0590 laser distance sensor...");
if (!this->write_byte(COMMAND_REG, 0x00)) { if (!this->write_byte(COMMAND_REG, 0x00)) {
ESP_LOGE(TAG, "SEN0590 not responding. Check wiring and address."); ESP_LOGE(TAG, "SEN0590 not responding. Check wiring and address.");
@@ -26,7 +24,7 @@ class SEN0590Component : public sensor::Sensor, public PollingComponent, public
ESP_LOGD(TAG, "SEN0590 Setup complete."); ESP_LOGD(TAG, "SEN0590 Setup complete.");
} }
void update() override { void SEN0590Component::update() {
if (!this->write_byte(COMMAND_REG, MEASURE_COMMAND)) { if (!this->write_byte(COMMAND_REG, MEASURE_COMMAND)) {
ESP_LOGW(TAG, "Failed to send measurement command"); ESP_LOGW(TAG, "Failed to send measurement command");
this->status_set_warning(); this->status_set_warning();
@@ -57,8 +55,7 @@ class SEN0590Component : public sensor::Sensor, public PollingComponent, public
this->status_clear_warning(); this->status_clear_warning();
} }
float get_setup_priority() const override { return setup_priority::DATA; } float SEN0590Component::get_setup_priority() const { return setup_priority::DATA; }
};
} // namespace sen0590 } // namespace sen0590
} // namespace esphome } // namespace esphome