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.pull/82560/head^2
parent
f081fa8feb
commit
048d30904e
|
@ -90,8 +90,7 @@ def setup_platform(
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
entities = [
|
entities = [
|
||||||
QBittorrentSensor(description, client, name, LoginRequired)
|
QBittorrentSensor(description, client, name) for description in SENSOR_TYPES
|
||||||
for description in SENSOR_TYPES
|
|
||||||
]
|
]
|
||||||
|
|
||||||
add_entities(entities, True)
|
add_entities(entities, True)
|
||||||
|
@ -111,12 +110,10 @@ class QBittorrentSensor(SensorEntity):
|
||||||
description: SensorEntityDescription,
|
description: SensorEntityDescription,
|
||||||
qbittorrent_client,
|
qbittorrent_client,
|
||||||
client_name,
|
client_name,
|
||||||
exception,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the qBittorrent sensor."""
|
"""Initialize the qBittorrent sensor."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self.client = qbittorrent_client
|
self.client = qbittorrent_client
|
||||||
self._exception = exception
|
|
||||||
|
|
||||||
self._attr_name = f"{client_name} {description.name}"
|
self._attr_name = f"{client_name} {description.name}"
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
|
@ -130,7 +127,7 @@ class QBittorrentSensor(SensorEntity):
|
||||||
_LOGGER.error("Connection lost")
|
_LOGGER.error("Connection lost")
|
||||||
self._attr_available = False
|
self._attr_available = False
|
||||||
return
|
return
|
||||||
except self._exception:
|
except LoginRequired:
|
||||||
_LOGGER.error("Invalid authentication")
|
_LOGGER.error("Invalid authentication")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue