ESPHome  2022.9.1
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 } // namespace number
20 } // namespace esphome
std::string get_unit_of_measurement()
Get the unit of measurement, using the manual override if set.
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
optional< std::string > unit_of_measurement_
Unit of measurement override.
Definition: number_traits.h:39