From 528a50947925f2a07bfc6f3e5db50d5679eb59a7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 23 May 2025 15:28:41 +0200 Subject: [PATCH] Mark light methods and properties as mandatory in pylint plugin (#145510) --- homeassistant/components/blebox/light.py | 10 +++++----- homeassistant/components/xiaomi_miio/light.py | 2 +- pylint/plugins/hass_enforce_type_hints.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/blebox/light.py b/homeassistant/components/blebox/light.py index 86ec8993779..75900ca7d97 100644 --- a/homeassistant/components/blebox/light.py +++ b/homeassistant/components/blebox/light.py @@ -84,7 +84,7 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): return color_util.color_temperature_mired_to_kelvin(self._feature.color_temp) @property - def color_mode(self): + def color_mode(self) -> ColorMode: """Return the color mode. Set values to _attr_ibutes if needed. @@ -92,7 +92,7 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): return COLOR_MODE_MAP.get(self._feature.color_mode, ColorMode.ONOFF) @property - def supported_color_modes(self): + def supported_color_modes(self) -> set[ColorMode]: """Return supported color modes.""" return {self.color_mode} @@ -107,7 +107,7 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): return self._feature.effect @property - def rgb_color(self): + def rgb_color(self) -> tuple[int, int, int] | None: """Return value for rgb.""" if (rgb_hex := self._feature.rgb_hex) is None: return None @@ -118,14 +118,14 @@ class BleBoxLightEntity(BleBoxEntity[blebox_uniapi.light.Light], LightEntity): ) @property - def rgbw_color(self): + def rgbw_color(self) -> tuple[int, int, int, int] | None: """Return the hue and saturation.""" if (rgbw_hex := self._feature.rgbw_hex) is None: return None return tuple(blebox_uniapi.light.Light.rgb_hex_to_rgb_list(rgbw_hex)[0:4]) @property - def rgbww_color(self): + def rgbww_color(self) -> tuple[int, int, int, int, int] | None: """Return value for rgbww.""" if (rgbww_hex := self._feature.rgbww_hex) is None: return None diff --git a/homeassistant/components/xiaomi_miio/light.py b/homeassistant/components/xiaomi_miio/light.py index 781ac0b4acd..7c1c1b7bfb0 100644 --- a/homeassistant/components/xiaomi_miio/light.py +++ b/homeassistant/components/xiaomi_miio/light.py @@ -841,7 +841,7 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb): return self._hs_color @property - def color_mode(self): + def color_mode(self) -> ColorMode: """Return the color mode of the light.""" if self.hs_color: return ColorMode.HS diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index a6d77611926..57dff037f56 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -1816,6 +1816,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { TypeHintMatch( function_name="color_mode", return_type=["ColorMode", "str", None], + mandatory=True, ), TypeHintMatch( function_name="hs_color", @@ -1828,26 +1829,32 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { TypeHintMatch( function_name="rgb_color", return_type=["tuple[int, int, int]", None], + mandatory=True, ), TypeHintMatch( function_name="rgbw_color", return_type=["tuple[int, int, int, int]", None], + mandatory=True, ), TypeHintMatch( function_name="rgbww_color", return_type=["tuple[int, int, int, int, int]", None], + mandatory=True, ), TypeHintMatch( function_name="color_temp", return_type=["int", None], + mandatory=True, ), TypeHintMatch( function_name="min_mireds", return_type="int", + mandatory=True, ), TypeHintMatch( function_name="max_mireds", return_type="int", + mandatory=True, ), TypeHintMatch( function_name="effect_list", @@ -1864,10 +1871,12 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { TypeHintMatch( function_name="supported_color_modes", return_type=["set[ColorMode]", "set[str]", None], + mandatory=True, ), TypeHintMatch( function_name="supported_features", return_type="LightEntityFeature", + mandatory=True, ), TypeHintMatch( function_name="turn_on", @@ -1892,6 +1901,7 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { kwargs_type="Any", return_type=None, has_async_counterpart=True, + mandatory=True, ), ], ),