mirror of
https://github.com/esphome/esphome.git
synced 2025-11-20 08:46:01 +00:00
Adding last_reset_type to sensors that should support it. (#2039)
This commit is contained in:
@@ -16,6 +16,18 @@ const char *state_class_to_string(StateClass state_class) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *last_reset_type_to_string(LastResetType last_reset_type) {
|
||||
switch (last_reset_type) {
|
||||
case LAST_RESET_TYPE_NEVER:
|
||||
return "never";
|
||||
case LAST_RESET_TYPE_AUTO:
|
||||
return "auto";
|
||||
case LAST_RESET_TYPE_NONE:
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void Sensor::publish_state(float state) {
|
||||
this->raw_state = state;
|
||||
this->raw_callback_.call(state);
|
||||
@@ -64,6 +76,7 @@ void Sensor::set_state_class(const std::string &state_class) {
|
||||
ESP_LOGW(TAG, "'%s' - Unrecognized state class %s", this->get_name().c_str(), state_class.c_str());
|
||||
}
|
||||
}
|
||||
void Sensor::set_last_reset_type(LastResetType last_reset_type) { this->last_reset_type = last_reset_type; }
|
||||
std::string Sensor::get_unit_of_measurement() {
|
||||
if (this->unit_of_measurement_.has_value())
|
||||
return *this->unit_of_measurement_;
|
||||
|
||||
Reference in New Issue
Block a user