From 1b80c661953bdf347a2091275f6dbb8115a299c7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 17 Nov 2022 10:30:39 +0100 Subject: [PATCH] Adjust type hints for FanEntityFeature (#82241) * Adjust type hints for FanEntityFeature * Adjust template default --- homeassistant/components/bond/fan.py | 2 +- homeassistant/components/esphome/fan.py | 2 +- homeassistant/components/fan/__init__.py | 4 ++-- homeassistant/components/homekit_controller/fan.py | 2 +- homeassistant/components/knx/fan.py | 4 ++-- homeassistant/components/template/fan.py | 14 ++++---------- homeassistant/components/zwave_js/fan.py | 6 +++--- pylint/plugins/hass_enforce_type_hints.py | 4 ++++ 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/bond/fan.py b/homeassistant/components/bond/fan.py index d1121e4a3a8..18ce3777b4e 100644 --- a/homeassistant/components/bond/fan.py +++ b/homeassistant/components/bond/fan.py @@ -82,7 +82,7 @@ class BondFan(BondEntity, FanEntity): self._attr_preset_mode = PRESET_MODE_BREEZE if breeze[0] else None @property - def supported_features(self) -> int: + def supported_features(self) -> FanEntityFeature | int: """Flag supported features.""" features = 0 if self._device.supports_speed(): diff --git a/homeassistant/components/esphome/fan.py b/homeassistant/components/esphome/fan.py index 772a1b8befa..fc8a3e600f3 100644 --- a/homeassistant/components/esphome/fan.py +++ b/homeassistant/components/esphome/fan.py @@ -158,7 +158,7 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity): return _FAN_DIRECTIONS.from_esphome(self._state.direction) @property - def supported_features(self) -> int: + def supported_features(self) -> FanEntityFeature | int: """Flag supported features.""" flags = 0 if self._static_info.supports_oscillation: diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index b65e6f75b3e..b5cd653502f 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -190,7 +190,7 @@ class FanEntity(ToggleEntity): _attr_preset_mode: str | None _attr_preset_modes: list[str] | None _attr_speed_count: int - _attr_supported_features: int = 0 + _attr_supported_features: FanEntityFeature | int = 0 def set_percentage(self, percentage: int) -> None: """Set the speed of the fan, as a percentage.""" @@ -363,7 +363,7 @@ class FanEntity(ToggleEntity): return data @property - def supported_features(self) -> int: + def supported_features(self) -> FanEntityFeature | int: """Flag supported features.""" return self._attr_supported_features diff --git a/homeassistant/components/homekit_controller/fan.py b/homeassistant/components/homekit_controller/fan.py index cdd9c3e803c..dffa323f8ad 100644 --- a/homeassistant/components/homekit_controller/fan.py +++ b/homeassistant/components/homekit_controller/fan.py @@ -95,7 +95,7 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity): return oscillating == 1 @property - def supported_features(self) -> int: + def supported_features(self) -> FanEntityFeature | int: """Flag supported features.""" features = 0 diff --git a/homeassistant/components/knx/fan.py b/homeassistant/components/knx/fan.py index 27f9fb963f7..60db7e95a65 100644 --- a/homeassistant/components/knx/fan.py +++ b/homeassistant/components/knx/fan.py @@ -76,9 +76,9 @@ class KNXFan(KnxEntity, FanEntity): await self._device.set_speed(percentage) @property - def supported_features(self) -> int: + def supported_features(self) -> FanEntityFeature: """Flag supported features.""" - flags: int = FanEntityFeature.SET_SPEED + flags = FanEntityFeature.SET_SPEED if self._device.supports_oscillation: flags |= FanEntityFeature.OSCILLATE diff --git a/homeassistant/components/template/fan.py b/homeassistant/components/template/fan.py index b27a6ee3e51..3d3c17551ca 100644 --- a/homeassistant/components/template/fan.py +++ b/homeassistant/components/template/fan.py @@ -147,7 +147,6 @@ class TemplateFan(TemplateEntity, FanEntity): self._preset_mode_template = config.get(CONF_PRESET_MODE_TEMPLATE) self._oscillating_template = config.get(CONF_OSCILLATING_TEMPLATE) self._direction_template = config.get(CONF_DIRECTION_TEMPLATE) - self._supported_features = 0 self._on_script = Script(hass, config[CONF_ON_ACTION], friendly_name, DOMAIN) self._off_script = Script(hass, config[CONF_OFF_ACTION], friendly_name, DOMAIN) @@ -189,18 +188,13 @@ class TemplateFan(TemplateEntity, FanEntity): self._preset_modes = config.get(CONF_PRESET_MODES) if self._percentage_template: - self._supported_features |= FanEntityFeature.SET_SPEED + self._attr_supported_features |= FanEntityFeature.SET_SPEED if self._preset_mode_template and self._preset_modes: - self._supported_features |= FanEntityFeature.PRESET_MODE + self._attr_supported_features |= FanEntityFeature.PRESET_MODE if self._oscillating_template: - self._supported_features |= FanEntityFeature.OSCILLATE + self._attr_supported_features |= FanEntityFeature.OSCILLATE if self._direction_template: - self._supported_features |= FanEntityFeature.DIRECTION - - @property - def supported_features(self) -> int: - """Flag supported features.""" - return self._supported_features + self._attr_supported_features |= FanEntityFeature.DIRECTION @property def speed_count(self) -> int: diff --git a/homeassistant/components/zwave_js/fan.py b/homeassistant/components/zwave_js/fan.py index 27f73353ca8..bf4942d76cc 100644 --- a/homeassistant/components/zwave_js/fan.py +++ b/homeassistant/components/zwave_js/fan.py @@ -250,9 +250,9 @@ class ValueMappingZwaveFan(ZwaveFan): return len(self.fan_value_mapping.speeds) @property - def supported_features(self) -> int: + def supported_features(self) -> FanEntityFeature: """Flag supported features.""" - flags: int = FanEntityFeature.SET_SPEED + flags = FanEntityFeature.SET_SPEED if self.has_fan_value_mapping and self.fan_value_mapping.presets: flags |= FanEntityFeature.PRESET_MODE @@ -387,7 +387,7 @@ class ZwaveThermostatFan(ZWaveBaseEntity, FanEntity): return list(self._fan_mode.metadata.states.values()) @property - def supported_features(self) -> int: + def supported_features(self) -> FanEntityFeature: """Flag supported features.""" return FanEntityFeature.PRESET_MODE diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 2bb80cac2d7..5da1c563c0f 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -1288,6 +1288,10 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { function_name="preset_modes", return_type=["list[str]", None], ), + TypeHintMatch( + function_name="supported_features", + return_type=["FanEntityFeature", "int"], + ), TypeHintMatch( function_name="set_percentage", arg_types={1: "int"},