Add support for Sensor state class (#33)

This commit is contained in:
Franck Nijhof 2021-05-25 23:39:01 +02:00 committed by GitHub
parent 23ac74da4d
commit a6a25d88b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 123 additions and 78 deletions

View File

@ -409,6 +409,11 @@ message LightCommandRequest {
} }
// ==================== SENSOR ==================== // ==================== SENSOR ====================
enum SensorStateClass {
STATE_CLASS_NONE = 0;
STATE_CLASS_MEASUREMENT = 1;
}
message ListEntitiesSensorResponse { message ListEntitiesSensorResponse {
option (id) = 16; option (id) = 16;
option (source) = SOURCE_SERVER; option (source) = SOURCE_SERVER;
@ -424,6 +429,7 @@ message ListEntitiesSensorResponse {
int32 accuracy_decimals = 7; int32 accuracy_decimals = 7;
bool force_update = 8; bool force_update = 8;
string device_class = 9; string device_class = 9;
SensorStateClass state_class = 10;
} }
message SensorStateResponse { message SensorStateResponse {
option (id) = 25; option (id) = 25;

File diff suppressed because one or more lines are too long

View File

@ -148,6 +148,10 @@ class LightState(EntityState):
# ==================== SENSOR ==================== # ==================== SENSOR ====================
class SensorStateClass(enum.IntEnum):
NONE = 0
MEASUREMENT = 1
@attr.s @attr.s
class SensorInfo(EntityInfo): class SensorInfo(EntityInfo):
icon = attr.ib(type=str, default='') icon = attr.ib(type=str, default='')
@ -155,6 +159,7 @@ class SensorInfo(EntityInfo):
unit_of_measurement = attr.ib(type=str, default='') unit_of_measurement = attr.ib(type=str, default='')
accuracy_decimals = attr.ib(type=int, default=0) accuracy_decimals = attr.ib(type=int, default=0)
force_update = attr.ib(type=bool, default=False) force_update = attr.ib(type=bool, default=False)
state_class = attr.ib(type=SensorStateClass, converter=SensorStateClass, default=SensorStateClass.NONE)
@attr.s @attr.s