1 """Support for LCN lights."""
3 from collections.abc
import Iterable
4 from functools
import partial
12 DOMAIN
as DOMAIN_LIGHT,
24 ADD_ENTITIES_CALLBACKS,
32 from .entity
import LcnEntity
33 from .helpers
import InputType
39 config_entry: ConfigEntry,
40 async_add_entities: AddEntitiesCallback,
41 entity_configs: Iterable[ConfigType],
43 """Add entities for this domain."""
44 entities: list[LcnOutputLight | LcnRelayLight] = []
45 for entity_config
in entity_configs:
46 if entity_config[CONF_DOMAIN_DATA][CONF_OUTPUT]
in OUTPUT_PORTS:
56 config_entry: ConfigEntry,
57 async_add_entities: AddEntitiesCallback,
59 """Set up LCN light entities from a config entry."""
60 add_entities = partial(
66 hass.data[DOMAIN][config_entry.entry_id][ADD_ENTITIES_CALLBACKS].
update(
67 {DOMAIN_LIGHT: add_entities}
73 for entity_config
in config_entry.data[CONF_ENTITIES]
74 if entity_config[CONF_DOMAIN] == DOMAIN_LIGHT
80 """Representation of a LCN light for output ports."""
82 _attr_supported_features = LightEntityFeature.TRANSITION
84 _attr_brightness = 255
86 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
87 """Initialize the LCN light."""
88 super().
__init__(config, config_entry)
90 self.
outputoutput = pypck.lcn_defs.OutputPort[config[CONF_DOMAIN_DATA][CONF_OUTPUT]]
92 self.
_transition_transition = pypck.lcn_defs.time_to_ramp_value(
93 config[CONF_DOMAIN_DATA][CONF_TRANSITION] * 1000.0
95 self.
dimmabledimmable = config[CONF_DOMAIN_DATA][CONF_DIMMABLE]
106 """Run when entity about to be added to hass."""
112 """Run when entity will be removed from hass."""
118 """Turn the entity on."""
119 if ATTR_BRIGHTNESS
in kwargs:
120 percent =
int(kwargs[ATTR_BRIGHTNESS] / 255.0 * 100)
123 if ATTR_TRANSITION
in kwargs:
124 transition = pypck.lcn_defs.time_to_ramp_value(
125 kwargs[ATTR_TRANSITION] * 1000
131 self.
outputoutput.value, percent, transition
139 """Turn the entity off."""
140 if ATTR_TRANSITION
in kwargs:
141 transition = pypck.lcn_defs.time_to_ramp_value(
142 kwargs[ATTR_TRANSITION] * 1000
148 self.
outputoutput.value, 0, transition
156 """Set light state when LCN input object (command) is received."""
158 not isinstance(input_obj, pypck.inputs.ModStatusOutput)
159 or input_obj.get_output_id() != self.
outputoutput.value
172 """Representation of a LCN light for relay ports."""
174 _attr_color_mode = ColorMode.ONOFF
175 _attr_supported_color_modes = {ColorMode.ONOFF}
178 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
179 """Initialize the LCN light."""
180 super().
__init__(config, config_entry)
182 self.
outputoutput = pypck.lcn_defs.RelayPort[config[CONF_DOMAIN_DATA][CONF_OUTPUT]]
185 """Run when entity about to be added to hass."""
191 """Run when entity will be removed from hass."""
197 """Turn the entity on."""
198 states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
199 states[self.
outputoutput.value] = pypck.lcn_defs.RelayStateModifier.ON
206 """Turn the entity off."""
207 states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
208 states[self.
outputoutput.value] = pypck.lcn_defs.RelayStateModifier.OFF
215 """Set light state when LCN input object (command) is received."""
216 if not isinstance(input_obj, pypck.inputs.ModStatusRelays):
None async_will_remove_from_hass(self)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_turn_on(self, **Any kwargs)
_attr_supported_color_modes
None async_turn_off(self, **Any kwargs)
None input_received(self, InputType input_obj)
None async_added_to_hass(self)
None input_received(self, InputType input_obj)
None async_added_to_hass(self)
None async_turn_off(self, **Any kwargs)
None async_will_remove_from_hass(self)
None async_turn_on(self, **Any kwargs)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_write_ha_state(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
IssData update(pyiss.ISS iss)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None add_lcn_entities(ConfigEntry config_entry, AddEntitiesCallback async_add_entities, Iterable[ConfigType] entity_configs)