From 68141873cdad82f1edcfd13781e947cc09fc0d9f Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 4 Mar 2024 19:50:33 +0100 Subject: [PATCH] Enable strict typing of homeworks (#112267) --- .strict-typing | 1 + .../components/homeworks/__init__.py | 17 +++++++++---- homeassistant/components/homeworks/light.py | 24 +++++++++---------- mypy.ini | 10 ++++++++ 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.strict-typing b/.strict-typing index 74535719bb3..fb621d3e53a 100644 --- a/.strict-typing +++ b/.strict-typing @@ -228,6 +228,7 @@ homeassistant.components.homekit_controller.select homeassistant.components.homekit_controller.storage homeassistant.components.homekit_controller.utils homeassistant.components.homewizard.* +homeassistant.components.homeworks.* homeassistant.components.http.* homeassistant.components.huawei_lte.* homeassistant.components.humidifier.* diff --git a/homeassistant/components/homeworks/__init__.py b/homeassistant/components/homeworks/__init__.py index 05ba4d02454..4e620dac27f 100644 --- a/homeassistant/components/homeworks/__init__.py +++ b/homeassistant/components/homeworks/__init__.py @@ -17,7 +17,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_STOP, Platform, ) -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send @@ -118,7 +118,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except (ConnectionError, OSError) as err: raise ConfigEntryNotReady from err - def cleanup(event): + def cleanup(event: Event) -> None: controller.close() entry.async_on_unload(hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, cleanup)) @@ -158,7 +158,7 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: await hass.config_entries.async_reload(entry.entry_id) -def calculate_unique_id(controller_id, addr, idx): +def calculate_unique_id(controller_id: str, addr: str, idx: int) -> str: """Calculate entity unique id.""" return f"homeworks.{controller_id}.{addr}.{idx}" @@ -194,7 +194,14 @@ class HomeworksKeypad: instead of a sensor entity in hass. """ - def __init__(self, hass, controller, controller_id, addr, name): + def __init__( + self, + hass: HomeAssistant, + controller: Homeworks, + controller_id: str, + addr: str, + name: str, + ) -> None: """Register callback that will be used for signals.""" self._addr = addr self._controller = controller @@ -208,7 +215,7 @@ class HomeworksKeypad: ) @callback - def _update_callback(self, msg_type, values): + def _update_callback(self, msg_type: str, values: list[Any]) -> None: """Fire events if button is pressed or released.""" if msg_type == HW_BUTTON_PRESSED: diff --git a/homeassistant/components/homeworks/light.py b/homeassistant/components/homeworks/light.py index 98f327bdfce..3e6836c75b8 100644 --- a/homeassistant/components/homeworks/light.py +++ b/homeassistant/components/homeworks/light.py @@ -4,7 +4,7 @@ from __future__ import annotations import logging from typing import Any -from pyhomeworks.pyhomeworks import HW_LIGHT_CHANGED +from pyhomeworks.pyhomeworks import HW_LIGHT_CHANGED, Homeworks from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity from homeassistant.config_entries import ConfigEntry @@ -47,12 +47,12 @@ class HomeworksLight(HomeworksEntity, LightEntity): def __init__( self, - controller, - controller_id, - addr, - name, - rate, - ): + controller: Homeworks, + controller_id: str, + addr: str, + name: str, + rate: float, + ) -> None: """Create device with Addr, name, and rate.""" super().__init__(controller, controller_id, addr, 0, name) self._rate = rate @@ -83,28 +83,28 @@ class HomeworksLight(HomeworksEntity, LightEntity): self._set_brightness(0) @property - def brightness(self): + def brightness(self) -> int: """Control the brightness.""" return self._level - def _set_brightness(self, level): + def _set_brightness(self, level: int) -> None: """Send the brightness level to the device.""" self._controller.fade_dim( float((level * 100.0) / 255.0), self._rate, 0, self._addr ) @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, str]: """Supported attributes.""" return {"homeworks_address": self._addr} @property - def is_on(self): + def is_on(self) -> bool: """Is the light on/off.""" return self._level != 0 @callback - def _update_callback(self, msg_type, values): + def _update_callback(self, msg_type: str, values: list[Any]) -> None: """Process device specific messages.""" if msg_type == HW_LIGHT_CHANGED: diff --git a/mypy.ini b/mypy.ini index 224508fb6bc..a8b146059fc 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2041,6 +2041,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.homeworks.*] +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.http.*] check_untyped_defs = true disallow_incomplete_defs = true