From 048d30904e62d61fd5d5ab94635e381c94b6fdd4 Mon Sep 17 00:00:00 2001 From: Chris Xiao <30990835+chrisx8@users.noreply.github.com> Date: Tue, 28 Mar 2023 10:52:16 -0400 Subject: [PATCH] Simplify qbittorrent sensor class init (#90411) catch LoginException directly in QBittorrentSensor init Since the `exception` arg in QBittorrentSensor `__init__` is always LoginException, we catch LoginException directly in `__init__` instead of passing LoginException as an argument. --- homeassistant/components/qbittorrent/sensor.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/qbittorrent/sensor.py b/homeassistant/components/qbittorrent/sensor.py index bee7a5d61a6..cafb8d8b21e 100644 --- a/homeassistant/components/qbittorrent/sensor.py +++ b/homeassistant/components/qbittorrent/sensor.py @@ -90,8 +90,7 @@ def setup_platform( name = config.get(CONF_NAME) entities = [ - QBittorrentSensor(description, client, name, LoginRequired) - for description in SENSOR_TYPES + QBittorrentSensor(description, client, name) for description in SENSOR_TYPES ] add_entities(entities, True) @@ -111,12 +110,10 @@ class QBittorrentSensor(SensorEntity): description: SensorEntityDescription, qbittorrent_client, client_name, - exception, ) -> None: """Initialize the qBittorrent sensor.""" self.entity_description = description self.client = qbittorrent_client - self._exception = exception self._attr_name = f"{client_name} {description.name}" self._attr_available = False @@ -130,7 +127,7 @@ class QBittorrentSensor(SensorEntity): _LOGGER.error("Connection lost") self._attr_available = False return - except self._exception: + except LoginRequired: _LOGGER.error("Invalid authentication") return