From 24e817a17345dff8f31a5c7b84fde16229d48cde Mon Sep 17 00:00:00 2001 From: Glenn Waters Date: Sun, 17 Apr 2022 20:31:37 -0400 Subject: [PATCH] ElkM1 integration add types, part 2 (#70210) --- .strict-typing | 4 +++ homeassistant/components/elkm1/light.py | 17 ++++++--- homeassistant/components/elkm1/switch.py | 6 ++-- mypy.ini | 44 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/.strict-typing b/.strict-typing index cb259dc1307..7d04ab85b1e 100644 --- a/.strict-typing +++ b/.strict-typing @@ -83,6 +83,10 @@ homeassistant.components.dunehd.* homeassistant.components.efergy.* homeassistant.components.elgato.* homeassistant.components.elkm1.__init__ +homeassistant.components.elkm1.discovery +homeassistant.components.elkm1.light +homeassistant.components.elkm1.scene +homeassistant.components.elkm1.switch homeassistant.components.esphome.* homeassistant.components.energy.* homeassistant.components.evil_genius_labs.* diff --git a/homeassistant/components/elkm1/light.py b/homeassistant/components/elkm1/light.py index 46ce9b34a0a..936a71d13e0 100644 --- a/homeassistant/components/elkm1/light.py +++ b/homeassistant/components/elkm1/light.py @@ -1,6 +1,12 @@ """Support for control of ElkM1 lighting (X10, UPB, etc).""" from __future__ import annotations +from typing import Any + +from elkm1_lib.elements import Element +from elkm1_lib.elk import Elk +from elkm1_lib.lights import Light + from homeassistant.components.light import ( ATTR_BRIGHTNESS, COLOR_MODE_BRIGHTNESS, @@ -32,14 +38,15 @@ class ElkLight(ElkEntity, LightEntity): _attr_color_mode = COLOR_MODE_BRIGHTNESS _attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS} + _element: Light - def __init__(self, element, elk, elk_data): + def __init__(self, element: Element, elk: Elk, elk_data: dict[str, Any]) -> None: """Initialize the Elk light.""" super().__init__(element, elk, elk_data) self._brightness = self._element.status @property - def brightness(self): + def brightness(self) -> int: """Get the brightness.""" return self._brightness @@ -48,14 +55,14 @@ class ElkLight(ElkEntity, LightEntity): """Get the current brightness.""" return self._brightness != 0 - def _element_changed(self, element, changeset): + def _element_changed(self, element: Element, changeset: Any) -> None: status = self._element.status if self._element.status != 1 else 100 self._brightness = round(status * 2.55) - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the light.""" self._element.level(round(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55)) - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn off the light.""" self._element.level(0) diff --git a/homeassistant/components/elkm1/switch.py b/homeassistant/components/elkm1/switch.py index df9620dd91b..54588958e61 100644 --- a/homeassistant/components/elkm1/switch.py +++ b/homeassistant/components/elkm1/switch.py @@ -1,6 +1,8 @@ """Support for control of ElkM1 outputs (relays).""" from __future__ import annotations +from typing import Any + from elkm1_lib.outputs import Output from homeassistant.components.switch import SwitchEntity @@ -35,10 +37,10 @@ class ElkOutput(ElkAttachedEntity, SwitchEntity): """Get the current output status.""" return self._element.output_on - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the output.""" self._element.turn_on(0) - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn off the output.""" self._element.turn_off() diff --git a/mypy.ini b/mypy.ini index 9400349f6d7..352acbd4072 100644 --- a/mypy.ini +++ b/mypy.ini @@ -715,6 +715,50 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.elkm1.discovery] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_return_any = true +warn_unreachable = true + +[mypy-homeassistant.components.elkm1.light] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_return_any = true +warn_unreachable = true + +[mypy-homeassistant.components.elkm1.scene] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_return_any = true +warn_unreachable = true + +[mypy-homeassistant.components.elkm1.switch] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.esphome.*] check_untyped_defs = true disallow_incomplete_defs = true