mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	[core] Use get_unit_of_measurement_ref() in entity logging to avoid string allocations (#10532)
This commit is contained in:
		| @@ -18,8 +18,8 @@ void log_number(const char *tag, const char *prefix, const char *type, Number *o | |||||||
|     ESP_LOGCONFIG(tag, "%s  Icon: '%s'", prefix, obj->get_icon_ref().c_str()); |     ESP_LOGCONFIG(tag, "%s  Icon: '%s'", prefix, obj->get_icon_ref().c_str()); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (!obj->traits.get_unit_of_measurement().empty()) { |   if (!obj->traits.get_unit_of_measurement_ref().empty()) { | ||||||
|     ESP_LOGCONFIG(tag, "%s  Unit of Measurement: '%s'", prefix, obj->traits.get_unit_of_measurement().c_str()); |     ESP_LOGCONFIG(tag, "%s  Unit of Measurement: '%s'", prefix, obj->traits.get_unit_of_measurement_ref().c_str()); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (!obj->traits.get_device_class_ref().empty()) { |   if (!obj->traits.get_device_class_ref().empty()) { | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *o | |||||||
|                 "%s  Unit of Measurement: '%s'\n" |                 "%s  Unit of Measurement: '%s'\n" | ||||||
|                 "%s  Accuracy Decimals: %d", |                 "%s  Accuracy Decimals: %d", | ||||||
|                 prefix, type, obj->get_name().c_str(), prefix, state_class_to_string(obj->get_state_class()), prefix, |                 prefix, type, obj->get_name().c_str(), prefix, state_class_to_string(obj->get_state_class()), prefix, | ||||||
|                 obj->get_unit_of_measurement().c_str(), prefix, obj->get_accuracy_decimals()); |                 obj->get_unit_of_measurement_ref().c_str(), prefix, obj->get_accuracy_decimals()); | ||||||
|  |  | ||||||
|   if (!obj->get_device_class_ref().empty()) { |   if (!obj->get_device_class_ref().empty()) { | ||||||
|     ESP_LOGCONFIG(tag, "%s  Device Class: '%s'", prefix, obj->get_device_class_ref().c_str()); |     ESP_LOGCONFIG(tag, "%s  Device Class: '%s'", prefix, obj->get_device_class_ref().c_str()); | ||||||
| @@ -128,7 +128,7 @@ void Sensor::internal_send_state_to_frontend(float state) { | |||||||
|   this->set_has_state(true); |   this->set_has_state(true); | ||||||
|   this->state = state; |   this->state = state; | ||||||
|   ESP_LOGD(TAG, "'%s': Sending state %.5f %s with %d decimals of accuracy", this->get_name().c_str(), state, |   ESP_LOGD(TAG, "'%s': Sending state %.5f %s with %d decimals of accuracy", this->get_name().c_str(), state, | ||||||
|            this->get_unit_of_measurement().c_str(), this->get_accuracy_decimals()); |            this->get_unit_of_measurement_ref().c_str(), this->get_accuracy_decimals()); | ||||||
|   this->callback_.call(state); |   this->callback_.call(state); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user