1 """Support for LCN binary sensors."""
3 from collections.abc
import Iterable
4 from functools
import partial
10 DOMAIN
as DOMAIN_BINARY_SENSOR,
26 ADD_ENTITIES_CALLBACKS,
32 from .entity
import LcnEntity
33 from .helpers
import InputType
37 config_entry: ConfigEntry,
38 async_add_entities: AddEntitiesCallback,
39 entity_configs: Iterable[ConfigType],
41 """Add entities for this domain."""
42 entities: list[LcnRegulatorLockSensor | LcnBinarySensor | LcnLockKeysSensor] = []
43 for entity_config
in entity_configs:
44 if entity_config[CONF_DOMAIN_DATA][CONF_SOURCE]
in SETPOINTS:
46 elif entity_config[CONF_DOMAIN_DATA][CONF_SOURCE]
in BINSENSOR_PORTS:
56 config_entry: ConfigEntry,
57 async_add_entities: AddEntitiesCallback,
59 """Set up LCN switch entities from a config entry."""
60 add_entities = partial(
66 hass.data[DOMAIN][config_entry.entry_id][ADD_ENTITIES_CALLBACKS].
update(
67 {DOMAIN_BINARY_SENSOR: add_entities}
73 for entity_config
in config_entry.data[CONF_ENTITIES]
74 if entity_config[CONF_DOMAIN] == DOMAIN_BINARY_SENSOR
80 """Representation of a LCN binary sensor for regulator locks."""
82 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
83 """Initialize the LCN binary sensor."""
84 super().
__init__(config, config_entry)
87 config[CONF_DOMAIN_DATA][CONF_SOURCE]
91 """Run when entity about to be added to hass."""
101 if entity_automations + entity_scripts:
105 f
"deprecated_binary_sensor_{self.entity_id}",
106 breaks_in_ha_version=
"2025.5.0",
108 severity=IssueSeverity.WARNING,
109 translation_key=
"deprecated_regulatorlock_sensor",
110 translation_placeholders={
111 "entity": f
"{DOMAIN_BINARY_SENSOR}.{self.name.lower().replace(' ', '_')}",
116 """Run when entity will be removed from hass."""
123 self.
hasshass, DOMAIN, f
"deprecated_binary_sensor_{self.entity_id}"
127 """Set sensor value when LCN input object (command) is received."""
129 not isinstance(input_obj, pypck.inputs.ModStatusVar)
134 self.
_attr_is_on_attr_is_on = input_obj.get_value().is_locked_regulator()
139 """Representation of a LCN binary sensor for binary sensor ports."""
141 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
142 """Initialize the LCN binary sensor."""
143 super().
__init__(config, config_entry)
146 config[CONF_DOMAIN_DATA][CONF_SOURCE]
150 """Run when entity about to be added to hass."""
158 """Run when entity will be removed from hass."""
166 """Set sensor value when LCN input object (command) is received."""
167 if not isinstance(input_obj, pypck.inputs.ModStatusBinSensors):
175 """Representation of a LCN sensor for key locks."""
177 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
178 """Initialize the LCN sensor."""
179 super().
__init__(config, config_entry)
181 self.
sourcesource = pypck.lcn_defs.Key[config[CONF_DOMAIN_DATA][CONF_SOURCE]]
184 """Run when entity about to be added to hass."""
192 if entity_automations + entity_scripts:
196 f
"deprecated_binary_sensor_{self.entity_id}",
197 breaks_in_ha_version=
"2025.5.0",
199 severity=IssueSeverity.WARNING,
200 translation_key=
"deprecated_keylock_sensor",
201 translation_placeholders={
202 "entity": f
"{DOMAIN_BINARY_SENSOR}.{self.name.lower().replace(' ', '_')}",
207 """Run when entity will be removed from hass."""
212 self.
hasshass, DOMAIN, f
"deprecated_binary_sensor_{self.entity_id}"
216 """Set sensor value when LCN input object (command) is received."""
218 not isinstance(input_obj, pypck.inputs.ModStatusKeyLocks)
219 or self.
sourcesource
not in pypck.lcn_defs.Key
223 table_id = ord(self.
sourcesource.name[0]) - 65
224 key_id =
int(self.
sourcesource.name[1]) - 1
226 self.
_attr_is_on_attr_is_on = input_obj.get_state(table_id, key_id)
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None input_received(self, InputType input_obj)
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None input_received(self, InputType input_obj)
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 async_write_ha_state(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
list[str] automations_with_entity(HomeAssistant hass, str entity_id)
IssData update(pyiss.ISS iss)
None add_lcn_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)
None async_create_issue(HomeAssistant hass, str entry_id)
None async_delete_issue(HomeAssistant hass, str entry_id)
list[str] scripts_with_entity(HomeAssistant hass, str entity_id)