mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	[pmwcs3] Optimize logging (#8936)
This commit is contained in:
		| @@ -26,33 +26,31 @@ static const char *const TAG = "pmwcs3"; | |||||||
| void PMWCS3Component::new_i2c_address(uint8_t address) { | void PMWCS3Component::new_i2c_address(uint8_t address) { | ||||||
|   if (!this->write_byte(PMWCS3_SET_I2C_ADDRESS, address)) { |   if (!this->write_byte(PMWCS3_SET_I2C_ADDRESS, address)) { | ||||||
|     this->status_set_warning(); |     this->status_set_warning(); | ||||||
|     ESP_LOGW(TAG, "couldn't write the new I2C address %d", address); |     ESP_LOGW(TAG, "Setting I2C address failed (%d)", address); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   this->set_i2c_address(address);  // Allows device to continue working until new firmware is written with new address. |   this->set_i2c_address(address);  // Allows device to continue working until new firmware is written with new address. | ||||||
|   ESP_LOGVV(TAG, "changed I2C address to %d", address); |   ESP_LOGVV(TAG, "Set I2C address to %d", address); | ||||||
|   this->status_clear_warning(); |   this->status_clear_warning(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void PMWCS3Component::air_calibration() { | void PMWCS3Component::air_calibration() { | ||||||
|   if (!this->write_bytes(PMWCS3_REG_CALIBRATE_AIR, nullptr, 0)) { |   if (!this->write_bytes(PMWCS3_REG_CALIBRATE_AIR, nullptr, 0)) { | ||||||
|     this->status_set_warning(); |     this->status_set_warning(); | ||||||
|     ESP_LOGW(TAG, "couldn't start air calibration"); |     ESP_LOGW(TAG, "Starting air calibration failed"); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   ESP_LOGW(TAG, "Start air calibration during the next 300s"); |   ESP_LOGW(TAG, "Running air calibration for 300s"); | ||||||
| } | } | ||||||
| void PMWCS3Component::water_calibration() { | void PMWCS3Component::water_calibration() { | ||||||
|   if (!this->write_bytes(PMWCS3_REG_CALIBRATE_WATER, nullptr, 0)) { |   if (!this->write_bytes(PMWCS3_REG_CALIBRATE_WATER, nullptr, 0)) { | ||||||
|     this->status_set_warning(); |     this->status_set_warning(); | ||||||
|     ESP_LOGW(TAG, "couldn't start water calibration"); |     ESP_LOGW(TAG, "Starting water calibration failed"); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   ESP_LOGW(TAG, "Start water calibration during the next 300s"); |   ESP_LOGW(TAG, "Running water calibration for 300s"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void PMWCS3Component::setup() { ESP_LOGCONFIG(TAG, "Running setup"); } |  | ||||||
|  |  | ||||||
| void PMWCS3Component::update() { this->read_data_(); } | void PMWCS3Component::update() { this->read_data_(); } | ||||||
|  |  | ||||||
| float PMWCS3Component::get_setup_priority() const { return setup_priority::DATA; } | float PMWCS3Component::get_setup_priority() const { return setup_priority::DATA; } | ||||||
| @@ -61,10 +59,8 @@ void PMWCS3Component::dump_config() { | |||||||
|   ESP_LOGCONFIG(TAG, "PMWCS3"); |   ESP_LOGCONFIG(TAG, "PMWCS3"); | ||||||
|   LOG_I2C_DEVICE(this); |   LOG_I2C_DEVICE(this); | ||||||
|   if (this->is_failed()) { |   if (this->is_failed()) { | ||||||
|     ESP_LOGE(TAG, "Communication with PMWCS3 failed!"); |     ESP_LOGE(TAG, "Communication failed"); | ||||||
|   } |   } | ||||||
|   ESP_LOGI(TAG, "%s", this->is_failed() ? "FAILED" : "OK"); |  | ||||||
|  |  | ||||||
|   LOG_UPDATE_INTERVAL(this); |   LOG_UPDATE_INTERVAL(this); | ||||||
|   LOG_SENSOR("  ", "e25", this->e25_sensor_); |   LOG_SENSOR("  ", "e25", this->e25_sensor_); | ||||||
|   LOG_SENSOR("  ", "ec", this->ec_sensor_); |   LOG_SENSOR("  ", "ec", this->ec_sensor_); | ||||||
| @@ -75,7 +71,7 @@ void PMWCS3Component::read_data_() { | |||||||
|   /////// Super important !!!! first activate reading PMWCS3_REG_READ_START (if not, return always the same values) //// |   /////// Super important !!!! first activate reading PMWCS3_REG_READ_START (if not, return always the same values) //// | ||||||
|   if (!this->write_bytes(PMWCS3_REG_READ_START, nullptr, 0)) { |   if (!this->write_bytes(PMWCS3_REG_READ_START, nullptr, 0)) { | ||||||
|     this->status_set_warning(); |     this->status_set_warning(); | ||||||
|     ESP_LOGVV(TAG, "Failed to write into REG_READ_START register !!!"); |     ESP_LOGVV(TAG, "Writing REG_READ_START failed"); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -85,7 +81,7 @@ void PMWCS3Component::read_data_() { | |||||||
|     uint8_t data[8]; |     uint8_t data[8]; | ||||||
|     float e25, ec, temperature, vwc; |     float e25, ec, temperature, vwc; | ||||||
|     if (!this->read_bytes(PMWCS3_REG_GET_DATA, (uint8_t *) &data, 8)) { |     if (!this->read_bytes(PMWCS3_REG_GET_DATA, (uint8_t *) &data, 8)) { | ||||||
|       ESP_LOGVV(TAG, "Error reading PMWCS3_REG_GET_DATA registers"); |       ESP_LOGVV(TAG, "Reading PMWCS3_REG_GET_DATA failed"); | ||||||
|       this->mark_failed(); |       this->mark_failed(); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -12,7 +12,6 @@ namespace pmwcs3 { | |||||||
|  |  | ||||||
| class PMWCS3Component : public PollingComponent, public i2c::I2CDevice { | class PMWCS3Component : public PollingComponent, public i2c::I2CDevice { | ||||||
|  public: |  public: | ||||||
|   void setup() override; |  | ||||||
|   void update() override; |   void update() override; | ||||||
|   void dump_config() override; |   void dump_config() override; | ||||||
|   float get_setup_priority() const override; |   float get_setup_priority() const override; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user