Enable strict typing for the otbr integration (#86473)

* Enable strict typing for the otbr integration

* Bump python-otbr-api to 1.0.2
This commit is contained in:
Erik Montnemery 2023-01-24 06:55:12 +01:00 committed by GitHub
parent ea95abcb30
commit 2ab3d3ebf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 10 deletions

View File

@ -223,6 +223,7 @@ homeassistant.components.onewire.*
homeassistant.components.open_meteo.*
homeassistant.components.openexchangerates.*
homeassistant.components.openuv.*
homeassistant.components.otbr.*
homeassistant.components.overkiz.*
homeassistant.components.peco.*
homeassistant.components.persistent_notification.*

View File

@ -1,8 +1,10 @@
"""The Open Thread Border Router integration."""
from __future__ import annotations
from collections.abc import Callable, Coroutine
import dataclasses
from functools import wraps
from typing import Any, Concatenate, ParamSpec, TypeVar
import python_otbr_api
@ -15,12 +17,17 @@ from homeassistant.helpers.typing import ConfigType
from . import websocket_api
from .const import DOMAIN
_R = TypeVar("_R")
_P = ParamSpec("_P")
def _handle_otbr_error(func):
def _handle_otbr_error(
func: Callable[Concatenate[OTBRData, _P], Coroutine[Any, Any, _R]]
) -> Callable[Concatenate[OTBRData, _P], Coroutine[Any, Any, _R]]:
"""Handle OTBR errors."""
@wraps(func)
async def _func(self, *args, **kwargs):
async def _func(self: OTBRData, *args: _P.args, **kwargs: _P.kwargs) -> _R:
try:
return await func(self, *args, **kwargs)
except python_otbr_api.OTBRError as exc:

View File

@ -4,7 +4,7 @@
"config_flow": true,
"dependencies": ["thread"],
"documentation": "https://www.home-assistant.io/integrations/otbr",
"requirements": ["python-otbr-api==1.0.1"],
"requirements": ["python-otbr-api==1.0.2"],
"after_dependencies": ["hassio"],
"codeowners": ["@home-assistant/core"],
"iot_class": "local_polling",

View File

@ -17,7 +17,7 @@ if TYPE_CHECKING:
@callback
def async_setup(hass) -> None:
def async_setup(hass: HomeAssistant) -> None:
"""Set up the OTBR Websocket API."""
async_register_command(hass, websocket_info)
@ -44,13 +44,10 @@ async def websocket_info(
connection.send_error(msg["id"], "get_dataset_failed", str(exc))
return
if dataset:
dataset = dataset.hex()
connection.send_result(
msg["id"],
{
"url": data.url,
"active_dataset_tlvs": dataset,
"active_dataset_tlvs": dataset.hex() if dataset else None,
},
)

View File

@ -1984,6 +1984,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.otbr.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.overkiz.*]
check_untyped_defs = true
disallow_incomplete_defs = true

View File

@ -2081,7 +2081,7 @@ python-mystrom==1.1.2
python-nest==4.2.0
# homeassistant.components.otbr
python-otbr-api==1.0.1
python-otbr-api==1.0.2
# homeassistant.components.picnic
python-picnic-api==1.1.0

View File

@ -1471,7 +1471,7 @@ python-miio==0.5.12
python-nest==4.2.0
# homeassistant.components.otbr
python-otbr-api==1.0.1
python-otbr-api==1.0.2
# homeassistant.components.picnic
python-picnic-api==1.1.0