1 """Support for LCN switches."""
3 from collections.abc
import Iterable
4 from functools
import partial
17 ADD_ENTITIES_CALLBACKS,
25 from .entity
import LcnEntity
26 from .helpers
import InputType
32 config_entry: ConfigEntry,
33 async_add_entities: AddEntitiesCallback,
34 entity_configs: Iterable[ConfigType],
36 """Add entities for this domain."""
38 LcnOutputSwitch | LcnRelaySwitch | LcnRegulatorLockSwitch | LcnKeyLockSwitch
40 for entity_config
in entity_configs:
41 if entity_config[CONF_DOMAIN_DATA][CONF_OUTPUT]
in OUTPUT_PORTS:
43 elif entity_config[CONF_DOMAIN_DATA][CONF_OUTPUT]
in RELAY_PORTS:
45 elif entity_config[CONF_DOMAIN_DATA][CONF_OUTPUT]
in SETPOINTS:
55 config_entry: ConfigEntry,
56 async_add_entities: AddEntitiesCallback,
58 """Set up LCN switch entities from a config entry."""
59 add_entities = partial(
60 add_lcn_switch_entities,
65 hass.data[DOMAIN][config_entry.entry_id][ADD_ENTITIES_CALLBACKS].
update(
66 {DOMAIN_SWITCH: add_entities}
72 for entity_config
in config_entry.data[CONF_ENTITIES]
73 if entity_config[CONF_DOMAIN] == DOMAIN_SWITCH
79 """Representation of a LCN switch for output ports."""
83 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
84 """Initialize the LCN switch."""
85 super().
__init__(config, config_entry)
87 self.
outputoutput = pypck.lcn_defs.OutputPort[config[CONF_DOMAIN_DATA][CONF_OUTPUT]]
90 """Run when entity about to be added to hass."""
96 """Run when entity will be removed from hass."""
102 """Turn the entity on."""
109 """Turn the entity off."""
116 """Set switch state when LCN input object (command) is received."""
118 not isinstance(input_obj, pypck.inputs.ModStatusOutput)
119 or input_obj.get_output_id() != self.
outputoutput.value
128 """Representation of a LCN switch for relay ports."""
132 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
133 """Initialize the LCN switch."""
134 super().
__init__(config, config_entry)
136 self.
outputoutput = pypck.lcn_defs.RelayPort[config[CONF_DOMAIN_DATA][CONF_OUTPUT]]
139 """Run when entity about to be added to hass."""
145 """Run when entity will be removed from hass."""
151 """Turn the entity on."""
152 states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
153 states[self.
outputoutput.value] = pypck.lcn_defs.RelayStateModifier.ON
160 """Turn the entity off."""
161 states = [pypck.lcn_defs.RelayStateModifier.NOCHANGE] * 8
162 states[self.
outputoutput.value] = pypck.lcn_defs.RelayStateModifier.OFF
169 """Set switch state when LCN input object (command) is received."""
170 if not isinstance(input_obj, pypck.inputs.ModStatusRelays):
178 """Representation of a LCN switch for regulator locks."""
182 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
183 """Initialize the LCN switch."""
184 super().
__init__(config, config_entry)
187 config[CONF_DOMAIN_DATA][CONF_OUTPUT]
192 """Run when entity about to be added to hass."""
200 """Run when entity will be removed from hass."""
208 """Turn the entity on."""
215 """Turn the entity off."""
222 """Set switch state when LCN input object (command) is received."""
224 not isinstance(input_obj, pypck.inputs.ModStatusVar)
234 """Representation of a LCN switch for key locks."""
238 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
239 """Initialize the LCN switch."""
240 super().
__init__(config, config_entry)
242 self.
keykey = pypck.lcn_defs.Key[config[CONF_DOMAIN_DATA][CONF_OUTPUT]]
247 """Run when entity about to be added to hass."""
253 """Run when entity will be removed from hass."""
259 """Turn the entity on."""
260 states = [pypck.lcn_defs.KeyLockStateModifier.NOCHANGE] * 8
261 states[self.
key_idkey_id] = pypck.lcn_defs.KeyLockStateModifier.ON
270 """Turn the entity off."""
271 states = [pypck.lcn_defs.KeyLockStateModifier.NOCHANGE] * 8
272 states[self.
key_idkey_id] = pypck.lcn_defs.KeyLockStateModifier.OFF
281 """Set switch state when LCN input object (command) is received."""
283 not isinstance(input_obj, pypck.inputs.ModStatusKeyLocks)
284 or self.
keykey
not in pypck.lcn_defs.Key
None async_turn_off(self, **Any kwargs)
None async_will_remove_from_hass(self)
None async_added_to_hass(self)
None async_turn_on(self, **Any kwargs)
None input_received(self, InputType input_obj)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_turn_off(self, **Any kwargs)
None async_added_to_hass(self)
None input_received(self, InputType input_obj)
None async_turn_on(self, **Any kwargs)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_will_remove_from_hass(self)
None input_received(self, InputType input_obj)
None async_added_to_hass(self)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_turn_on(self, **Any kwargs)
None async_will_remove_from_hass(self)
None async_turn_off(self, **Any kwargs)
None input_received(self, InputType input_obj)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None async_write_ha_state(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
IssData update(pyiss.ISS iss)
None add_lcn_switch_entities(ConfigEntry config_entry, AddEntitiesCallback async_add_entities, Iterable[ConfigType] entity_configs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)