1 """Fans on Zigbee Home Automation networks."""
3 from __future__
import annotations
8 from zha.application.platforms.fan.const
import FanEntityFeature
as ZHAFanEntityFeature
17 from .entity
import ZHAEntity
18 from .helpers
import (
21 async_add_entities
as zha_async_add_entities,
22 convert_zha_error_to_ha_error,
29 config_entry: ConfigEntry,
30 async_add_entities: AddEntitiesCallback,
32 """Set up the Zigbee Home Automation fan from config entry."""
34 entities_to_create = zha_data.platforms[Platform.FAN]
40 zha_async_add_entities, async_add_entities, ZhaFan, entities_to_create
43 config_entry.async_on_unload(unsub)
47 """Representation of a ZHA fan."""
49 _attr_translation_key: str =
"fan"
50 _enable_turn_on_off_backwards_compatibility =
False
52 def __init__(self, entity_data: EntityData) ->
None:
53 """Initialize the ZHA fan."""
56 zha_features: ZHAFanEntityFeature = self.entity_data.entity.supported_features
58 if ZHAFanEntityFeature.DIRECTION
in zha_features:
59 features |= FanEntityFeature.DIRECTION
60 if ZHAFanEntityFeature.OSCILLATE
in zha_features:
61 features |= FanEntityFeature.OSCILLATE
62 if ZHAFanEntityFeature.PRESET_MODE
in zha_features:
63 features |= FanEntityFeature.PRESET_MODE
64 if ZHAFanEntityFeature.SET_SPEED
in zha_features:
65 features |= FanEntityFeature.SET_SPEED
66 if ZHAFanEntityFeature.TURN_ON
in zha_features:
67 features |= FanEntityFeature.TURN_ON
68 if ZHAFanEntityFeature.TURN_OFF
in zha_features:
69 features |= FanEntityFeature.TURN_OFF
75 """Return the current preset mode."""
76 return self.entity_data.entity.preset_mode
80 """Return the available preset modes."""
81 return self.entity_data.entity.preset_modes
85 """Return the default on percentage."""
86 return self.entity_data.entity.default_on_percentage
90 """Return the range of speeds the fan supports. Off is not included."""
91 return self.entity_data.entity.speed_range
95 """Return the number of speeds the fan supports."""
96 return self.entity_data.entity.speed_count
98 @convert_zha_error_to_ha_error
101 percentage: int |
None =
None,
102 preset_mode: str |
None =
None,
105 """Turn the entity on."""
106 await self.entity_data.entity.async_turn_on(
107 percentage=percentage, preset_mode=preset_mode
111 @convert_zha_error_to_ha_error
113 """Turn the entity off."""
114 await self.entity_data.entity.async_turn_off()
117 @convert_zha_error_to_ha_error
119 """Set the speed percentage of the fan."""
120 await self.entity_data.entity.async_set_percentage(percentage=percentage)
123 @convert_zha_error_to_ha_error
125 """Set the preset mode for the fan."""
126 await self.entity_data.entity.async_set_preset_mode(preset_mode=preset_mode)
131 """Return the current speed percentage."""
132 return self.entity_data.entity.percentage
list[str] preset_modes(self)
None async_set_preset_mode(self, str preset_mode)
str|None preset_mode(self)
int default_on_percentage(self)
tuple[int, int] speed_range(self)
None async_set_percentage(self, int percentage)
int|None percentage(self)
None __init__(self, EntityData entity_data)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
HAZHAData get_zha_data(HomeAssistant hass)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)