From f3f5fca0b90ea394f885ff5d523c91f173b7cbb8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 20 May 2025 12:00:10 +0200 Subject: [PATCH] Mark turn_on/turn_off/toggle as mandatory in pylint plugin (#145249) * Mark turn_on/turn_off/toggle as mandatory in pylint plugin * Fixes --- homeassistant/components/rainbird/switch.py | 5 +++-- homeassistant/components/triggercmd/switch.py | 5 +++-- homeassistant/components/tuya/humidifier.py | 5 +++-- pylint/plugins/hass_enforce_type_hints.py | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/rainbird/switch.py b/homeassistant/components/rainbird/switch.py index f188350138e..5ba30d5803b 100644 --- a/homeassistant/components/rainbird/switch.py +++ b/homeassistant/components/rainbird/switch.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging +from typing import Any from pyrainbird.exceptions import RainbirdApiException, RainbirdDeviceBusyException import voluptuous as vol @@ -91,7 +92,7 @@ class RainBirdSwitch(CoordinatorEntity[RainbirdUpdateCoordinator], SwitchEntity) """Return state attributes.""" return {"zone": self._zone} - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" try: await self.coordinator.controller.irrigate_zone( @@ -111,7 +112,7 @@ class RainBirdSwitch(CoordinatorEntity[RainbirdUpdateCoordinator], SwitchEntity) self.async_write_ha_state() await self.coordinator.async_request_refresh() - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn the switch off.""" try: await self.coordinator.controller.stop_irrigation() diff --git a/homeassistant/components/triggercmd/switch.py b/homeassistant/components/triggercmd/switch.py index e04cf5ee7e8..e03ff333751 100644 --- a/homeassistant/components/triggercmd/switch.py +++ b/homeassistant/components/triggercmd/switch.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging +from typing import Any from triggercmd import client, ha @@ -59,13 +60,13 @@ class TRIGGERcmdSwitch(SwitchEntity): """Return True if hub is available.""" return self._switch.hub.online - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" await self.trigger("on") self._attr_is_on = True self.async_write_ha_state() - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn the switch off.""" await self.trigger("off") self._attr_is_on = False diff --git a/homeassistant/components/tuya/humidifier.py b/homeassistant/components/tuya/humidifier.py index 6c47148eeda..36fcf8f52aa 100644 --- a/homeassistant/components/tuya/humidifier.py +++ b/homeassistant/components/tuya/humidifier.py @@ -3,6 +3,7 @@ from __future__ import annotations from dataclasses import dataclass +from typing import Any from tuya_sharing import CustomerDevice, Manager @@ -165,11 +166,11 @@ class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity): return round(self._current_humidity.scale_value(current_humidity)) - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn the device on.""" self._send_command([{"code": self._switch_dpcode, "value": True}]) - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn the device off.""" self._send_command([{"code": self._switch_dpcode, "value": False}]) diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 60da232f938..bc1af17f97a 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -801,18 +801,21 @@ _TOGGLE_ENTITY_MATCH: list[TypeHintMatch] = [ kwargs_type="Any", return_type=None, has_async_counterpart=True, + mandatory=True, ), TypeHintMatch( function_name="turn_off", kwargs_type="Any", return_type=None, has_async_counterpart=True, + mandatory=True, ), TypeHintMatch( function_name="toggle", kwargs_type="Any", return_type=None, has_async_counterpart=True, + mandatory=True, ), ] _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {