ESPHome  2022.12.8
number_traits.cpp
Go to the documentation of this file.
1 #include "esphome/core/log.h"
2 #include "number_traits.h"
3 
4 namespace esphome {
5 namespace number {
6 
7 static const char *const TAG = "number";
8 
9 void NumberTraits::set_unit_of_measurement(const std::string &unit_of_measurement) {
10  this->unit_of_measurement_ = unit_of_measurement;
11 }
12 
14  if (this->unit_of_measurement_.has_value())
15  return *this->unit_of_measurement_;
16  return "";
17 }
18 
19 void NumberTraits::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
20 
22  if (this->device_class_.has_value())
23  return *this->device_class_;
24  return "";
25 }
26 
27 } // namespace number
28 } // namespace esphome
std::string get_unit_of_measurement()
Get the unit of measurement, using the manual override if set.
optional< std::string > device_class_
Definition: number_traits.h:45
bool has_value() const
Definition: optional.h:87
void set_unit_of_measurement(const std::string &unit_of_measurement)
Manually set the unit of measurement.
Definition: a4988.cpp:4
void set_device_class(const std::string &device_class)
optional< std::string > unit_of_measurement_
Unit of measurement override.
Definition: number_traits.h:43