Add `ConfigEntryNotReady` exception when the update during setup fails
This commit is contained in:
		
							parent
							
								
									5e24680d5d
								
							
						
					
					
						commit
						2c278da442
					
				|  | @ -1,5 +1,12 @@ | ||||||
| # Changelog | # Changelog | ||||||
| 
 | 
 | ||||||
|  | ## [0.3.1] Let HomeAssistant schedule failing setup of integration | ||||||
|  | 
 | ||||||
|  | ### Added | ||||||
|  | 
 | ||||||
|  | - Add a `try / catch` mechanism to the first update of the client while setup and throw a | ||||||
|  |   `ConfigEntryNotReady` exception when the update fails | ||||||
|  | 
 | ||||||
| ## [0.3.0] Icons and Chore | ## [0.3.0] Icons and Chore | ||||||
| 
 | 
 | ||||||
| ### Added | ### Added | ||||||
|  |  | ||||||
|  | @ -1,7 +1,9 @@ | ||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
|  | from aiohttp import ClientResponseError | ||||||
| from homeassistant.config_entries import ConfigEntry | from homeassistant.config_entries import ConfigEntry | ||||||
| from homeassistant.core import DOMAIN, HomeAssistant | from homeassistant.core import DOMAIN, HomeAssistant | ||||||
|  | from homeassistant.exceptions import ConfigEntryNotReady | ||||||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||||
| from pysmartthings import SmartThings | from pysmartthings import SmartThings | ||||||
| 
 | 
 | ||||||
|  | @ -49,7 +51,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||||||
|             entry.data.get(CONF_ENTRY_MAX_VOLUME), |             entry.data.get(CONF_ENTRY_MAX_VOLUME), | ||||||
|             entry.data.get(CONF_ENTRY_DEVICE_NAME), |             entry.data.get(CONF_ENTRY_DEVICE_NAME), | ||||||
|         ) |         ) | ||||||
|  |         try: | ||||||
|             await soundbar_device.update() |             await soundbar_device.update() | ||||||
|  |         except ClientResponseError as excp: | ||||||
|  |             raise ConfigEntryNotReady("An error occurred while setting up the soundbar device. " | ||||||
|  |                                       "Please recheck whether the device has power or is connected to the internet.")\ | ||||||
|  |                 from excp | ||||||
|         domain_config.devices[entry.data.get(CONF_ENTRY_DEVICE_ID)] = DeviceConfig( |         domain_config.devices[entry.data.get(CONF_ENTRY_DEVICE_ID)] = DeviceConfig( | ||||||
|             entry.data, soundbar_device |             entry.data, soundbar_device | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  | @ -8,5 +8,5 @@ | ||||||
|   "iot_class": "cloud_polling", |   "iot_class": "cloud_polling", | ||||||
|   "issue_tracker": "https://github.com/samuelspagl/ha_samsung_soundbar/issues", |   "issue_tracker": "https://github.com/samuelspagl/ha_samsung_soundbar/issues", | ||||||
|   "requirements": ["pysmartthings"], |   "requirements": ["pysmartthings"], | ||||||
|   "version": "0.3.0" |   "version": "0.3.1" | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue