Add strict typing to Tractive integration (#56948)

* Strict typing

* Add few missing types

* Run hassfest

* Fix mypy errors

* Use List instead of list
This commit is contained in:
Maciej Bieniek 2021-10-03 09:13:12 +02:00 committed by GitHub
parent 1aeab65f56
commit f3c76fb859
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 166 additions and 134 deletions

View file

@ -3,7 +3,7 @@ from __future__ import annotations
from dataclasses import dataclass
import logging
from typing import Any, Literal
from typing import Any, Final, Literal, cast
from aiotractive.exceptions import TractiveError
@ -26,7 +26,7 @@ from .const import (
)
from .entity import TractiveEntity
_LOGGER = logging.getLogger(__name__)
_LOGGER: Final = logging.getLogger(__name__)
@dataclass
@ -43,7 +43,7 @@ class TractiveSwitchEntityDescription(
"""Class describing Tractive switch entities."""
SWITCH_TYPES: tuple[TractiveSwitchEntityDescription, ...] = (
SWITCH_TYPES: Final[tuple[TractiveSwitchEntityDescription, ...]] = (
TractiveSwitchEntityDescription(
key=ATTR_BUZZER,
name="Tracker Buzzer",
@ -162,12 +162,14 @@ class TractiveSwitch(TractiveEntity, SwitchEntity):
async def async_set_buzzer(self, active: bool) -> dict[str, Any]:
"""Set the buzzer on/off."""
return await self._tracker.set_buzzer_active(active)
return cast(dict[str, Any], await self._tracker.set_buzzer_active(active))
async def async_set_led(self, active: bool) -> dict[str, Any]:
"""Set the LED on/off."""
return await self._tracker.set_led_active(active)
return cast(dict[str, Any], await self._tracker.set_led_active(active))
async def async_set_live_tracking(self, active: bool) -> dict[str, Any]:
"""Set the live tracking on/off."""
return await self._tracker.set_live_tracking_active(active)
return cast(
dict[str, Any], await self._tracker.set_live_tracking_active(active)
)