mirror of
https://github.com/esphome/esphome.git
synced 2025-09-05 04:42:21 +01:00
Device class attribute for sensor component (#1525)
* Add constants for sensor device_class * Add device_class attribute to sensor component * Add device_class attribute to sensor class * Add device_class to mhz19 temperature sensor * Add device_class to sensor in api component * Add test for device_class of sensor * Rename DEVICE_CLASS_NONE to DEVICE_CLASS_EMPTY for consistency * Make optional attributes of sensor component truly optional
This commit is contained in:
@@ -1494,6 +1494,10 @@ bool ListEntitiesSensorResponse::decode_length(uint32_t field_id, ProtoLengthDel
|
||||
this->unit_of_measurement = value.as_string();
|
||||
return true;
|
||||
}
|
||||
case 9: {
|
||||
this->device_class = value.as_string();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -1517,6 +1521,7 @@ void ListEntitiesSensorResponse::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_string(6, this->unit_of_measurement);
|
||||
buffer.encode_int32(7, this->accuracy_decimals);
|
||||
buffer.encode_bool(8, this->force_update);
|
||||
buffer.encode_string(9, this->device_class);
|
||||
}
|
||||
void ListEntitiesSensorResponse::dump_to(std::string &out) const {
|
||||
char buffer[64];
|
||||
@@ -1554,6 +1559,10 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const {
|
||||
out.append(" force_update: ");
|
||||
out.append(YESNO(this->force_update));
|
||||
out.append("\n");
|
||||
|
||||
out.append(" device_class: ");
|
||||
out.append("'").append(this->device_class).append("'");
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
}
|
||||
bool SensorStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
|
Reference in New Issue
Block a user