1 """Support for LiteJet lights."""
3 from __future__
import annotations
7 from pylitejet
import LiteJet, LiteJetError
22 from .const
import CONF_DEFAULT_TRANSITION, DOMAIN
24 ATTR_NUMBER =
"number"
29 config_entry: ConfigEntry,
30 async_add_entities: AddEntitiesCallback,
34 system: LiteJet = hass.data[DOMAIN]
37 for index
in system.loads():
38 name = await system.get_load_name(index)
39 entities.append(
LiteJetLight(config_entry, system, index, name))
45 """Representation of a single LiteJet light."""
47 _attr_color_mode = ColorMode.BRIGHTNESS
48 _attr_should_poll =
False
49 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
50 _attr_supported_features = LightEntityFeature.TRANSITION
51 _attr_has_entity_name =
True
55 self, config_entry: ConfigEntry, system: LiteJet, index: int, name: str
57 """Initialize a LiteJet light."""
66 identifiers={(DOMAIN, f
"{config_entry.entry_id}_light_{index}")},
68 via_device=(DOMAIN, f
"{config_entry.entry_id}_mcp"),
72 """Run when this Entity has been added to HA."""
78 """Entity being removed from hass."""
83 """Handle state changes."""
87 """Handle connected changes."""
91 """Turn on the light."""
96 if ATTR_BRIGHTNESS
not in kwargs
and ATTR_TRANSITION
not in kwargs:
98 await self.
_lj_lj.activate_load(self.
_index_index)
99 except LiteJetError
as exc:
100 raise HomeAssistantError
from exc
105 default_transition = self.
_config_entry_config_entry.options.get(CONF_DEFAULT_TRANSITION, 0)
106 transition = kwargs.get(ATTR_TRANSITION, default_transition)
107 brightness =
int(kwargs.get(ATTR_BRIGHTNESS, 255) / 255 * 99)
110 await self.
_lj_lj.activate_load_at(self.
_index_index, brightness,
int(transition))
111 except LiteJetError
as exc:
112 raise HomeAssistantError
from exc
115 """Turn off the light."""
116 if ATTR_TRANSITION
in kwargs:
118 await self.
_lj_lj.activate_load_at(self.
_index_index, 0, kwargs[ATTR_TRANSITION])
119 except LiteJetError
as exc:
120 raise HomeAssistantError
from exc
127 await self.
_lj_lj.deactivate_load(self.
_index_index)
128 except LiteJetError
as exc:
129 raise HomeAssistantError
from exc
132 """Retrieve the light's brightness from the LiteJet system."""
139 await self.
_lj_lj.get_load_level(self.
_index_index) / 99 * 255
int|None brightness(self)
None _on_connected_changed(self, bool connected, str reason)
None async_added_to_hass(self)
_attr_extra_state_attributes
None _on_load_changed(self, int|None level)
None async_turn_on(self, **Any kwargs)
None async_will_remove_from_hass(self)
None async_turn_off(self, **Any kwargs)
None __init__(self, ConfigEntry config_entry, LiteJet system, int index, str name)
None schedule_update_ha_state(self, bool force_refresh=False)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)