1 """Support for KNX/IP fans."""
3 from __future__
import annotations
6 from typing
import Any, Final
8 from xknx.devices
import Fan
as XknxFan
10 from homeassistant
import config_entries
17 percentage_to_ranged_value,
18 ranged_value_to_percentage,
22 from .
import KNXModule
23 from .const
import KNX_ADDRESS, KNX_MODULE_KEY
24 from .entity
import KnxYamlEntity
25 from .schema
import FanSchema
27 DEFAULT_PERCENTAGE: Final = 50
33 async_add_entities: AddEntitiesCallback,
35 """Set up fan(s) for KNX platform."""
36 knx_module = hass.data[KNX_MODULE_KEY]
37 config: list[ConfigType] = knx_module.config_yaml[Platform.FAN]
43 """Representation of a KNX fan."""
46 _enable_turn_on_off_backwards_compatibility =
False
48 def __init__(self, knx_module: KNXModule, config: ConfigType) ->
None:
49 """Initialize of KNX fan."""
50 max_step = config.get(FanSchema.CONF_MAX_STEP)
52 knx_module=knx_module,
55 name=config[CONF_NAME],
56 group_address_speed=config.get(KNX_ADDRESS),
57 group_address_speed_state=config.get(FanSchema.CONF_STATE_ADDRESS),
58 group_address_oscillation=config.get(
59 FanSchema.CONF_OSCILLATION_ADDRESS
61 group_address_oscillation_state=config.get(
62 FanSchema.CONF_OSCILLATION_STATE_ADDRESS
68 self._step_range: tuple[int, int] |
None = (1, max_step)
if max_step
else None
74 """Set the speed of the fan, as a percentage."""
77 await self.
_device_device.set_speed(step)
79 await self.
_device_device.set_speed(percentage)
83 """Flag supported features."""
85 FanEntityFeature.SET_SPEED
86 | FanEntityFeature.TURN_ON
87 | FanEntityFeature.TURN_OFF
90 if self.
_device_device.supports_oscillation:
91 flags |= FanEntityFeature.OSCILLATE
97 """Return the current speed as a percentage."""
98 if self.
_device_device.current_speed
is None:
103 self._step_range, self.
_device_device.current_speed
105 return self.
_device_device.current_speed
109 """Return the number of speeds the fan supports."""
110 if self._step_range
is None:
111 return super().speed_count
116 percentage: int |
None =
None,
117 preset_mode: str |
None =
None,
120 """Turn on the fan."""
121 if percentage
is None:
127 """Turn the fan off."""
131 """Oscillate the fan."""
132 await self.
_device_device.set_oscillation(oscillating)
136 """Return whether or not the fan is currently oscillating."""
137 return self.
_device_device.current_oscillation
None async_set_percentage(self, int percentage)
None async_turn_off(self, **Any kwargs)
FanEntityFeature supported_features(self)
int|None percentage(self)
None async_set_percentage(self, int percentage)
bool|None oscillating(self)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None __init__(self, KNXModule knx_module, ConfigType config)
None async_oscillate(self, bool oscillating)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
float percentage_to_ranged_value(tuple[float, float] low_high_range, float percentage)
int ranged_value_to_percentage(tuple[float, float] low_high_range, float value)
int int_states_in_range(tuple[float, float] low_high_range)