mirror of
https://github.com/esphome/esphome.git
synced 2025-11-20 08:46:01 +00: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:
@@ -40,6 +40,13 @@ std::string Sensor::get_icon() {
|
||||
return *this->icon_;
|
||||
return this->icon();
|
||||
}
|
||||
void Sensor::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
|
||||
std::string Sensor::get_device_class() {
|
||||
if (this->device_class_.has_value())
|
||||
return *this->device_class_;
|
||||
return this->device_class();
|
||||
}
|
||||
std::string Sensor::device_class() { return ""; }
|
||||
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