1 """Platform allowing several locks to be grouped into one lock."""
3 from __future__
import annotations
8 import voluptuous
as vol
11 DOMAIN
as LOCK_DOMAIN,
12 PLATFORM_SCHEMA
as LOCK_PLATFORM_SCHEMA,
34 from .entity
import GroupEntity
36 DEFAULT_NAME =
"Lock Group"
41 PLATFORM_SCHEMA = LOCK_PLATFORM_SCHEMA.extend(
43 vol.Required(CONF_ENTITIES): cv.entities_domain(LOCK_DOMAIN),
44 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
45 vol.Optional(CONF_UNIQUE_ID): cv.string,
49 _LOGGER = logging.getLogger(__name__)
55 async_add_entities: AddEntitiesCallback,
56 discovery_info: DiscoveryInfoType |
None =
None,
58 """Set up the Lock Group platform."""
62 config.get(CONF_UNIQUE_ID),
64 config[CONF_ENTITIES],
72 config_entry: ConfigEntry,
73 async_add_entities: AddEntitiesCallback,
75 """Initialize Lock Group config entry."""
76 registry = er.async_get(hass)
77 entities = er.async_validate_entity_ids(
78 registry, config_entry.options[CONF_ENTITIES]
83 config_entry.entry_id,
93 hass: HomeAssistant, name: str, validated_config: dict[str, Any]
95 """Create a preview sensor."""
99 validated_config[CONF_ENTITIES],
104 """Representation of a lock group."""
106 _attr_available =
False
107 _attr_should_poll =
False
111 unique_id: str |
None,
113 entity_ids: list[str],
115 """Initialize a lock group."""
124 """Forward the lock command to all locks in the group."""
125 data = {ATTR_ENTITY_ID: self.
_entity_ids_entity_ids}
126 _LOGGER.debug(
"Forwarded lock command: %s", data)
128 await self.
hasshass.services.async_call(
137 """Forward the unlock command to all locks in the group."""
138 data = {ATTR_ENTITY_ID: self.
_entity_ids_entity_ids}
139 await self.
hasshass.services.async_call(
148 """Forward the open command to all locks in the group."""
149 data = {ATTR_ENTITY_ID: self.
_entity_ids_entity_ids}
150 await self.
hasshass.services.async_call(
160 """Query all members and determine the lock group state."""
164 if (state := self.
hasshass.states.get(entity_id))
is not None
168 state
not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
for state
in states
186 self.
_attr_is_locked_attr_is_locked = all(state == LockState.LOCKED
for state
in states)
None async_unlock(self, **Any kwargs)
_attr_extra_state_attributes
None __init__(self, str|None unique_id, str name, list[str] entity_ids)
None async_update_group_state(self)
None async_open(self, **Any kwargs)
None async_lock(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
LockGroup async_create_preview_lock(HomeAssistant hass, str name, dict[str, Any] validated_config)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)