1 """Support for TPLink Fan devices."""
7 from kasa
import Device, Module
8 from kasa.interfaces
import Fan
as FanInterface
14 percentage_to_ranged_value,
15 ranged_value_to_percentage,
19 from .
import TPLinkConfigEntry
20 from .coordinator
import TPLinkDataUpdateCoordinator
21 from .entity
import CoordinatedTPLinkEntity, async_refresh_after
23 _LOGGER = logging.getLogger(__name__)
28 config_entry: TPLinkConfigEntry,
29 async_add_entities: AddEntitiesCallback,
32 data = config_entry.runtime_data
33 parent_coordinator = data.parent_coordinator
34 device = parent_coordinator.device
35 entities: list[CoordinatedTPLinkEntity] = []
36 if Module.Fan
in device.modules:
39 device, parent_coordinator, fan_module=device.modules[Module.Fan]
46 fan_module=child.modules[Module.Fan],
49 for child
in device.children
50 if Module.Fan
in child.modules
59 """Representation of a fan for a TPLink Fan device."""
62 _attr_supported_features = (
63 FanEntityFeature.SET_SPEED
64 | FanEntityFeature.TURN_OFF
65 | FanEntityFeature.TURN_ON
67 _enable_turn_on_off_backwards_compatibility =
False
72 coordinator: TPLinkDataUpdateCoordinator,
73 fan_module: FanInterface,
74 parent: Device |
None =
None,
76 """Initialize the fan."""
79 self.
_attr_name_attr_name =
None if parent
is None else device.alias
81 super().
__init__(device, coordinator, parent=parent)
86 percentage: int |
None =
None,
87 preset_mode: str |
None =
None,
90 """Turn on the fan."""
91 if percentage
is not None:
92 value_in_range = math.ceil(
96 value_in_range = SPEED_RANGE[1]
97 await self.
fan_modulefan_module.set_fan_speed_level(value_in_range)
101 """Turn the fan off."""
102 await self.
fan_modulefan_module.set_fan_speed_level(0)
105 """Set the speed percentage of the fan."""
107 await self.
fan_modulefan_module.set_fan_speed_level(value_in_range)
111 """Update the entity's attributes."""
112 fan_speed = self.
fan_modulefan_module.fan_speed_level
None __init__(self, Device device, TPLinkDataUpdateCoordinator coordinator, FanInterface fan_module, Device|None parent=None)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None _async_update_attrs(self)
None async_set_percentage(self, int percentage)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, TPLinkConfigEntry 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)