1 """Support for Freedompro fan."""
3 from __future__
import annotations
8 from pyfreedompro
import put_state
19 from .const
import DOMAIN
20 from .coordinator
import FreedomproDataUpdateCoordinator
24 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
26 """Set up Freedompro fan."""
27 api_key: str = entry.data[CONF_API_KEY]
28 coordinator: FreedomproDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
31 for device
in coordinator.data
32 if device[
"type"] ==
"fan"
37 """Representation of a Freedompro fan."""
39 _attr_has_entity_name =
True
43 _enable_turn_on_off_backwards_compatibility =
False
49 device: dict[str, Any],
50 coordinator: FreedomproDataUpdateCoordinator,
52 """Initialize the Freedompro fan."""
54 self.
_session_session = aiohttp_client.async_get_clientsession(hass)
60 (DOMAIN, device[
"uid"]),
62 manufacturer=
"Freedompro",
67 FanEntityFeature.TURN_OFF | FanEntityFeature.TURN_ON
74 """Return True if entity is on."""
79 """Handle updated data from the coordinator."""
83 for device
in self.coordinator.data
84 if device[
"uid"] == self.
unique_idunique_id
88 if device
is not None and "state" in device:
89 state = device[
"state"]
91 if "rotationSpeed" in state:
96 """When entity is added to hass."""
102 percentage: int |
None =
None,
103 preset_mode: str |
None =
None,
106 """Async function to turn on the fan."""
107 payload = {
"on":
True}
117 """Async function to turn off the fan."""
118 payload = {
"on":
False}
128 """Set the speed percentage of the fan."""
129 payload = {
"rotationSpeed": percentage}
None _handle_coordinator_update(self)
None async_added_to_hass(self)
None async_set_percentage(self, int percentage)
None async_turn_off(self, **Any kwargs)
None __init__(self, HomeAssistant hass, str api_key, dict[str, Any] device, FreedomproDataUpdateCoordinator coordinator)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)