1 """Light platform for Advantage Air integration."""
10 from .
import AdvantageAirDataConfigEntry
11 from .const
import ADVANTAGE_AIR_STATE_ON, DOMAIN
as ADVANTAGE_AIR_DOMAIN
12 from .entity
import AdvantageAirEntity, AdvantageAirThingEntity
13 from .models
import AdvantageAirData
18 config_entry: AdvantageAirDataConfigEntry,
19 async_add_entities: AddEntitiesCallback,
21 """Set up AdvantageAir light platform."""
23 instance = config_entry.runtime_data
25 entities: list[LightEntity] = []
26 if my_lights := instance.coordinator.data.get(
"myLights"):
27 for light
in my_lights[
"lights"].values():
28 if light.get(
"relay"):
32 if things := instance.coordinator.data.get(
"myThings"):
33 for thing
in things[
"things"].values():
34 if thing[
"channelDipState"] == 4:
36 elif thing[
"channelDipState"] == 5:
42 """Representation of Advantage Air Light."""
44 _attr_color_mode = ColorMode.ONOFF
45 _attr_supported_color_modes = {ColorMode.ONOFF}
48 def __init__(self, instance: AdvantageAirData, light: dict[str, Any]) ->
None:
49 """Initialize an Advantage Air Light."""
52 self._id: str = light[
"id"]
53 self._attr_unique_id += f
"-{self._id}"
55 identifiers={(ADVANTAGE_AIR_DOMAIN, self._attr_unique_id)},
56 via_device=(ADVANTAGE_AIR_DOMAIN, self.coordinator.data[
"system"][
"rid"]),
57 manufacturer=
"Advantage Air",
58 model=light.get(
"moduleType"),
62 instance.api.lights.async_update_state, self._id
66 def _data(self) -> dict[str, Any]:
67 """Return the light object."""
68 return self.coordinator.data[
"myLights"][
"lights"][self._id]
72 """Return if the light is on."""
73 return self.
_data_data[
"state"] == ADVANTAGE_AIR_STATE_ON
76 """Turn the light on."""
80 """Turn the light off."""
85 """Representation of Advantage Air Dimmable Light."""
87 _attr_color_mode = ColorMode.BRIGHTNESS
88 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
90 def __init__(self, instance: AdvantageAirData, light: dict[str, Any]) ->
None:
91 """Initialize an Advantage Air Dimmable Light."""
94 instance.api.lights.async_update_value, self._id
99 """Return the brightness of this light between 0..255."""
100 return round(self.
_data_data[
"value"] * 255 / 100)
103 """Turn the light on and optionally set the brightness."""
104 if ATTR_BRIGHTNESS
in kwargs:
105 return await self.
async_update_valueasync_update_value(round(kwargs[ATTR_BRIGHTNESS] / 2.55))
110 """Representation of Advantage Air Light controlled by myThings."""
112 _attr_color_mode = ColorMode.ONOFF
113 _attr_supported_color_modes = {ColorMode.ONOFF}
117 """Representation of Advantage Air Dimmable Light controlled by myThings."""
119 _attr_color_mode = ColorMode.BRIGHTNESS
120 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
124 """Return the brightness of this light between 0..255."""
125 return round(self.
_data_data[
"value"] * 255 / 100)
128 """Turn the light on by setting the brightness."""
129 await self.
async_update_valueasync_update_value(round(kwargs.get(ATTR_BRIGHTNESS, 255) / 2.55))
def update_handle_factory(self, func, *keys)
None async_turn_on(self, **Any kwargs)
None __init__(self, AdvantageAirData instance, dict[str, Any] light)
dict[str, Any] _data(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, AdvantageAirData instance, dict[str, Any] light)
None async_turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, AdvantageAirDataConfigEntry config_entry, AddEntitiesCallback async_add_entities)