Adjust type hints for FanEntityFeature (#82241)
* Adjust type hints for FanEntityFeature * Adjust template default
This commit is contained in:
parent
3d00923665
commit
1b80c66195
8 changed files with 18 additions and 20 deletions
|
@ -82,7 +82,7 @@ class BondFan(BondEntity, FanEntity):
|
||||||
self._attr_preset_mode = PRESET_MODE_BREEZE if breeze[0] else None
|
self._attr_preset_mode = PRESET_MODE_BREEZE if breeze[0] else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> FanEntityFeature | int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
features = 0
|
features = 0
|
||||||
if self._device.supports_speed():
|
if self._device.supports_speed():
|
||||||
|
|
|
@ -158,7 +158,7 @@ class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity):
|
||||||
return _FAN_DIRECTIONS.from_esphome(self._state.direction)
|
return _FAN_DIRECTIONS.from_esphome(self._state.direction)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> FanEntityFeature | int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
flags = 0
|
flags = 0
|
||||||
if self._static_info.supports_oscillation:
|
if self._static_info.supports_oscillation:
|
||||||
|
|
|
@ -190,7 +190,7 @@ class FanEntity(ToggleEntity):
|
||||||
_attr_preset_mode: str | None
|
_attr_preset_mode: str | None
|
||||||
_attr_preset_modes: list[str] | None
|
_attr_preset_modes: list[str] | None
|
||||||
_attr_speed_count: int
|
_attr_speed_count: int
|
||||||
_attr_supported_features: int = 0
|
_attr_supported_features: FanEntityFeature | int = 0
|
||||||
|
|
||||||
def set_percentage(self, percentage: int) -> None:
|
def set_percentage(self, percentage: int) -> None:
|
||||||
"""Set the speed of the fan, as a percentage."""
|
"""Set the speed of the fan, as a percentage."""
|
||||||
|
@ -363,7 +363,7 @@ class FanEntity(ToggleEntity):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> FanEntityFeature | int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return self._attr_supported_features
|
return self._attr_supported_features
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ class BaseHomeKitFan(HomeKitEntity, FanEntity):
|
||||||
return oscillating == 1
|
return oscillating == 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> FanEntityFeature | int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
features = 0
|
features = 0
|
||||||
|
|
||||||
|
|
|
@ -76,9 +76,9 @@ class KNXFan(KnxEntity, FanEntity):
|
||||||
await self._device.set_speed(percentage)
|
await self._device.set_speed(percentage)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> FanEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
flags: int = FanEntityFeature.SET_SPEED
|
flags = FanEntityFeature.SET_SPEED
|
||||||
|
|
||||||
if self._device.supports_oscillation:
|
if self._device.supports_oscillation:
|
||||||
flags |= FanEntityFeature.OSCILLATE
|
flags |= FanEntityFeature.OSCILLATE
|
||||||
|
|
|
@ -147,7 +147,6 @@ class TemplateFan(TemplateEntity, FanEntity):
|
||||||
self._preset_mode_template = config.get(CONF_PRESET_MODE_TEMPLATE)
|
self._preset_mode_template = config.get(CONF_PRESET_MODE_TEMPLATE)
|
||||||
self._oscillating_template = config.get(CONF_OSCILLATING_TEMPLATE)
|
self._oscillating_template = config.get(CONF_OSCILLATING_TEMPLATE)
|
||||||
self._direction_template = config.get(CONF_DIRECTION_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._on_script = Script(hass, config[CONF_ON_ACTION], friendly_name, DOMAIN)
|
||||||
self._off_script = Script(hass, config[CONF_OFF_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)
|
self._preset_modes = config.get(CONF_PRESET_MODES)
|
||||||
|
|
||||||
if self._percentage_template:
|
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:
|
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:
|
if self._oscillating_template:
|
||||||
self._supported_features |= FanEntityFeature.OSCILLATE
|
self._attr_supported_features |= FanEntityFeature.OSCILLATE
|
||||||
if self._direction_template:
|
if self._direction_template:
|
||||||
self._supported_features |= FanEntityFeature.DIRECTION
|
self._attr_supported_features |= FanEntityFeature.DIRECTION
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self) -> int:
|
|
||||||
"""Flag supported features."""
|
|
||||||
return self._supported_features
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def speed_count(self) -> int:
|
def speed_count(self) -> int:
|
||||||
|
|
|
@ -250,9 +250,9 @@ class ValueMappingZwaveFan(ZwaveFan):
|
||||||
return len(self.fan_value_mapping.speeds)
|
return len(self.fan_value_mapping.speeds)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> FanEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
flags: int = FanEntityFeature.SET_SPEED
|
flags = FanEntityFeature.SET_SPEED
|
||||||
if self.has_fan_value_mapping and self.fan_value_mapping.presets:
|
if self.has_fan_value_mapping and self.fan_value_mapping.presets:
|
||||||
flags |= FanEntityFeature.PRESET_MODE
|
flags |= FanEntityFeature.PRESET_MODE
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ class ZwaveThermostatFan(ZWaveBaseEntity, FanEntity):
|
||||||
return list(self._fan_mode.metadata.states.values())
|
return list(self._fan_mode.metadata.states.values())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> FanEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return FanEntityFeature.PRESET_MODE
|
return FanEntityFeature.PRESET_MODE
|
||||||
|
|
||||||
|
|
|
@ -1288,6 +1288,10 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
||||||
function_name="preset_modes",
|
function_name="preset_modes",
|
||||||
return_type=["list[str]", None],
|
return_type=["list[str]", None],
|
||||||
),
|
),
|
||||||
|
TypeHintMatch(
|
||||||
|
function_name="supported_features",
|
||||||
|
return_type=["FanEntityFeature", "int"],
|
||||||
|
),
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="set_percentage",
|
function_name="set_percentage",
|
||||||
arg_types={1: "int"},
|
arg_types={1: "int"},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue