From 9850709b37fdfa704ac3db4c45a2660880a7ca65 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Fri, 7 Oct 2022 10:28:05 -0400 Subject: [PATCH] Add strict typing to Skybell (#79800) --- .strict-typing | 1 + homeassistant/components/skybell/sensor.py | 18 +++++++++++++----- mypy.ini | 10 ++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.strict-typing b/.strict-typing index 635356f4950..466312a30a9 100644 --- a/.strict-typing +++ b/.strict-typing @@ -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.* diff --git a/homeassistant/components/skybell/sensor.py b/homeassistant/components/skybell/sensor.py index 7acc30d0bd0..ff3ba47ae85 100644 --- a/homeassistant/components/skybell/sensor.py +++ b/homeassistant/components/skybell/sensor.py @@ -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) diff --git a/mypy.ini b/mypy.ini index 267e856aa09..819f461454b 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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