mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 00:05:43 +00:00
Clean-up sensor integration (#2275)
This commit is contained in:
@@ -31,16 +31,9 @@ void MQTTSensorComponent::dump_config() {
|
||||
std::string MQTTSensorComponent::component_type() const { return "sensor"; }
|
||||
|
||||
uint32_t MQTTSensorComponent::get_expire_after() const {
|
||||
if (this->expire_after_.has_value()) {
|
||||
if (this->expire_after_.has_value())
|
||||
return *this->expire_after_;
|
||||
} else {
|
||||
#ifdef USE_DEEP_SLEEP
|
||||
if (deep_sleep::global_has_deep_sleep) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return this->sensor_->calculate_expected_filter_update_interval() * 5;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void MQTTSensorComponent::set_expire_after(uint32_t expire_after) { this->expire_after_ = expire_after; }
|
||||
void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
|
||||
@@ -61,8 +54,8 @@ void MQTTSensorComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryCo
|
||||
if (this->sensor_->get_force_update())
|
||||
root["force_update"] = true;
|
||||
|
||||
if (this->sensor_->state_class != STATE_CLASS_NONE)
|
||||
root["state_class"] = state_class_to_string(this->sensor_->state_class);
|
||||
if (this->sensor_->get_state_class() != STATE_CLASS_NONE)
|
||||
root["state_class"] = state_class_to_string(this->sensor_->get_state_class());
|
||||
|
||||
config.command_topic = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user