mirror of
https://github.com/esphome/esphome.git
synced 2025-09-16 18:22:22 +01:00
Add new total_increasing state-class for Home Assistant 2021.9+ (#2166)
This commit is contained in:
@@ -81,6 +81,7 @@ StateClasses = sensor_ns.enum("StateClass")
|
||||
STATE_CLASSES = {
|
||||
"": StateClasses.STATE_CLASS_NONE,
|
||||
"measurement": StateClasses.STATE_CLASS_MEASUREMENT,
|
||||
"total_increasing": StateClasses.STATE_CLASS_TOTAL_INCREASING,
|
||||
}
|
||||
validate_state_class = cv.enum(STATE_CLASSES, lower=True, space="_")
|
||||
|
||||
|
@@ -10,6 +10,8 @@ const char *state_class_to_string(StateClass state_class) {
|
||||
switch (state_class) {
|
||||
case STATE_CLASS_MEASUREMENT:
|
||||
return "measurement";
|
||||
case STATE_CLASS_TOTAL_INCREASING:
|
||||
return "total_increasing";
|
||||
case STATE_CLASS_NONE:
|
||||
default:
|
||||
return "";
|
||||
@@ -72,6 +74,8 @@ void Sensor::set_state_class(StateClass state_class) { this->state_class = state
|
||||
void Sensor::set_state_class(const std::string &state_class) {
|
||||
if (str_equals_case_insensitive(state_class, "measurement")) {
|
||||
this->state_class = STATE_CLASS_MEASUREMENT;
|
||||
} else if (str_equals_case_insensitive(state_class, "total_increasing")) {
|
||||
this->state_class = STATE_CLASS_TOTAL_INCREASING;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "'%s' - Unrecognized state class %s", this->get_name().c_str(), state_class.c_str());
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@ namespace sensor {
|
||||
enum StateClass : uint8_t {
|
||||
STATE_CLASS_NONE = 0,
|
||||
STATE_CLASS_MEASUREMENT = 1,
|
||||
STATE_CLASS_TOTAL_INCREASING = 2,
|
||||
};
|
||||
|
||||
const char *state_class_to_string(StateClass state_class);
|
||||
|
Reference in New Issue
Block a user