mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Merge branch 'state_class_to_string_flash' into memory_api
This commit is contained in:
		| @@ -44,7 +44,7 @@ ErrorCode I2CDevice::write_register(uint8_t a_register, const uint8_t *data, siz | ||||
|  | ||||
|   buffer[0] = a_register; | ||||
|   std::copy(data, data + len, buffer + 1); | ||||
|   return bus_->write_readv(this->address_, buffer, len + 1, nullptr, 0); | ||||
|   return this->bus_->write_readv(this->address_, buffer, len + 1, nullptr, 0); | ||||
| } | ||||
|  | ||||
| ErrorCode I2CDevice::write_register16(uint16_t a_register, const uint8_t *data, size_t len) const { | ||||
| @@ -54,7 +54,7 @@ ErrorCode I2CDevice::write_register16(uint16_t a_register, const uint8_t *data, | ||||
|   buffer[0] = a_register >> 8; | ||||
|   buffer[1] = a_register; | ||||
|   std::copy(data, data + len, buffer + 2); | ||||
|   return bus_->write_readv(this->address_, buffer, len + 2, nullptr, 0); | ||||
|   return this->bus_->write_readv(this->address_, buffer, len + 2, nullptr, 0); | ||||
| } | ||||
|  | ||||
| bool I2CDevice::read_bytes_16(uint8_t a_register, uint16_t *data, uint8_t len) { | ||||
|   | ||||
| @@ -16,10 +16,10 @@ template<size_t STACK_SIZE> class SmallBufferWithHeapFallback { | ||||
|  public: | ||||
|   uint8_t *get(size_t size) { | ||||
|     if (size <= STACK_SIZE) { | ||||
|       return stack_buffer_; | ||||
|       return this->stack_buffer_; | ||||
|     } | ||||
|     heap_buffer_ = std::unique_ptr<uint8_t[]>(new uint8_t[size]); | ||||
|     return heap_buffer_.get(); | ||||
|     this->heap_buffer_ = std::unique_ptr<uint8_t[]>(new uint8_t[size]); | ||||
|     return this->heap_buffer_.get(); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   | ||||
| @@ -58,8 +58,13 @@ void MQTTSensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCon | ||||
|   if (this->sensor_->get_force_update()) | ||||
|     root[MQTT_FORCE_UPDATE] = true; | ||||
|  | ||||
|   if (this->sensor_->get_state_class() != STATE_CLASS_NONE) | ||||
|   if (this->sensor_->get_state_class() != STATE_CLASS_NONE) { | ||||
| #ifdef USE_STORE_LOG_STR_IN_FLASH | ||||
|     root[MQTT_STATE_CLASS] = (const __FlashStringHelper *) state_class_to_string(this->sensor_->get_state_class()); | ||||
| #else | ||||
|     root[MQTT_STATE_CLASS] = state_class_to_string(this->sensor_->get_state_class()); | ||||
| #endif | ||||
|   } | ||||
|  | ||||
|   config.command_topic = false; | ||||
| } | ||||
|   | ||||
| @@ -38,6 +38,7 @@ void SEN5XComponent::setup() { | ||||
|       this->mark_failed(); | ||||
|       return; | ||||
|     } | ||||
|     delay(20);  // per datasheet | ||||
|  | ||||
|     uint16_t raw_read_status; | ||||
|     if (!this->read_data(raw_read_status)) { | ||||
|   | ||||
| @@ -17,7 +17,8 @@ void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *o | ||||
|                 "%s  State Class: '%s'\n" | ||||
|                 "%s  Unit of Measurement: '%s'\n" | ||||
|                 "%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, | ||||
|                 LOG_STR_ARG(state_class_to_string(obj->get_state_class())), prefix, | ||||
|                 obj->get_unit_of_measurement_ref().c_str(), prefix, obj->get_accuracy_decimals()); | ||||
|  | ||||
|   if (!obj->get_device_class_ref().empty()) { | ||||
| @@ -33,17 +34,17 @@ void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *o | ||||
|   } | ||||
| } | ||||
|  | ||||
| const char *state_class_to_string(StateClass state_class) { | ||||
| const LogString *state_class_to_string(StateClass state_class) { | ||||
|   switch (state_class) { | ||||
|     case STATE_CLASS_MEASUREMENT: | ||||
|       return "measurement"; | ||||
|       return LOG_STR("measurement"); | ||||
|     case STATE_CLASS_TOTAL_INCREASING: | ||||
|       return "total_increasing"; | ||||
|       return LOG_STR("total_increasing"); | ||||
|     case STATE_CLASS_TOTAL: | ||||
|       return "total"; | ||||
|       return LOG_STR("total"); | ||||
|     case STATE_CLASS_NONE: | ||||
|     default: | ||||
|       return ""; | ||||
|       return LOG_STR(""); | ||||
|   } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -33,7 +33,7 @@ enum StateClass : uint8_t { | ||||
|   STATE_CLASS_TOTAL = 3, | ||||
| }; | ||||
|  | ||||
| const char *state_class_to_string(StateClass state_class); | ||||
| const LogString *state_class_to_string(StateClass state_class); | ||||
|  | ||||
| /** Base-class for all sensors. | ||||
|  * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user