From d26484d4826dc6126a2bd546927f1deae6afd0c2 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 18 Jan 2023 13:17:08 +0100 Subject: [PATCH] Remove unnecessary try-else (4) (#86161) --- homeassistant/components/nam/config_flow.py | 12 ++++++------ homeassistant/components/rainmachine/config_flow.py | 4 ++-- homeassistant/components/shelly/config_flow.py | 12 ++++++------ homeassistant/components/switchbee/climate.py | 4 ++-- homeassistant/components/switchbee/coordinator.py | 4 ++-- homeassistant/components/syncthing/__init__.py | 4 ++-- homeassistant/components/syncthru/__init__.py | 12 +++++------- homeassistant/components/wiz/config_flow.py | 10 +++++----- homeassistant/components/zwave_js/__init__.py | 6 +++--- 9 files changed, 33 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/nam/config_flow.py b/homeassistant/components/nam/config_flow.py index 3dc2d7f0ba0..20021f1e6d4 100644 --- a/homeassistant/components/nam/config_flow.py +++ b/homeassistant/components/nam/config_flow.py @@ -209,12 +209,12 @@ class NAMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): await async_check_credentials(self.hass, self.host, user_input) except (ApiError, AuthFailed, ClientConnectorError, asyncio.TimeoutError): return self.async_abort(reason="reauth_unsuccessful") - else: - self.hass.config_entries.async_update_entry( - self.entry, data={**user_input, CONF_HOST: self.host} - ) - await self.hass.config_entries.async_reload(self.entry.entry_id) - return self.async_abort(reason="reauth_successful") + + self.hass.config_entries.async_update_entry( + self.entry, data={**user_input, CONF_HOST: self.host} + ) + await self.hass.config_entries.async_reload(self.entry.entry_id) + return self.async_abort(reason="reauth_successful") return self.async_show_form( step_id="reauth_confirm", diff --git a/homeassistant/components/rainmachine/config_flow.py b/homeassistant/components/rainmachine/config_flow.py index 1efcf5302fc..1ad97de7d0b 100644 --- a/homeassistant/components/rainmachine/config_flow.py +++ b/homeassistant/components/rainmachine/config_flow.py @@ -41,8 +41,8 @@ async def async_get_controller( await client.load_local(ip_address, password, port=port, use_ssl=ssl) except RainMachineError: return None - else: - return get_client_controller(client) + + return get_client_controller(client) class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index f6be4a254c6..3b24bf026a9 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -329,12 +329,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): await validate_input(self.hass, host, info, user_input) except (DeviceConnectionError, InvalidAuthError, FirmwareUnsupported): return self.async_abort(reason="reauth_unsuccessful") - else: - self.hass.config_entries.async_update_entry( - self.entry, data={**self.entry.data, **user_input} - ) - await self.hass.config_entries.async_reload(self.entry.entry_id) - return self.async_abort(reason="reauth_successful") + + self.hass.config_entries.async_update_entry( + self.entry, data={**self.entry.data, **user_input} + ) + await self.hass.config_entries.async_reload(self.entry.entry_id) + return self.async_abort(reason="reauth_successful") if self.entry.data.get("gen", 1) == 1: schema = { diff --git a/homeassistant/components/switchbee/climate.py b/homeassistant/components/switchbee/climate.py index efc9c25d4bd..3b42287e89f 100644 --- a/homeassistant/components/switchbee/climate.py +++ b/homeassistant/components/switchbee/climate.py @@ -178,5 +178,5 @@ class SwitchBeeClimateEntity(SwitchBeeDeviceEntity[SwitchBeeThermostat], Climate raise HomeAssistantError( f"Failed to set {self.name} state {state}, error: {str(exp)}" ) from exp - else: - await self.coordinator.async_refresh() + + await self.coordinator.async_refresh() diff --git a/homeassistant/components/switchbee/coordinator.py b/homeassistant/components/switchbee/coordinator.py index ad9e9669ac8..b1b606615dd 100644 --- a/homeassistant/components/switchbee/coordinator.py +++ b/homeassistant/components/switchbee/coordinator.py @@ -83,8 +83,8 @@ class SwitchBeeCoordinator(DataUpdateCoordinator[Mapping[int, SwitchBeeBaseDevic raise UpdateFailed( f"Error communicating with API: {exp}" ) from SwitchBeeError - else: - _LOGGER.debug("Loaded devices") + + _LOGGER.debug("Loaded devices") # Get the state of the devices try: diff --git a/homeassistant/components/syncthing/__init__.py b/homeassistant/components/syncthing/__init__.py index 15f9bc7d307..1f492656166 100644 --- a/homeassistant/components/syncthing/__init__.py +++ b/homeassistant/components/syncthing/__init__.py @@ -172,5 +172,5 @@ class SyncthingClient: await self._client.system.ping() except aiosyncthing.exceptions.SyncthingError: return False - else: - return True + + return True diff --git a/homeassistant/components/syncthru/__init__.py b/homeassistant/components/syncthru/__init__.py index c757ff0c529..f77f68450a4 100644 --- a/homeassistant/components/syncthru/__init__.py +++ b/homeassistant/components/syncthru/__init__.py @@ -42,13 +42,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: exc_info=api_error, ) raise api_error - else: - # if the printer is offline, we raise an UpdateFailed - if printer.is_unknown_state(): - raise UpdateFailed( - f"Configured printer at {printer.url} does not respond." - ) - return printer + + # if the printer is offline, we raise an UpdateFailed + if printer.is_unknown_state(): + raise UpdateFailed(f"Configured printer at {printer.url} does not respond.") + return printer coordinator = DataUpdateCoordinator[SyncThru]( hass, diff --git a/homeassistant/components/wiz/config_flow.py b/homeassistant/components/wiz/config_flow.py index b1bce3eda0d..f2d109bd6bb 100644 --- a/homeassistant/components/wiz/config_flow.py +++ b/homeassistant/components/wiz/config_flow.py @@ -114,11 +114,11 @@ class WizConfigFlow(ConfigFlow, domain=DOMAIN): bulbtype = await bulb.get_bulbtype() except WIZ_CONNECT_EXCEPTIONS: return self.async_abort(reason="cannot_connect") - else: - return self.async_create_entry( - title=name_from_bulb_type_and_mac(bulbtype, device.mac_address), - data={CONF_HOST: device.ip_address}, - ) + + return self.async_create_entry( + title=name_from_bulb_type_and_mac(bulbtype, device.mac_address), + data={CONF_HOST: device.ip_address}, + ) current_unique_ids = self._async_current_ids() current_hosts = { diff --git a/homeassistant/components/zwave_js/__init__.py b/homeassistant/components/zwave_js/__init__.py index 25ca742a611..ee007a95e81 100644 --- a/homeassistant/components/zwave_js/__init__.py +++ b/homeassistant/components/zwave_js/__init__.py @@ -157,9 +157,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: raise ConfigEntryNotReady(f"Invalid server version: {err}") from err except (asyncio.TimeoutError, BaseZwaveJSServerError) as err: raise ConfigEntryNotReady(f"Failed to connect: {err}") from err - else: - async_delete_issue(hass, DOMAIN, "invalid_server_version") - LOGGER.info("Connected to Zwave JS Server") + + async_delete_issue(hass, DOMAIN, "invalid_server_version") + LOGGER.info("Connected to Zwave JS Server") dev_reg = device_registry.async_get(hass) ent_reg = entity_registry.async_get(hass)