1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-16 10:12:21 +01:00

Keep Unit of Measurement in Flash. (#4719)

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Fabian
2023-05-10 01:42:55 +02:00
committed by GitHub
parent 3c05ae4e1a
commit 535003014b
6 changed files with 22 additions and 33 deletions

View File

@@ -22,15 +22,6 @@ std::string state_class_to_string(StateClass state_class) {
Sensor::Sensor() : state(NAN), raw_state(NAN) {}
std::string Sensor::get_unit_of_measurement() {
if (this->unit_of_measurement_.has_value())
return *this->unit_of_measurement_;
return "";
}
void Sensor::set_unit_of_measurement(const std::string &unit_of_measurement) {
this->unit_of_measurement_ = unit_of_measurement;
}
int8_t Sensor::get_accuracy_decimals() {
if (this->accuracy_decimals_.has_value())
return *this->accuracy_decimals_;

View File

@@ -54,15 +54,10 @@ std::string state_class_to_string(StateClass state_class);
*
* A sensor has unit of measurement and can use publish_state to send out a new value with the specified accuracy.
*/
class Sensor : public EntityBase, public EntityBase_DeviceClass {
class Sensor : public EntityBase, public EntityBase_DeviceClass, public EntityBase_UnitOfMeasurement {
public:
explicit Sensor();
/// Get the unit of measurement, using the manual override if set.
std::string get_unit_of_measurement();
/// Manually set the unit of measurement.
void set_unit_of_measurement(const std::string &unit_of_measurement);
/// Get the accuracy in decimals, using the manual override if set.
int8_t get_accuracy_decimals();
/// Manually set the accuracy in decimals.
@@ -158,7 +153,6 @@ class Sensor : public EntityBase, public EntityBase_DeviceClass {
Filter *filter_list_{nullptr}; ///< Store all active filters.
optional<std::string> unit_of_measurement_; ///< Unit of measurement override
optional<int8_t> accuracy_decimals_; ///< Accuracy in decimals override
optional<StateClass> state_class_{STATE_CLASS_NONE}; ///< State class override
bool force_update_{false}; ///< Force update mode