1 """Fan definition for Intellifire."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
10 from intellifire4py.control
import IntelliFireController
11 from intellifire4py.model
import IntelliFirePollData
22 percentage_to_ranged_value,
23 ranged_value_to_percentage,
26 from .const
import DOMAIN, LOGGER
27 from .coordinator
import IntellifireDataUpdateCoordinator
28 from .entity
import IntellifireEntity
31 @dataclass(frozen=True)
33 """Required keys for fan entity."""
35 set_fn: Callable[[IntelliFireController, int], Awaitable]
36 value_fn: Callable[[IntelliFirePollData], int]
37 speed_range: tuple[int, int]
40 @dataclass(frozen=True)
42 FanEntityDescription, IntellifireFanRequiredKeysMixin
44 """Describes a fan entity."""
47 INTELLIFIRE_FANS: tuple[IntellifireFanEntityDescription, ...] = (
50 translation_key=
"fan",
51 set_fn=
lambda control_api, speed: control_api.set_fan_speed(speed=speed),
52 value_fn=
lambda data: data.fanspeed,
61 async_add_entities: AddEntitiesCallback,
63 """Set up the fans."""
64 coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
66 if coordinator.data.has_fan:
69 for description
in INTELLIFIRE_FANS
72 LOGGER.debug(
"Disabling Fan - IntelliFire device does not appear to have one")
76 """Fan entity for the fireplace."""
78 entity_description: IntellifireFanEntityDescription
79 _attr_supported_features = (
80 FanEntityFeature.SET_SPEED
81 | FanEntityFeature.TURN_OFF
82 | FanEntityFeature.TURN_ON
84 _enable_turn_on_off_backwards_compatibility =
False
88 """Return on or off."""
93 """Return fan percentage."""
96 self.coordinator.read_api.data.fanspeed,
101 """Count of supported speeds."""
105 """Set the speed percentage of the fan."""
107 LOGGER.debug(
"Setting Fan Speed %s", percentage)
109 int_value = math.ceil(
112 await self.
entity_descriptionentity_description.set_fn(self.coordinator.control_api, int_value)
113 await self.coordinator.async_request_refresh()
117 percentage: int |
None =
None,
118 preset_mode: str |
None =
None,
121 """Turn on the fan."""
123 int_value = math.ceil(
130 await self.
entity_descriptionentity_description.set_fn(self.coordinator.control_api, int_value)
131 await self.coordinator.async_request_refresh()
134 """Turn off the fan."""
135 await self.
entity_descriptionentity_description.set_fn(self.coordinator.control_api, 0)
136 await self.coordinator.async_request_refresh()
None async_turn_off(self, **Any kwargs)
int|None percentage(self)
None async_set_percentage(self, int percentage)
None async_turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry 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)