Enforce strict typing for Notion (#53355)
* Enforce strict typing for Notion * Code review
This commit is contained in:
parent
91018d0451
commit
4b353917f5
4 changed files with 24 additions and 10 deletions
|
@ -1,6 +1,9 @@
|
|||
"""Support for Notion."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
from aionotion import async_get_client
|
||||
from aionotion.errors import InvalidCredentialsError, NotionError
|
||||
|
@ -55,9 +58,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
LOGGER.error("Config entry failed: %s", err)
|
||||
raise ConfigEntryNotReady from err
|
||||
|
||||
async def async_update():
|
||||
async def async_update() -> dict[str, dict[str, Any]]:
|
||||
"""Get the latest data from the Notion API."""
|
||||
data = {"bridges": {}, "sensors": {}, "tasks": {}}
|
||||
data: dict[str, dict[str, Any]] = {"bridges": {}, "sensors": {}, "tasks": {}}
|
||||
tasks = {
|
||||
"bridges": client.bridge.async_all(),
|
||||
"sensors": client.sensor.async_all(),
|
||||
|
@ -111,7 +114,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
async def async_register_new_bridge(
|
||||
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
|
||||
):
|
||||
) -> None:
|
||||
"""Register a new bridge."""
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry.async_get_or_create(
|
||||
|
@ -190,13 +193,16 @@ class NotionEntity(CoordinatorEntity):
|
|||
self._bridge_id = sensor["bridge"]["id"]
|
||||
|
||||
device_registry = await dr.async_get_registry(self.hass)
|
||||
this_device = device_registry.async_get_device(
|
||||
{(DOMAIN, sensor["hardware_id"])}
|
||||
)
|
||||
bridge = self.coordinator.data["bridges"][self._bridge_id]
|
||||
bridge_device = device_registry.async_get_device(
|
||||
{(DOMAIN, bridge["hardware_id"])}
|
||||
)
|
||||
this_device = device_registry.async_get_device(
|
||||
{(DOMAIN, sensor["hardware_id"])}
|
||||
)
|
||||
|
||||
if not bridge_device or not this_device:
|
||||
return
|
||||
|
||||
device_registry.async_update_device(
|
||||
this_device.id, via_device_id=bridge_device.id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue