From d7d989b9fbc5ad01882b1505b6493168f5bd6052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20J=C3=A1l?= Date: Wed, 30 Aug 2023 06:03:08 +0200 Subject: [PATCH] Switchbot nightlatch feature (#98620) Co-authored-by: J. Nick Koston --- homeassistant/components/switchbot/lock.py | 12 +++++++++++- homeassistant/components/switchbot/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/switchbot/lock.py b/homeassistant/components/switchbot/lock.py index 7710cde12a9..60f4fe66c26 100644 --- a/homeassistant/components/switchbot/lock.py +++ b/homeassistant/components/switchbot/lock.py @@ -4,7 +4,7 @@ from typing import Any import switchbot from switchbot.const import LockStatus -from homeassistant.components.lock import LockEntity +from homeassistant.components.lock import LockEntity, LockEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -34,6 +34,8 @@ class SwitchBotLock(SwitchbotEntity, LockEntity): """Initialize the entity.""" super().__init__(coordinator) self._async_update_attrs() + if self._device.is_night_latch_enabled(): + self._attr_supported_features = LockEntityFeature.OPEN def _async_update_attrs(self) -> None: """Update the entity attributes.""" @@ -53,5 +55,13 @@ class SwitchBotLock(SwitchbotEntity, LockEntity): async def async_unlock(self, **kwargs: Any) -> None: """Unlock the lock.""" + if self._device.is_night_latch_enabled(): + self._last_run_success = await self._device.unlock_without_unlatch() + else: + self._last_run_success = await self._device.unlock() + self.async_write_ha_state() + + async def async_open(self, **kwargs: Any) -> None: + """Open the lock.""" self._last_run_success = await self._device.unlock() self.async_write_ha_state() diff --git a/homeassistant/components/switchbot/manifest.json b/homeassistant/components/switchbot/manifest.json index 237ba98c19d..2259a450559 100644 --- a/homeassistant/components/switchbot/manifest.json +++ b/homeassistant/components/switchbot/manifest.json @@ -39,5 +39,5 @@ "documentation": "https://www.home-assistant.io/integrations/switchbot", "iot_class": "local_push", "loggers": ["switchbot"], - "requirements": ["PySwitchbot==0.38.0"] + "requirements": ["PySwitchbot==0.39.1"] } diff --git a/requirements_all.txt b/requirements_all.txt index 6224caab074..14ecb74f0aa 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -96,7 +96,7 @@ PyRMVtransport==0.3.3 PySocks==1.7.1 # homeassistant.components.switchbot -PySwitchbot==0.38.0 +PySwitchbot==0.39.1 # homeassistant.components.switchmate PySwitchmate==0.5.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ce11b3fe61e..c377616a49e 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -86,7 +86,7 @@ PyRMVtransport==0.3.3 PySocks==1.7.1 # homeassistant.components.switchbot -PySwitchbot==0.38.0 +PySwitchbot==0.39.1 # homeassistant.components.syncthru PySyncThru==0.7.10