From de30712d76c3fa1f7d5a7f9a1f99edf7d0a4741d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Matheson=20Wergeland?= Date: Tue, 29 Aug 2023 22:02:09 +0200 Subject: [PATCH] Verisure: propagate lock code digits configuration immediately (#99241) --- homeassistant/components/verisure/__init__.py | 10 ++++++++++ homeassistant/components/verisure/lock.py | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/verisure/__init__.py b/homeassistant/components/verisure/__init__.py index 62f41913862..dfd9d9cdc04 100644 --- a/homeassistant/components/verisure/__init__.py +++ b/homeassistant/components/verisure/__init__.py @@ -48,9 +48,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # Set up all platforms for this device/entry. await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + # Update options + entry.async_on_unload(entry.add_update_listener(update_listener)) + return True +async def update_listener(hass: HomeAssistant, entry: ConfigEntry): + """Handle options update.""" + # Propagate configuration change. + coordinator = hass.data[DOMAIN][entry.entry_id] + coordinator.async_update_listeners() + + async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload Verisure config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/verisure/lock.py b/homeassistant/components/verisure/lock.py index ad9590d2524..1a81b437116 100644 --- a/homeassistant/components/verisure/lock.py +++ b/homeassistant/components/verisure/lock.py @@ -70,9 +70,6 @@ class VerisureDoorlock(CoordinatorEntity[VerisureDataUpdateCoordinator], LockEnt self.serial_number = serial_number self._state: str | None = None - self._digits = coordinator.entry.options.get( - CONF_LOCK_CODE_DIGITS, DEFAULT_LOCK_CODE_DIGITS - ) @property def device_info(self) -> DeviceInfo: @@ -111,8 +108,11 @@ class VerisureDoorlock(CoordinatorEntity[VerisureDataUpdateCoordinator], LockEnt @property def code_format(self) -> str: - """Return the required six digit code.""" - return "^\\d{%s}$" % self._digits + """Return the configured code format.""" + digits = self.coordinator.entry.options.get( + CONF_LOCK_CODE_DIGITS, DEFAULT_LOCK_CODE_DIGITS + ) + return "^\\d{%s}$" % digits @property def is_locked(self) -> bool: