mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[core] Fix IndexError when OTA devices cannot be resolved (#11311)
This commit is contained in:
		
				
					committed by
					
						 Jesse Hills
						Jesse Hills
					
				
			
			
				
	
			
			
			
						parent
						
							0e34d1b64d
						
					
				
				
					commit
					6aff1394ad
				
			| @@ -185,7 +185,9 @@ def choose_upload_log_host( | |||||||
|             else: |             else: | ||||||
|                 resolved.append(device) |                 resolved.append(device) | ||||||
|         if not resolved: |         if not resolved: | ||||||
|             _LOGGER.error("All specified devices: %s could not be resolved.", defaults) |             raise EsphomeError( | ||||||
|  |                 f"All specified devices {defaults} could not be resolved. Is the device connected to the network?" | ||||||
|  |             ) | ||||||
|         return resolved |         return resolved | ||||||
|  |  | ||||||
|     # No devices specified, show interactive chooser |     # No devices specified, show interactive chooser | ||||||
|   | |||||||
| @@ -321,12 +321,14 @@ def test_choose_upload_log_host_with_serial_device_no_ports( | |||||||
| ) -> None: | ) -> None: | ||||||
|     """Test SERIAL device when no serial ports are found.""" |     """Test SERIAL device when no serial ports are found.""" | ||||||
|     setup_core() |     setup_core() | ||||||
|     result = choose_upload_log_host( |     with pytest.raises( | ||||||
|  |         EsphomeError, match="All specified devices .* could not be resolved" | ||||||
|  |     ): | ||||||
|  |         choose_upload_log_host( | ||||||
|             default="SERIAL", |             default="SERIAL", | ||||||
|             check_default=None, |             check_default=None, | ||||||
|             purpose=Purpose.UPLOADING, |             purpose=Purpose.UPLOADING, | ||||||
|         ) |         ) | ||||||
|     assert result == [] |  | ||||||
|     assert "No serial ports found, skipping SERIAL device" in caplog.text |     assert "No serial ports found, skipping SERIAL device" in caplog.text | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -367,12 +369,14 @@ def test_choose_upload_log_host_with_ota_device_with_api_config() -> None: | |||||||
|     """Test OTA device when API is configured (no upload without OTA in config).""" |     """Test OTA device when API is configured (no upload without OTA in config).""" | ||||||
|     setup_core(config={CONF_API: {}}, address="192.168.1.100") |     setup_core(config={CONF_API: {}}, address="192.168.1.100") | ||||||
|  |  | ||||||
|     result = choose_upload_log_host( |     with pytest.raises( | ||||||
|  |         EsphomeError, match="All specified devices .* could not be resolved" | ||||||
|  |     ): | ||||||
|  |         choose_upload_log_host( | ||||||
|             default="OTA", |             default="OTA", | ||||||
|             check_default=None, |             check_default=None, | ||||||
|             purpose=Purpose.UPLOADING, |             purpose=Purpose.UPLOADING, | ||||||
|         ) |         ) | ||||||
|     assert result == [] |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_choose_upload_log_host_with_ota_device_with_api_config_logging() -> None: | def test_choose_upload_log_host_with_ota_device_with_api_config_logging() -> None: | ||||||
| @@ -405,12 +409,14 @@ def test_choose_upload_log_host_with_ota_device_no_fallback() -> None: | |||||||
|     """Test OTA device with no valid fallback options.""" |     """Test OTA device with no valid fallback options.""" | ||||||
|     setup_core() |     setup_core() | ||||||
|  |  | ||||||
|     result = choose_upload_log_host( |     with pytest.raises( | ||||||
|  |         EsphomeError, match="All specified devices .* could not be resolved" | ||||||
|  |     ): | ||||||
|  |         choose_upload_log_host( | ||||||
|             default="OTA", |             default="OTA", | ||||||
|             check_default=None, |             check_default=None, | ||||||
|             purpose=Purpose.UPLOADING, |             purpose=Purpose.UPLOADING, | ||||||
|         ) |         ) | ||||||
|     assert result == [] |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.usefixtures("mock_choose_prompt") | @pytest.mark.usefixtures("mock_choose_prompt") | ||||||
| @@ -615,21 +621,19 @@ def test_choose_upload_log_host_empty_defaults_list() -> None: | |||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.usefixtures("mock_no_serial_ports", "mock_no_mqtt_logging") | @pytest.mark.usefixtures("mock_no_serial_ports", "mock_no_mqtt_logging") | ||||||
| def test_choose_upload_log_host_all_devices_unresolved( | def test_choose_upload_log_host_all_devices_unresolved() -> None: | ||||||
|     caplog: pytest.LogCaptureFixture, |  | ||||||
| ) -> None: |  | ||||||
|     """Test when all specified devices cannot be resolved.""" |     """Test when all specified devices cannot be resolved.""" | ||||||
|     setup_core() |     setup_core() | ||||||
|  |  | ||||||
|     result = choose_upload_log_host( |     with pytest.raises( | ||||||
|  |         EsphomeError, | ||||||
|  |         match=r"All specified devices \['SERIAL', 'OTA'\] could not be resolved", | ||||||
|  |     ): | ||||||
|  |         choose_upload_log_host( | ||||||
|             default=["SERIAL", "OTA"], |             default=["SERIAL", "OTA"], | ||||||
|             check_default=None, |             check_default=None, | ||||||
|             purpose=Purpose.UPLOADING, |             purpose=Purpose.UPLOADING, | ||||||
|         ) |         ) | ||||||
|     assert result == [] |  | ||||||
|     assert ( |  | ||||||
|         "All specified devices: ['SERIAL', 'OTA'] could not be resolved." in caplog.text |  | ||||||
|     ) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.usefixtures("mock_no_serial_ports", "mock_no_mqtt_logging") | @pytest.mark.usefixtures("mock_no_serial_ports", "mock_no_mqtt_logging") | ||||||
| @@ -762,12 +766,14 @@ def test_choose_upload_log_host_no_address_with_ota_config() -> None: | |||||||
|     """Test OTA device when OTA is configured but no address is set.""" |     """Test OTA device when OTA is configured but no address is set.""" | ||||||
|     setup_core(config={CONF_OTA: {}}) |     setup_core(config={CONF_OTA: {}}) | ||||||
|  |  | ||||||
|     result = choose_upload_log_host( |     with pytest.raises( | ||||||
|  |         EsphomeError, match="All specified devices .* could not be resolved" | ||||||
|  |     ): | ||||||
|  |         choose_upload_log_host( | ||||||
|             default="OTA", |             default="OTA", | ||||||
|             check_default=None, |             check_default=None, | ||||||
|             purpose=Purpose.UPLOADING, |             purpose=Purpose.UPLOADING, | ||||||
|         ) |         ) | ||||||
|     assert result == [] |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @dataclass | @dataclass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user