mirror of
https://github.com/esphome/esphome.git
synced 2025-11-18 15:55:46 +00:00
[core] Deprecate get_icon(), get_device_class(), get_unit_of_measurement() and fix remaining non-MQTT usages (#11732)
This commit is contained in:
@@ -235,7 +235,7 @@ void GraphLegend::init(Graph *g) {
|
|||||||
std::string valstr =
|
std::string valstr =
|
||||||
value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals());
|
value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals());
|
||||||
if (this->units_) {
|
if (this->units_) {
|
||||||
valstr += trace->sensor_->get_unit_of_measurement();
|
valstr += trace->sensor_->get_unit_of_measurement_ref();
|
||||||
}
|
}
|
||||||
this->font_value_->measure(valstr.c_str(), &fw, &fos, &fbl, &fh);
|
this->font_value_->measure(valstr.c_str(), &fw, &fos, &fbl, &fh);
|
||||||
if (fw > valw)
|
if (fw > valw)
|
||||||
@@ -371,7 +371,7 @@ void Graph::draw_legend(display::Display *buff, uint16_t x_offset, uint16_t y_of
|
|||||||
std::string valstr =
|
std::string valstr =
|
||||||
value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals());
|
value_accuracy_to_string(trace->sensor_->get_state(), trace->sensor_->get_accuracy_decimals());
|
||||||
if (legend_->units_) {
|
if (legend_->units_) {
|
||||||
valstr += trace->sensor_->get_unit_of_measurement();
|
valstr += trace->sensor_->get_unit_of_measurement_ref();
|
||||||
}
|
}
|
||||||
buff->printf(xv, yv, legend_->font_value_, trace->get_line_color(), TextAlign::TOP_CENTER, "%s", valstr.c_str());
|
buff->printf(xv, yv, legend_->font_value_, trace->get_line_color(), TextAlign::TOP_CENTER, "%s", valstr.c_str());
|
||||||
ESP_LOGV(TAG, " value: %s", valstr.c_str());
|
ESP_LOGV(TAG, " value: %s", valstr.c_str());
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ void PrometheusHandler::sensor_row_(AsyncResponseStream *stream, sensor::Sensor
|
|||||||
stream->print(ESPHOME_F("\",name=\""));
|
stream->print(ESPHOME_F("\",name=\""));
|
||||||
stream->print(relabel_name_(obj).c_str());
|
stream->print(relabel_name_(obj).c_str());
|
||||||
stream->print(ESPHOME_F("\",unit=\""));
|
stream->print(ESPHOME_F("\",unit=\""));
|
||||||
stream->print(obj->get_unit_of_measurement().c_str());
|
stream->print(obj->get_unit_of_measurement_ref().c_str());
|
||||||
stream->print(ESPHOME_F("\"} "));
|
stream->print(ESPHOME_F("\"} "));
|
||||||
stream->print(value_accuracy_to_string(obj->state, obj->get_accuracy_decimals()).c_str());
|
stream->print(value_accuracy_to_string(obj->state, obj->get_accuracy_decimals()).c_str());
|
||||||
stream->print(ESPHOME_F("\n"));
|
stream->print(ESPHOME_F("\n"));
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ void Sprinkler::set_valve_run_duration(const optional<size_t> valve_number, cons
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto call = this->valve_[valve_number.value()].run_duration_number->make_call();
|
auto call = this->valve_[valve_number.value()].run_duration_number->make_call();
|
||||||
if (this->valve_[valve_number.value()].run_duration_number->traits.get_unit_of_measurement() == MIN_STR) {
|
if (this->valve_[valve_number.value()].run_duration_number->traits.get_unit_of_measurement_ref() == MIN_STR) {
|
||||||
call.set_value(run_duration.value() / 60.0);
|
call.set_value(run_duration.value() / 60.0);
|
||||||
} else {
|
} else {
|
||||||
call.set_value(run_duration.value());
|
call.set_value(run_duration.value());
|
||||||
@@ -732,7 +732,7 @@ uint32_t Sprinkler::valve_run_duration(const size_t valve_number) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (this->valve_[valve_number].run_duration_number != nullptr) {
|
if (this->valve_[valve_number].run_duration_number != nullptr) {
|
||||||
if (this->valve_[valve_number].run_duration_number->traits.get_unit_of_measurement() == MIN_STR) {
|
if (this->valve_[valve_number].run_duration_number->traits.get_unit_of_measurement_ref() == MIN_STR) {
|
||||||
return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state * 60));
|
return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state * 60));
|
||||||
} else {
|
} else {
|
||||||
return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state));
|
return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state));
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ class EntityBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get/set this entity's icon
|
// Get/set this entity's icon
|
||||||
std::string get_icon() const;
|
[[deprecated("Use get_icon_ref() instead for better performance (avoids string copy). Will stop working in ESPHome "
|
||||||
|
"2026.5.0")]] std::string
|
||||||
|
get_icon() const;
|
||||||
void set_icon(const char *icon);
|
void set_icon(const char *icon);
|
||||||
StringRef get_icon_ref() const {
|
StringRef get_icon_ref() const {
|
||||||
static constexpr auto EMPTY_STRING = StringRef::from_lit("");
|
static constexpr auto EMPTY_STRING = StringRef::from_lit("");
|
||||||
@@ -158,7 +160,9 @@ class EntityBase {
|
|||||||
class EntityBase_DeviceClass { // NOLINT(readability-identifier-naming)
|
class EntityBase_DeviceClass { // NOLINT(readability-identifier-naming)
|
||||||
public:
|
public:
|
||||||
/// Get the device class, using the manual override if set.
|
/// Get the device class, using the manual override if set.
|
||||||
std::string get_device_class();
|
[[deprecated("Use get_device_class_ref() instead for better performance (avoids string copy). Will stop working in "
|
||||||
|
"ESPHome 2026.5.0")]] std::string
|
||||||
|
get_device_class();
|
||||||
/// Manually set the device class.
|
/// Manually set the device class.
|
||||||
void set_device_class(const char *device_class);
|
void set_device_class(const char *device_class);
|
||||||
/// Get the device class as StringRef
|
/// Get the device class as StringRef
|
||||||
@@ -174,7 +178,9 @@ class EntityBase_DeviceClass { // NOLINT(readability-identifier-naming)
|
|||||||
class EntityBase_UnitOfMeasurement { // NOLINT(readability-identifier-naming)
|
class EntityBase_UnitOfMeasurement { // NOLINT(readability-identifier-naming)
|
||||||
public:
|
public:
|
||||||
/// Get the unit of measurement, using the manual override if set.
|
/// Get the unit of measurement, using the manual override if set.
|
||||||
std::string get_unit_of_measurement();
|
[[deprecated("Use get_unit_of_measurement_ref() instead for better performance (avoids string copy). Will stop "
|
||||||
|
"working in ESPHome 2026.5.0")]] std::string
|
||||||
|
get_unit_of_measurement();
|
||||||
/// Manually set the unit of measurement.
|
/// Manually set the unit of measurement.
|
||||||
void set_unit_of_measurement(const char *unit_of_measurement);
|
void set_unit_of_measurement(const char *unit_of_measurement);
|
||||||
/// Get the unit of measurement as StringRef
|
/// Get the unit of measurement as StringRef
|
||||||
|
|||||||
Reference in New Issue
Block a user