mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Improve OTA error messages adding return codes (#3698)
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							1a524a5a50
						
					
				
				
					commit
					df6830110d
				
			| @@ -49,7 +49,7 @@ OTAResponseTypes IDFOTABackend::end() { | ||||
|   this->md5_.calculate(); | ||||
|   if (!this->md5_.equals_hex(this->expected_bin_md5_)) { | ||||
|     this->abort(); | ||||
|     return OTA_RESPONSE_ERROR_UPDATE_END; | ||||
|     return OTA_RESPONSE_ERROR_MD5_MISMATCH; | ||||
|   } | ||||
|   esp_err_t err = esp_ota_end(this->update_handle_); | ||||
|   this->update_handle_ = 0; | ||||
|   | ||||
| @@ -296,7 +296,7 @@ void OTAComponent::handle_() { | ||||
|  | ||||
|     error_code = backend->write(buf, read); | ||||
|     if (error_code != OTA_RESPONSE_OK) { | ||||
|       ESP_LOGW(TAG, "Error writing binary data to flash!"); | ||||
|       ESP_LOGW(TAG, "Error writing binary data to flash!, error_code: %d", error_code); | ||||
|       goto error;  // NOLINT(cppcoreguidelines-avoid-goto) | ||||
|     } | ||||
|     total += read; | ||||
| @@ -321,7 +321,7 @@ void OTAComponent::handle_() { | ||||
|  | ||||
|   error_code = backend->end(); | ||||
|   if (error_code != OTA_RESPONSE_OK) { | ||||
|     ESP_LOGW(TAG, "Error ending OTA!"); | ||||
|     ESP_LOGW(TAG, "Error ending OTA!, error_code: %d", error_code); | ||||
|     goto error;  // NOLINT(cppcoreguidelines-avoid-goto) | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -32,6 +32,7 @@ enum OTAResponseTypes { | ||||
|   OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136, | ||||
|   OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137, | ||||
|   OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION = 138, | ||||
|   OTA_RESPONSE_ERROR_MD5_MISMATCH = 139, | ||||
|   OTA_RESPONSE_ERROR_UNKNOWN = 255, | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -30,6 +30,8 @@ RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG = 134 | ||||
| RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG = 135 | ||||
| RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 136 | ||||
| RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 137 | ||||
| RESPONSE_ERROR_NO_UPDATE_PARTITION = 138 | ||||
| RESPONSE_ERROR_MD5_MISMATCH = 139 | ||||
| RESPONSE_ERROR_UNKNOWN = 255 | ||||
|  | ||||
| OTA_VERSION_1_0 = 1 | ||||
| @@ -150,6 +152,16 @@ def check_error(data, expect): | ||||
|             "Error: The OTA partition on the ESP is too small. ESPHome needs to resize " | ||||
|             "this partition, please flash over USB." | ||||
|         ) | ||||
|     if dat == RESPONSE_ERROR_NO_UPDATE_PARTITION: | ||||
|         raise OTAError( | ||||
|             "Error: The OTA partition on the ESP couldn't be found. ESPHome needs to create " | ||||
|             "this partition, please flash over USB." | ||||
|         ) | ||||
|     if dat == RESPONSE_ERROR_MD5_MISMATCH: | ||||
|         raise OTAError( | ||||
|             "Error: Application MD5 code mismatch. Please try again " | ||||
|             "or flash over USB with a good quality cable." | ||||
|         ) | ||||
|     if dat == RESPONSE_ERROR_UNKNOWN: | ||||
|         raise OTAError("Unknown error from ESP") | ||||
|     if not isinstance(expect, (list, tuple)): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user