1 """Support for Fjäråskupan fans."""
3 from __future__
import annotations
7 from fjaraskupan
import (
8 COMMAND_AFTERCOOKINGTIMERAUTO,
9 COMMAND_AFTERCOOKINGTIMERMANUAL,
10 COMMAND_AFTERCOOKINGTIMEROFF,
23 ordered_list_item_to_percentage,
24 percentage_to_ordered_list_item,
27 from .
import async_setup_entry_platform
28 from .coordinator
import FjaraskupanCoordinator
30 ORDERED_NAMED_FAN_SPEEDS = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"]
32 PRESET_MODE_NORMAL =
"normal"
33 PRESET_MODE_AFTER_COOKING_MANUAL =
"after_cooking_manual"
34 PRESET_MODE_AFTER_COOKING_AUTO =
"after_cooking_auto"
37 PRESET_MODE_AFTER_COOKING_AUTO,
38 PRESET_MODE_AFTER_COOKING_MANUAL,
42 PRESET_MODE_AFTER_COOKING_MANUAL: COMMAND_AFTERCOOKINGTIMERMANUAL,
43 PRESET_MODE_AFTER_COOKING_AUTO: COMMAND_AFTERCOOKINGTIMERAUTO,
44 PRESET_MODE_NORMAL: COMMAND_AFTERCOOKINGTIMEROFF,
49 """The preset is unsupported."""
54 config_entry: ConfigEntry,
55 async_add_entities: AddEntitiesCallback,
57 """Set up sensors dynamically through discovery."""
59 def _constructor(coordinator: FjaraskupanCoordinator):
60 return [Fan(coordinator, coordinator.device_info)]
68 _attr_supported_features = (
69 FanEntityFeature.SET_SPEED
70 | FanEntityFeature.PRESET_MODE
71 | FanEntityFeature.TURN_OFF
72 | FanEntityFeature.TURN_ON
74 _enable_turn_on_off_backwards_compatibility =
False
75 _attr_has_entity_name =
True
80 coordinator: FjaraskupanCoordinator,
81 device_info: DeviceInfo,
83 """Init fan entity."""
100 await device.send_command(COMMAND_STOP_FAN)
102 new_speed = percentage_to_ordered_list_item(
103 ORDERED_NAMED_FAN_SPEEDS, percentage
105 await device.send_fan_speed(
int(new_speed))
109 percentage: int |
None =
None,
110 preset_mode: str |
None =
None,
113 """Turn on the fan."""
115 if preset_mode
is None:
118 if percentage
is None:
121 new_speed = percentage_to_ordered_list_item(
122 ORDERED_NAMED_FAN_SPEEDS, percentage
127 if command := PRESET_TO_COMMAND.get(preset_mode):
128 await device.send_command(command)
132 if preset_mode == PRESET_MODE_NORMAL:
133 await device.send_fan_speed(
int(new_speed))
134 elif preset_mode == PRESET_MODE_AFTER_COOKING_MANUAL:
135 await device.send_after_cooking(
int(new_speed))
136 elif preset_mode == PRESET_MODE_AFTER_COOKING_AUTO:
137 await device.send_after_cooking(0)
140 """Set new preset mode."""
141 command = PRESET_TO_COMMAND[preset_mode]
143 await device.send_command(command)
146 """Turn the entity off."""
148 await device.send_command(COMMAND_STOP_FAN)
152 """Return the number of speeds the fan supports."""
153 return len(ORDERED_NAMED_FAN_SPEEDS)
157 """Return the current speed."""
162 """Return true if fan is on."""
167 """Return the current preset mode."""
172 """Return a list of available preset modes."""
176 """Handle data update."""
182 self.
_percentage_percentage = ordered_list_item_to_percentage(
183 ORDERED_NAMED_FAN_SPEEDS,
str(data.fan_speed)
188 if data.after_cooking_on:
189 if data.after_cooking_fan_speed:
190 self.
_preset_mode_preset_mode = PRESET_MODE_AFTER_COOKING_MANUAL
192 self.
_preset_mode_preset_mode = PRESET_MODE_AFTER_COOKING_AUTO
198 """Handle data update."""
AsyncIterator[Device] async_connect_and_update(self)
None __init__(self, FjaraskupanCoordinator coordinator, DeviceInfo device_info)
None _update_from_device_data(self, State|None data)
None async_set_percentage(self, int percentage)
None _handle_coordinator_update(self)
None async_turn_off(self, **Any kwargs)
None async_set_preset_mode(self, str preset_mode)
int|None percentage(self)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
list[str]|None preset_modes(self)
str|None preset_mode(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_setup_entry_platform(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities, Callable[[FjaraskupanCoordinator], list[Entity]] constructor)