Add strict typing to Skybell (#79800)

This commit is contained in:
Robert Hillis 2022-10-07 10:28:05 -04:00 committed by GitHub
parent e1d3ba6ff1
commit 9850709b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -232,6 +232,7 @@ homeassistant.components.sensor.*
homeassistant.components.senz.* homeassistant.components.senz.*
homeassistant.components.shelly.* homeassistant.components.shelly.*
homeassistant.components.simplisafe.* homeassistant.components.simplisafe.*
homeassistant.components.skybell.*
homeassistant.components.slack.* homeassistant.components.slack.*
homeassistant.components.sleepiq.* homeassistant.components.sleepiq.*
homeassistant.components.smhi.* homeassistant.components.smhi.*

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any from datetime import datetime
from aioskybell import SkybellDevice from aioskybell import SkybellDevice
from aioskybell.helpers import const as CONST from aioskybell.helpers import const as CONST
@ -17,15 +17,23 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from .entity import DOMAIN, SkybellEntity from .entity import DOMAIN, SkybellEntity
@dataclass @dataclass
class SkybellSensorEntityDescription(SensorEntityDescription): class SkybellSensorEntityDescriptionMixIn:
"""Class to describe a Skybell sensor.""" """Mixin for Skybell sensor."""
value_fn: Callable[[SkybellDevice], Any] = lambda val: val value_fn: Callable[[SkybellDevice], StateType | datetime]
@dataclass
class SkybellSensorEntityDescription(
SensorEntityDescription, SkybellSensorEntityDescriptionMixIn
):
"""Class to describe a Skybell sensor."""
SENSOR_TYPES: tuple[SkybellSensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[SkybellSensorEntityDescription, ...] = (
@ -110,6 +118,6 @@ class SkybellSensor(SkybellEntity, SensorEntity):
entity_description: SkybellSensorEntityDescription entity_description: SkybellSensorEntityDescription
@property @property
def native_value(self) -> int: def native_value(self) -> StateType | datetime:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.entity_description.value_fn(self._device) return self.entity_description.value_fn(self._device)

View File

@ -2072,6 +2072,16 @@ disallow_untyped_defs = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.skybell.*]
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.slack.*] [mypy-homeassistant.components.slack.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true