Add state_class total (#3608)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Peter Galantha 2022-08-10 19:00:09 -07:00 committed by Jesse Hills
parent 4759b4fe2e
commit 7f41b7cd93
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
7 changed files with 11 additions and 0 deletions

View File

@ -473,6 +473,7 @@ enum SensorStateClass {
STATE_CLASS_NONE = 0; STATE_CLASS_NONE = 0;
STATE_CLASS_MEASUREMENT = 1; STATE_CLASS_MEASUREMENT = 1;
STATE_CLASS_TOTAL_INCREASING = 2; STATE_CLASS_TOTAL_INCREASING = 2;
STATE_CLASS_TOTAL = 3;
} }
enum SensorLastResetType { enum SensorLastResetType {

View File

@ -108,6 +108,8 @@ template<> const char *proto_enum_to_string<enums::SensorStateClass>(enums::Sens
return "STATE_CLASS_MEASUREMENT"; return "STATE_CLASS_MEASUREMENT";
case enums::STATE_CLASS_TOTAL_INCREASING: case enums::STATE_CLASS_TOTAL_INCREASING:
return "STATE_CLASS_TOTAL_INCREASING"; return "STATE_CLASS_TOTAL_INCREASING";
case enums::STATE_CLASS_TOTAL:
return "STATE_CLASS_TOTAL";
default: default:
return "UNKNOWN"; return "UNKNOWN";
} }

View File

@ -53,6 +53,7 @@ enum SensorStateClass : uint32_t {
STATE_CLASS_NONE = 0, STATE_CLASS_NONE = 0,
STATE_CLASS_MEASUREMENT = 1, STATE_CLASS_MEASUREMENT = 1,
STATE_CLASS_TOTAL_INCREASING = 2, STATE_CLASS_TOTAL_INCREASING = 2,
STATE_CLASS_TOTAL = 3,
}; };
enum SensorLastResetType : uint32_t { enum SensorLastResetType : uint32_t {
LAST_RESET_NONE = 0, LAST_RESET_NONE = 0,

View File

@ -109,6 +109,7 @@ STATE_CLASSES = {
"": StateClasses.STATE_CLASS_NONE, "": StateClasses.STATE_CLASS_NONE,
"measurement": StateClasses.STATE_CLASS_MEASUREMENT, "measurement": StateClasses.STATE_CLASS_MEASUREMENT,
"total_increasing": StateClasses.STATE_CLASS_TOTAL_INCREASING, "total_increasing": StateClasses.STATE_CLASS_TOTAL_INCREASING,
"total": StateClasses.STATE_CLASS_TOTAL,
} }
validate_state_class = cv.enum(STATE_CLASSES, lower=True, space="_") validate_state_class = cv.enum(STATE_CLASSES, lower=True, space="_")

View File

@ -12,6 +12,8 @@ std::string state_class_to_string(StateClass state_class) {
return "measurement"; return "measurement";
case STATE_CLASS_TOTAL_INCREASING: case STATE_CLASS_TOTAL_INCREASING:
return "total_increasing"; return "total_increasing";
case STATE_CLASS_TOTAL:
return "total";
case STATE_CLASS_NONE: case STATE_CLASS_NONE:
default: default:
return ""; return "";

View File

@ -36,6 +36,7 @@ enum StateClass : uint8_t {
STATE_CLASS_NONE = 0, STATE_CLASS_NONE = 0,
STATE_CLASS_MEASUREMENT = 1, STATE_CLASS_MEASUREMENT = 1,
STATE_CLASS_TOTAL_INCREASING = 2, STATE_CLASS_TOTAL_INCREASING = 2,
STATE_CLASS_TOTAL = 3,
}; };
std::string state_class_to_string(StateClass state_class); std::string state_class_to_string(StateClass state_class);

View File

@ -956,6 +956,9 @@ STATE_CLASS_MEASUREMENT = "measurement"
# The state represents a total that only increases, a decrease is considered a reset. # The state represents a total that only increases, a decrease is considered a reset.
STATE_CLASS_TOTAL_INCREASING = "total_increasing" STATE_CLASS_TOTAL_INCREASING = "total_increasing"
# The state represents a total amount that can both increase and decrease, e.g. a net energy meter.
STATE_CLASS_TOTAL = "total"
KEY_CORE = "core" KEY_CORE = "core"
KEY_TARGET_PLATFORM = "target_platform" KEY_TARGET_PLATFORM = "target_platform"
KEY_TARGET_FRAMEWORK = "target_framework" KEY_TARGET_FRAMEWORK = "target_framework"