1 """The IntelliFire Light."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
9 from intellifire4py.control
import IntelliFireController
10 from intellifire4py.model
import IntelliFirePollData
16 LightEntityDescription,
22 from .const
import DOMAIN, LOGGER
23 from .coordinator
import IntellifireDataUpdateCoordinator
24 from .entity
import IntellifireEntity
27 @dataclass(frozen=True)
29 """Required keys for fan entity."""
31 set_fn: Callable[[IntelliFireController, int], Awaitable]
32 value_fn: Callable[[IntelliFirePollData], int]
35 @dataclass(frozen=True)
37 LightEntityDescription, IntellifireLightRequiredKeysMixin
39 """Describes a light entity."""
42 INTELLIFIRE_LIGHTS: tuple[IntellifireLightEntityDescription, ...] = (
45 translation_key=
"lights",
46 set_fn=
lambda control_api, level: control_api.set_lights(level=level),
47 value_fn=
lambda data: data.light_level,
53 """Light entity for the fireplace."""
55 entity_description: IntellifireLightEntityDescription
56 _attr_color_mode = ColorMode.BRIGHTNESS
57 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
61 """Return the current brightness 0-255."""
66 """Return true if light is on."""
70 """Instruct the light to turn on."""
71 if ATTR_BRIGHTNESS
in kwargs:
72 light_level =
int(kwargs[ATTR_BRIGHTNESS] / 85)
76 await self.
entity_descriptionentity_description.set_fn(self.coordinator.control_api, light_level)
77 await self.coordinator.async_request_refresh()
80 """Instruct the light to turn off."""
81 await self.
entity_descriptionentity_description.set_fn(self.coordinator.control_api, 0)
82 await self.coordinator.async_request_refresh()
88 async_add_entities: AddEntitiesCallback,
90 """Set up the fans."""
91 coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
93 if coordinator.data.has_light:
96 for description
in INTELLIFIRE_LIGHTS
99 LOGGER.debug(
"Disabling Lights - IntelliFire device does not appear to have one")
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)