Skip to content

Commit

Permalink
Fix supported_features for ZHA fans (#122813)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey authored Jul 30, 2024
1 parent 36c0104 commit 004ecce
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions homeassistant/components/zha/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import functools
from typing import Any

from zha.application.platforms.fan.const import FanEntityFeature as ZHAFanEntityFeature

from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
Expand All @@ -15,6 +17,7 @@
from .entity import ZHAEntity
from .helpers import (
SIGNAL_ADD_ENTITIES,
EntityData,
async_add_entities as zha_async_add_entities,
convert_zha_error_to_ha_error,
get_zha_data,
Expand Down Expand Up @@ -43,14 +46,30 @@ async def async_setup_entry(
class ZhaFan(FanEntity, ZHAEntity):
"""Representation of a ZHA fan."""

_attr_supported_features = (
FanEntityFeature.SET_SPEED
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)
_attr_translation_key: str = "fan"
_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
def preset_mode(self) -> str | None:
"""Return the current preset mode."""
Expand Down

0 comments on commit 004ecce

Please sign in to comment.