1 """The brunt component."""
3 from __future__
import annotations
5 from asyncio
import timeout
8 from aiohttp.client_exceptions
import ClientResponseError, ServerDisconnectedError
9 from brunt
import BruntClientAsync, Thing
18 from .const
import REGULAR_INTERVAL
20 _LOGGER = logging.getLogger(__name__)
22 type BruntConfigEntry = ConfigEntry[BruntCoordinator]
26 """Config entry data."""
28 bapi: BruntClientAsync
29 config_entry: BruntConfigEntry
34 config_entry: BruntConfigEntry,
36 """Initialize the Brunt coordinator."""
40 config_entry=config_entry,
42 update_interval=REGULAR_INTERVAL,
48 self.
bapibapi = BruntClientAsync(
49 username=self.
config_entryconfig_entry.data[CONF_USERNAME],
50 password=self.
config_entryconfig_entry.data[CONF_PASSWORD],
54 await self.
bapibapi.async_login()
55 except ServerDisconnectedError
as exc:
57 except ClientResponseError
as exc:
59 f
"Brunt could not connect with username: {self.config_entry.data[CONF_USERNAME]}."
63 """Fetch data from the Brunt endpoint for all Things.
65 Error 403 is the API response for any kind of authentication error (failed password or email)
66 Error 401 is the API response for things that are not part of the account, could happen when a device is deleted from the account.
69 async
with timeout(10):
70 things = await self.
bapibapi.async_get_things(force=
True)
71 return {thing.serial: thing
for thing
in things}
72 except ServerDisconnectedError
as err:
73 raise UpdateFailed(f
"Error communicating with API: {err}")
from err
74 except ClientResponseError
as err:
76 raise ConfigEntryAuthFailed
from err
78 _LOGGER.warning(
"Device not found, will reload Brunt integration")
79 await self.
hasshass.config_entries.async_reload(self.
config_entryconfig_entry.entry_id)
80 raise UpdateFailed
from err
dict[str|None, Thing] _async_update_data(self)
None __init__(self, HomeAssistant hass, BruntConfigEntry config_entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)