Remove unnecessary try-else (4) (#86161)

This commit is contained in:
Marc Mueller 2023-01-18 13:17:08 +01:00 committed by GitHub
parent a44e44b7d0
commit d26484d482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 33 additions and 35 deletions

View File

@ -209,12 +209,12 @@ class NAMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
await async_check_credentials(self.hass, self.host, user_input) await async_check_credentials(self.hass, self.host, user_input)
except (ApiError, AuthFailed, ClientConnectorError, asyncio.TimeoutError): except (ApiError, AuthFailed, ClientConnectorError, asyncio.TimeoutError):
return self.async_abort(reason="reauth_unsuccessful") return self.async_abort(reason="reauth_unsuccessful")
else:
self.hass.config_entries.async_update_entry( self.hass.config_entries.async_update_entry(
self.entry, data={**user_input, CONF_HOST: self.host} self.entry, data={**user_input, CONF_HOST: self.host}
) )
await self.hass.config_entries.async_reload(self.entry.entry_id) await self.hass.config_entries.async_reload(self.entry.entry_id)
return self.async_abort(reason="reauth_successful") return self.async_abort(reason="reauth_successful")
return self.async_show_form( return self.async_show_form(
step_id="reauth_confirm", step_id="reauth_confirm",

View File

@ -41,8 +41,8 @@ async def async_get_controller(
await client.load_local(ip_address, password, port=port, use_ssl=ssl) await client.load_local(ip_address, password, port=port, use_ssl=ssl)
except RainMachineError: except RainMachineError:
return None return None
else:
return get_client_controller(client) return get_client_controller(client)
class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):

View File

@ -329,12 +329,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
await validate_input(self.hass, host, info, user_input) await validate_input(self.hass, host, info, user_input)
except (DeviceConnectionError, InvalidAuthError, FirmwareUnsupported): except (DeviceConnectionError, InvalidAuthError, FirmwareUnsupported):
return self.async_abort(reason="reauth_unsuccessful") return self.async_abort(reason="reauth_unsuccessful")
else:
self.hass.config_entries.async_update_entry( self.hass.config_entries.async_update_entry(
self.entry, data={**self.entry.data, **user_input} self.entry, data={**self.entry.data, **user_input}
) )
await self.hass.config_entries.async_reload(self.entry.entry_id) await self.hass.config_entries.async_reload(self.entry.entry_id)
return self.async_abort(reason="reauth_successful") return self.async_abort(reason="reauth_successful")
if self.entry.data.get("gen", 1) == 1: if self.entry.data.get("gen", 1) == 1:
schema = { schema = {

View File

@ -178,5 +178,5 @@ class SwitchBeeClimateEntity(SwitchBeeDeviceEntity[SwitchBeeThermostat], Climate
raise HomeAssistantError( raise HomeAssistantError(
f"Failed to set {self.name} state {state}, error: {str(exp)}" f"Failed to set {self.name} state {state}, error: {str(exp)}"
) from exp ) from exp
else:
await self.coordinator.async_refresh() await self.coordinator.async_refresh()

View File

@ -83,8 +83,8 @@ class SwitchBeeCoordinator(DataUpdateCoordinator[Mapping[int, SwitchBeeBaseDevic
raise UpdateFailed( raise UpdateFailed(
f"Error communicating with API: {exp}" f"Error communicating with API: {exp}"
) from SwitchBeeError ) from SwitchBeeError
else:
_LOGGER.debug("Loaded devices") _LOGGER.debug("Loaded devices")
# Get the state of the devices # Get the state of the devices
try: try:

View File

@ -172,5 +172,5 @@ class SyncthingClient:
await self._client.system.ping() await self._client.system.ping()
except aiosyncthing.exceptions.SyncthingError: except aiosyncthing.exceptions.SyncthingError:
return False return False
else:
return True return True

View File

@ -42,13 +42,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
exc_info=api_error, exc_info=api_error,
) )
raise api_error raise api_error
else:
# if the printer is offline, we raise an UpdateFailed # if the printer is offline, we raise an UpdateFailed
if printer.is_unknown_state(): if printer.is_unknown_state():
raise UpdateFailed( raise UpdateFailed(f"Configured printer at {printer.url} does not respond.")
f"Configured printer at {printer.url} does not respond." return printer
)
return printer
coordinator = DataUpdateCoordinator[SyncThru]( coordinator = DataUpdateCoordinator[SyncThru](
hass, hass,

View File

@ -114,11 +114,11 @@ class WizConfigFlow(ConfigFlow, domain=DOMAIN):
bulbtype = await bulb.get_bulbtype() bulbtype = await bulb.get_bulbtype()
except WIZ_CONNECT_EXCEPTIONS: except WIZ_CONNECT_EXCEPTIONS:
return self.async_abort(reason="cannot_connect") return self.async_abort(reason="cannot_connect")
else:
return self.async_create_entry( return self.async_create_entry(
title=name_from_bulb_type_and_mac(bulbtype, device.mac_address), title=name_from_bulb_type_and_mac(bulbtype, device.mac_address),
data={CONF_HOST: device.ip_address}, data={CONF_HOST: device.ip_address},
) )
current_unique_ids = self._async_current_ids() current_unique_ids = self._async_current_ids()
current_hosts = { current_hosts = {

View File

@ -157,9 +157,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
raise ConfigEntryNotReady(f"Invalid server version: {err}") from err raise ConfigEntryNotReady(f"Invalid server version: {err}") from err
except (asyncio.TimeoutError, BaseZwaveJSServerError) as err: except (asyncio.TimeoutError, BaseZwaveJSServerError) as err:
raise ConfigEntryNotReady(f"Failed to connect: {err}") from err raise ConfigEntryNotReady(f"Failed to connect: {err}") from err
else:
async_delete_issue(hass, DOMAIN, "invalid_server_version") async_delete_issue(hass, DOMAIN, "invalid_server_version")
LOGGER.info("Connected to Zwave JS Server") LOGGER.info("Connected to Zwave JS Server")
dev_reg = device_registry.async_get(hass) dev_reg = device_registry.async_get(hass)
ent_reg = entity_registry.async_get(hass) ent_reg = entity_registry.async_get(hass)