Improve `brunt` generic typing (#84735)
parent
bfb509ccb8
commit
e693ba17e0
|
@ -5,7 +5,7 @@ import logging
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientResponseError, ServerDisconnectedError
|
from aiohttp.client_exceptions import ClientResponseError, ServerDisconnectedError
|
||||||
import async_timeout
|
import async_timeout
|
||||||
from brunt import BruntClientAsync
|
from brunt import BruntClientAsync, Thing
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
|
@ -36,7 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
f"Brunt could not connect with username: {entry.data[CONF_USERNAME]}."
|
f"Brunt could not connect with username: {entry.data[CONF_USERNAME]}."
|
||||||
) from exc
|
) from exc
|
||||||
|
|
||||||
async def async_update_data():
|
async def async_update_data() -> dict[str | None, Thing]:
|
||||||
"""Fetch data from the Brunt endpoint for all Things.
|
"""Fetch data from the Brunt endpoint for all Things.
|
||||||
|
|
||||||
Error 403 is the API response for any kind of authentication error (failed password or email)
|
Error 403 is the API response for any kind of authentication error (failed password or email)
|
||||||
|
@ -54,6 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
if err.status == 401:
|
if err.status == 401:
|
||||||
_LOGGER.warning("Device not found, will reload Brunt integration")
|
_LOGGER.warning("Device not found, will reload Brunt integration")
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
|
raise UpdateFailed from err
|
||||||
|
|
||||||
coordinator = DataUpdateCoordinator(
|
coordinator = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Support for Brunt Blind Engine covers."""
|
"""Support for Brunt Blind Engine covers."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any, Optional
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientResponseError
|
from aiohttp.client_exceptions import ClientResponseError
|
||||||
from brunt import BruntClientAsync, Thing
|
from brunt import BruntClientAsync, Thing
|
||||||
|
@ -42,7 +42,9 @@ async def async_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the brunt platform."""
|
"""Set up the brunt platform."""
|
||||||
bapi: BruntClientAsync = hass.data[DOMAIN][entry.entry_id][DATA_BAPI]
|
bapi: BruntClientAsync = hass.data[DOMAIN][entry.entry_id][DATA_BAPI]
|
||||||
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][DATA_COOR]
|
coordinator: DataUpdateCoordinator[dict[str | None, Thing]] = hass.data[DOMAIN][
|
||||||
|
entry.entry_id
|
||||||
|
][DATA_COOR]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
BruntDevice(coordinator, serial, thing, bapi, entry.entry_id)
|
BruntDevice(coordinator, serial, thing, bapi, entry.entry_id)
|
||||||
|
@ -50,7 +52,9 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BruntDevice(CoordinatorEntity, CoverEntity):
|
class BruntDevice(
|
||||||
|
CoordinatorEntity[DataUpdateCoordinator[dict[Optional[str], Thing]]], CoverEntity
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Representation of a Brunt cover device.
|
Representation of a Brunt cover device.
|
||||||
|
|
||||||
|
@ -65,8 +69,8 @@ class BruntDevice(CoordinatorEntity, CoverEntity):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator[dict[str | None, Thing]],
|
||||||
serial: str,
|
serial: str | None,
|
||||||
thing: Thing,
|
thing: Thing,
|
||||||
bapi: BruntClientAsync,
|
bapi: BruntClientAsync,
|
||||||
entry_id: str,
|
entry_id: str,
|
||||||
|
@ -84,7 +88,7 @@ class BruntDevice(CoordinatorEntity, CoverEntity):
|
||||||
self._attr_device_class = CoverDeviceClass.BLIND
|
self._attr_device_class = CoverDeviceClass.BLIND
|
||||||
self._attr_attribution = ATTRIBUTION
|
self._attr_attribution = ATTRIBUTION
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, self._attr_unique_id)},
|
identifiers={(DOMAIN, self._attr_unique_id)}, # type: ignore[arg-type]
|
||||||
name=self._attr_name,
|
name=self._attr_name,
|
||||||
via_device=(DOMAIN, self._entry_id),
|
via_device=(DOMAIN, self._entry_id),
|
||||||
manufacturer="Brunt",
|
manufacturer="Brunt",
|
||||||
|
|
Loading…
Reference in New Issue