mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix supported_features for ZHA fans (#122813)
This commit is contained in:
parent
36c01042c1
commit
004eccec89
@ -5,6 +5,8 @@ from __future__ import annotations
|
|||||||
import functools
|
import functools
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from zha.application.platforms.fan.const import FanEntityFeature as ZHAFanEntityFeature
|
||||||
|
|
||||||
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
@ -15,6 +17,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from .entity import ZHAEntity
|
from .entity import ZHAEntity
|
||||||
from .helpers import (
|
from .helpers import (
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
|
EntityData,
|
||||||
async_add_entities as zha_async_add_entities,
|
async_add_entities as zha_async_add_entities,
|
||||||
convert_zha_error_to_ha_error,
|
convert_zha_error_to_ha_error,
|
||||||
get_zha_data,
|
get_zha_data,
|
||||||
@ -43,14 +46,30 @@ async def async_setup_entry(
|
|||||||
class ZhaFan(FanEntity, ZHAEntity):
|
class ZhaFan(FanEntity, ZHAEntity):
|
||||||
"""Representation of a ZHA fan."""
|
"""Representation of a ZHA fan."""
|
||||||
|
|
||||||
_attr_supported_features = (
|
|
||||||
FanEntityFeature.SET_SPEED
|
|
||||||
| FanEntityFeature.TURN_OFF
|
|
||||||
| FanEntityFeature.TURN_ON
|
|
||||||
)
|
|
||||||
_attr_translation_key: str = "fan"
|
_attr_translation_key: str = "fan"
|
||||||
_enable_turn_on_off_backwards_compatibility = False
|
_enable_turn_on_off_backwards_compatibility = False
|
||||||
|
|
||||||
|
def __init__(self, entity_data: EntityData) -> None:
|
||||||
|
"""Initialize the ZHA fan."""
|
||||||
|
super().__init__(entity_data)
|
||||||
|
features = FanEntityFeature(0)
|
||||||
|
zha_features: ZHAFanEntityFeature = self.entity_data.entity.supported_features
|
||||||
|
|
||||||
|
if ZHAFanEntityFeature.DIRECTION in zha_features:
|
||||||
|
features |= FanEntityFeature.DIRECTION
|
||||||
|
if ZHAFanEntityFeature.OSCILLATE in zha_features:
|
||||||
|
features |= FanEntityFeature.OSCILLATE
|
||||||
|
if ZHAFanEntityFeature.PRESET_MODE in zha_features:
|
||||||
|
features |= FanEntityFeature.PRESET_MODE
|
||||||
|
if ZHAFanEntityFeature.SET_SPEED in zha_features:
|
||||||
|
features |= FanEntityFeature.SET_SPEED
|
||||||
|
if ZHAFanEntityFeature.TURN_ON in zha_features:
|
||||||
|
features |= FanEntityFeature.TURN_ON
|
||||||
|
if ZHAFanEntityFeature.TURN_OFF in zha_features:
|
||||||
|
features |= FanEntityFeature.TURN_OFF
|
||||||
|
|
||||||
|
self._attr_supported_features = features
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preset_mode(self) -> str | None:
|
def preset_mode(self) -> str | None:
|
||||||
"""Return the current preset mode."""
|
"""Return the current preset mode."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user