diff --git a/.strict-typing b/.strict-typing index 19835bfd777..0a226f973f6 100644 --- a/.strict-typing +++ b/.strict-typing @@ -65,6 +65,7 @@ homeassistant.components.netatmo.* homeassistant.components.network.* homeassistant.components.no_ip.* homeassistant.components.notify.* +homeassistant.components.notion.* homeassistant.components.number.* homeassistant.components.onewire.* homeassistant.components.persistent_notification.* diff --git a/homeassistant/components/notion/__init__.py b/homeassistant/components/notion/__init__.py index 8acf9c24d4a..aab10916514 100644 --- a/homeassistant/components/notion/__init__.py +++ b/homeassistant/components/notion/__init__.py @@ -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 diff --git a/mypy.ini b/mypy.ini index e0bdc372f50..014272f0022 100644 --- a/mypy.ini +++ b/mypy.ini @@ -726,6 +726,17 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.notion.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.number.*] check_untyped_defs = true disallow_incomplete_defs = true @@ -1422,9 +1433,6 @@ ignore_errors = true [mypy-homeassistant.components.norway_air.*] ignore_errors = true -[mypy-homeassistant.components.notion.*] -ignore_errors = true - [mypy-homeassistant.components.nsw_fuel_station.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index b1c74fceb45..642dd47b732 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -114,7 +114,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.nilu.*", "homeassistant.components.nmap_tracker.*", "homeassistant.components.norway_air.*", - "homeassistant.components.notion.*", "homeassistant.components.nsw_fuel_station.*", "homeassistant.components.nuki.*", "homeassistant.components.nws.*",