From 1cc8feabb7471cfa0121054cf2c054aec8636651 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:24:52 +0100 Subject: [PATCH] Remove unnecessary try-else (1) (#86158) --- homeassistant/components/airzone/entity.py | 4 ++-- homeassistant/components/broadlink/updater.py | 21 +++++++++--------- homeassistant/components/camera/__init__.py | 4 ++-- .../components/co2signal/__init__.py | 11 +++++----- homeassistant/components/emoncms/sensor.py | 22 +++++++++---------- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/homeassistant/components/airzone/entity.py b/homeassistant/components/airzone/entity.py index 2752e2932ad..a05b8cd6181 100644 --- a/homeassistant/components/airzone/entity.py +++ b/homeassistant/components/airzone/entity.py @@ -152,5 +152,5 @@ class AirzoneZoneEntity(AirzoneEntity): raise HomeAssistantError( f"Failed to set zone {self.name}: {error}" ) from error - else: - self.coordinator.async_set_updated_data(self.coordinator.airzone.data()) + + self.coordinator.async_set_updated_data(self.coordinator.airzone.data()) diff --git a/homeassistant/components/broadlink/updater.py b/homeassistant/components/broadlink/updater.py index 2b98b757fbd..f3837c73263 100644 --- a/homeassistant/components/broadlink/updater.py +++ b/homeassistant/components/broadlink/updater.py @@ -76,17 +76,16 @@ class BroadlinkUpdateManager(ABC): ) raise UpdateFailed(err) from err - else: - if self.available is False: - _LOGGER.warning( - "Connected to %s (%s at %s)", - self.device.name, - self.device.api.model, - self.device.api.host[0], - ) - self.available = True - self.last_update = dt.utcnow() - return data + if self.available is False: + _LOGGER.warning( + "Connected to %s (%s at %s)", + self.device.name, + self.device.api.model, + self.device.api.host[0], + ) + self.available = True + self.last_update = dt.utcnow() + return data @abstractmethod async def async_fetch_data(self): diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index f329be16f1d..d80504df8fc 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -747,8 +747,8 @@ class CameraImageView(CameraView): ) except (HomeAssistantError, ValueError) as ex: raise web.HTTPInternalServerError() from ex - else: - return web.Response(body=image.content, content_type=image.content_type) + + return web.Response(body=image.content, content_type=image.content_type) class CameraMjpegStream(CameraView): diff --git a/homeassistant/components/co2signal/__init__.py b/homeassistant/components/co2signal/__init__.py index a5bae23332d..721a26e147f 100644 --- a/homeassistant/components/co2signal/__init__.py +++ b/homeassistant/components/co2signal/__init__.py @@ -131,12 +131,11 @@ def get_data(hass: HomeAssistant, config: Mapping[str, Any]) -> CO2SignalRespons _LOGGER.exception("Unexpected exception") raise UnknownError from err - else: - if "error" in data: - raise UnknownError(data["error"]) + if "error" in data: + raise UnknownError(data["error"]) - if data.get("status") != "ok": - _LOGGER.exception("Unexpected response: %s", data) - raise UnknownError + if data.get("status") != "ok": + _LOGGER.exception("Unexpected response: %s", data) + raise UnknownError return cast(CO2SignalResponse, data) diff --git a/homeassistant/components/emoncms/sensor.py b/homeassistant/components/emoncms/sensor.py index f9382d1060b..4a427615aaf 100644 --- a/homeassistant/components/emoncms/sensor.py +++ b/homeassistant/components/emoncms/sensor.py @@ -285,15 +285,15 @@ class EmonCmsData: except requests.exceptions.RequestException as exception: _LOGGER.error(exception) return + + if req.status_code == HTTPStatus.OK: + self.data = req.json() else: - if req.status_code == HTTPStatus.OK: - self.data = req.json() - else: - _LOGGER.error( - ( - "Please verify if the specified configuration value " - "'%s' is correct! (HTTP Status_code = %d)" - ), - CONF_URL, - req.status_code, - ) + _LOGGER.error( + ( + "Please verify if the specified configuration value " + "'%s' is correct! (HTTP Status_code = %d)" + ), + CONF_URL, + req.status_code, + )