Add QNAP QSW to strict typing (#71603)

This commit is contained in:
Álvaro Fernández Rojas 2022-05-09 19:57:27 +02:00 committed by GitHub
parent b9b83c05e9
commit d8e4f6d6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -175,6 +175,7 @@ homeassistant.components.powerwall.*
homeassistant.components.proximity.* homeassistant.components.proximity.*
homeassistant.components.pvoutput.* homeassistant.components.pvoutput.*
homeassistant.components.pure_energie.* homeassistant.components.pure_energie.*
homeassistant.components.qnap_qsw.*
homeassistant.components.rainmachine.* homeassistant.components.rainmachine.*
homeassistant.components.rdw.* homeassistant.components.rdw.*
homeassistant.components.recollect_waste.* homeassistant.components.recollect_waste.*

View File

@ -3,6 +3,7 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any, cast
from aioqsw.exceptions import QswError from aioqsw.exceptions import QswError
from aioqsw.localapi import QnapQswApi from aioqsw.localapi import QnapQswApi
@ -18,7 +19,7 @@ SCAN_INTERVAL = timedelta(seconds=60)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
class QswUpdateCoordinator(DataUpdateCoordinator): class QswUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
"""Class to manage fetching data from the QNAP QSW device.""" """Class to manage fetching data from the QNAP QSW device."""
def __init__(self, hass: HomeAssistant, qsw: QnapQswApi) -> None: def __init__(self, hass: HomeAssistant, qsw: QnapQswApi) -> None:
@ -30,13 +31,14 @@ class QswUpdateCoordinator(DataUpdateCoordinator):
_LOGGER, _LOGGER,
name=DOMAIN, name=DOMAIN,
update_interval=SCAN_INTERVAL, update_interval=SCAN_INTERVAL,
update_method=self._async_update,
) )
async def _async_update_data(self): async def _async_update(self) -> dict[str, Any]:
"""Update data via library.""" """Update data via library."""
async with async_timeout.timeout(QSW_TIMEOUT_SEC): async with async_timeout.timeout(QSW_TIMEOUT_SEC):
try: try:
await self.qsw.update() await self.qsw.update()
except QswError as error: except QswError as error:
raise UpdateFailed(error) from error raise UpdateFailed(error) from error
return self.qsw.data() return cast(dict[str, Any], self.qsw.data())

View File

@ -1688,6 +1688,17 @@ no_implicit_optional = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.qnap_qsw.*]
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.rainmachine.*] [mypy-homeassistant.components.rainmachine.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true