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
|
@ -65,6 +65,7 @@ homeassistant.components.netatmo.*
|
||||||
homeassistant.components.network.*
|
homeassistant.components.network.*
|
||||||
homeassistant.components.no_ip.*
|
homeassistant.components.no_ip.*
|
||||||
homeassistant.components.notify.*
|
homeassistant.components.notify.*
|
||||||
|
homeassistant.components.notion.*
|
||||||
homeassistant.components.number.*
|
homeassistant.components.number.*
|
||||||
homeassistant.components.onewire.*
|
homeassistant.components.onewire.*
|
||||||
homeassistant.components.persistent_notification.*
|
homeassistant.components.persistent_notification.*
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
"""Support for Notion."""
|
"""Support for Notion."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from aionotion import async_get_client
|
from aionotion import async_get_client
|
||||||
from aionotion.errors import InvalidCredentialsError, NotionError
|
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)
|
LOGGER.error("Config entry failed: %s", err)
|
||||||
raise ConfigEntryNotReady from 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."""
|
"""Get the latest data from the Notion API."""
|
||||||
data = {"bridges": {}, "sensors": {}, "tasks": {}}
|
data: dict[str, dict[str, Any]] = {"bridges": {}, "sensors": {}, "tasks": {}}
|
||||||
tasks = {
|
tasks = {
|
||||||
"bridges": client.bridge.async_all(),
|
"bridges": client.bridge.async_all(),
|
||||||
"sensors": client.sensor.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(
|
async def async_register_new_bridge(
|
||||||
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
|
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
|
||||||
):
|
) -> None:
|
||||||
"""Register a new bridge."""
|
"""Register a new bridge."""
|
||||||
device_registry = await dr.async_get_registry(hass)
|
device_registry = await dr.async_get_registry(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
|
@ -190,13 +193,16 @@ class NotionEntity(CoordinatorEntity):
|
||||||
self._bridge_id = sensor["bridge"]["id"]
|
self._bridge_id = sensor["bridge"]["id"]
|
||||||
|
|
||||||
device_registry = await dr.async_get_registry(self.hass)
|
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 = self.coordinator.data["bridges"][self._bridge_id]
|
||||||
bridge_device = device_registry.async_get_device(
|
bridge_device = device_registry.async_get_device(
|
||||||
{(DOMAIN, bridge["hardware_id"])}
|
{(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(
|
device_registry.async_update_device(
|
||||||
this_device.id, via_device_id=bridge_device.id
|
this_device.id, via_device_id=bridge_device.id
|
||||||
|
|
14
mypy.ini
14
mypy.ini
|
@ -726,6 +726,17 @@ no_implicit_optional = true
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = 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.*]
|
[mypy-homeassistant.components.number.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
@ -1422,9 +1433,6 @@ ignore_errors = true
|
||||||
[mypy-homeassistant.components.norway_air.*]
|
[mypy-homeassistant.components.norway_air.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.notion.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.nsw_fuel_station.*]
|
[mypy-homeassistant.components.nsw_fuel_station.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.nilu.*",
|
"homeassistant.components.nilu.*",
|
||||||
"homeassistant.components.nmap_tracker.*",
|
"homeassistant.components.nmap_tracker.*",
|
||||||
"homeassistant.components.norway_air.*",
|
"homeassistant.components.norway_air.*",
|
||||||
"homeassistant.components.notion.*",
|
|
||||||
"homeassistant.components.nsw_fuel_station.*",
|
"homeassistant.components.nsw_fuel_station.*",
|
||||||
"homeassistant.components.nuki.*",
|
"homeassistant.components.nuki.*",
|
||||||
"homeassistant.components.nws.*",
|
"homeassistant.components.nws.*",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue