mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Only give error for connected sensors at startup (#6474)
Co-authored-by: Leo Schelvis <LSchelvis@dela.org>
This commit is contained in:
parent
522b43bb41
commit
e5e8bc8515
2 changed files with 16 additions and 3 deletions
|
@ -60,7 +60,7 @@ void DallasComponent::setup() {
|
||||||
for (auto *sensor : this->sensors_) {
|
for (auto *sensor : this->sensors_) {
|
||||||
if (sensor->get_index().has_value()) {
|
if (sensor->get_index().has_value()) {
|
||||||
if (*sensor->get_index() >= this->found_sensors_.size()) {
|
if (*sensor->get_index() >= this->found_sensors_.size()) {
|
||||||
this->status_set_error();
|
this->status_set_error("Sensor configured by index but not found");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sensor->set_address(this->found_sensors_[*sensor->get_index()]);
|
sensor->set_address(this->found_sensors_[*sensor->get_index()]);
|
||||||
|
@ -109,8 +109,12 @@ void DallasComponent::update() {
|
||||||
result = this->one_wire_->reset();
|
result = this->one_wire_->reset();
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
if (!this->found_sensors_.empty()) {
|
||||||
|
// Only log error if at the start sensors were found (and thus are disconnected during uptime)
|
||||||
ESP_LOGE(TAG, "Requesting conversion failed");
|
ESP_LOGE(TAG, "Requesting conversion failed");
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
|
}
|
||||||
|
|
||||||
for (auto *sensor : this->sensors_) {
|
for (auto *sensor : this->sensors_) {
|
||||||
sensor->publish_state(NAN);
|
sensor->publish_state(NAN);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +128,12 @@ void DallasComponent::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto *sensor : this->sensors_) {
|
for (auto *sensor : this->sensors_) {
|
||||||
|
if (sensor->get_address() == 0) {
|
||||||
|
ESP_LOGV(TAG, "'%s' - Indexed sensor not found at startup, skipping update", sensor->get_name().c_str());
|
||||||
|
sensor->publish_state(NAN);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
this->set_timeout(sensor->get_address_name(), sensor->millis_to_wait_for_conversion(), [this, sensor] {
|
this->set_timeout(sensor->get_address_name(), sensor->millis_to_wait_for_conversion(), [this, sensor] {
|
||||||
bool res = sensor->read_scratch_pad();
|
bool res = sensor->read_scratch_pad();
|
||||||
|
|
||||||
|
@ -152,6 +162,8 @@ void DallasTemperatureSensor::set_resolution(uint8_t resolution) { this->resolut
|
||||||
optional<uint8_t> DallasTemperatureSensor::get_index() const { return this->index_; }
|
optional<uint8_t> DallasTemperatureSensor::get_index() const { return this->index_; }
|
||||||
void DallasTemperatureSensor::set_index(uint8_t index) { this->index_ = index; }
|
void DallasTemperatureSensor::set_index(uint8_t index) { this->index_ = index; }
|
||||||
uint8_t *DallasTemperatureSensor::get_address8() { return reinterpret_cast<uint8_t *>(&this->address_); }
|
uint8_t *DallasTemperatureSensor::get_address8() { return reinterpret_cast<uint8_t *>(&this->address_); }
|
||||||
|
uint64_t DallasTemperatureSensor::get_address() { return this->address_; }
|
||||||
|
|
||||||
const std::string &DallasTemperatureSensor::get_address_name() {
|
const std::string &DallasTemperatureSensor::get_address_name() {
|
||||||
if (this->address_name_.empty()) {
|
if (this->address_name_.empty()) {
|
||||||
this->address_name_ = std::string("0x") + format_hex(this->address_);
|
this->address_name_ = std::string("0x") + format_hex(this->address_);
|
||||||
|
|
|
@ -37,6 +37,7 @@ class DallasTemperatureSensor : public sensor::Sensor {
|
||||||
void set_parent(DallasComponent *parent) { parent_ = parent; }
|
void set_parent(DallasComponent *parent) { parent_ = parent; }
|
||||||
/// Helper to get a pointer to the address as uint8_t.
|
/// Helper to get a pointer to the address as uint8_t.
|
||||||
uint8_t *get_address8();
|
uint8_t *get_address8();
|
||||||
|
uint64_t get_address();
|
||||||
/// Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29".
|
/// Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29".
|
||||||
const std::string &get_address_name();
|
const std::string &get_address_name();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue