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.shelly.*
homeassistant.components.simplisafe.*
homeassistant.components.skybell.*
homeassistant.components.slack.*
homeassistant.components.sleepiq.*
homeassistant.components.smhi.*

View file

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

View file

@ -2072,6 +2072,16 @@ disallow_untyped_defs = true
warn_return_any = 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.*]
check_untyped_defs = true
disallow_incomplete_defs = true