From 630c43883472370603ae98fb620df1a56a9d777b Mon Sep 17 00:00:00 2001 From: Retha Runolfsson <137745329+zerzhang@users.noreply.github.com> Date: Wed, 21 May 2025 18:37:47 +0800 Subject: [PATCH] Add lock ultra and lock lite for switchbot integration (#145373) --- .../components/switchbot/__init__.py | 12 +++++ homeassistant/components/switchbot/const.py | 8 ++++ tests/components/switchbot/__init__.py | 44 +++++++++++++++++++ tests/components/switchbot/test_lock.py | 24 +++++++--- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/switchbot/__init__.py b/homeassistant/components/switchbot/__init__.py index 56629764f66..ee7d0b7e658 100644 --- a/homeassistant/components/switchbot/__init__.py +++ b/homeassistant/components/switchbot/__init__.py @@ -80,6 +80,16 @@ PLATFORMS_BY_TYPE = { SupportedModels.K10_PRO_VACUUM.value: [Platform.VACUUM, Platform.SENSOR], SupportedModels.K10_PRO_COMBO_VACUUM.value: [Platform.VACUUM, Platform.SENSOR], SupportedModels.HUB3.value: [Platform.SENSOR, Platform.BINARY_SENSOR], + SupportedModels.LOCK_LITE.value: [ + Platform.BINARY_SENSOR, + Platform.LOCK, + Platform.SENSOR, + ], + SupportedModels.LOCK_ULTRA.value: [ + Platform.BINARY_SENSOR, + Platform.LOCK, + Platform.SENSOR, + ], } CLASS_BY_DEVICE = { SupportedModels.CEILING_LIGHT.value: switchbot.SwitchbotCeilingLight, @@ -101,6 +111,8 @@ CLASS_BY_DEVICE = { SupportedModels.K10_VACUUM.value: switchbot.SwitchbotVacuum, SupportedModels.K10_PRO_VACUUM.value: switchbot.SwitchbotVacuum, SupportedModels.K10_PRO_COMBO_VACUUM.value: switchbot.SwitchbotVacuum, + SupportedModels.LOCK_LITE.value: switchbot.SwitchbotLock, + SupportedModels.LOCK_ULTRA.value: switchbot.SwitchbotLock, } diff --git a/homeassistant/components/switchbot/const.py b/homeassistant/components/switchbot/const.py index b19af0afe94..aae189be2e1 100644 --- a/homeassistant/components/switchbot/const.py +++ b/homeassistant/components/switchbot/const.py @@ -44,6 +44,8 @@ class SupportedModels(StrEnum): K10_PRO_VACUUM = "k10_pro_vacuum" K10_PRO_COMBO_VACUUM = "k10_pro_combo_vacumm" HUB3 = "hub3" + LOCK_LITE = "lock_lite" + LOCK_ULTRA = "lock_ultra" CONNECTABLE_SUPPORTED_MODEL_TYPES = { @@ -67,6 +69,8 @@ CONNECTABLE_SUPPORTED_MODEL_TYPES = { SwitchbotModel.K10_VACUUM: SupportedModels.K10_VACUUM, SwitchbotModel.K10_PRO_VACUUM: SupportedModels.K10_PRO_VACUUM, SwitchbotModel.K10_PRO_COMBO_VACUUM: SupportedModels.K10_PRO_COMBO_VACUUM, + SwitchbotModel.LOCK_LITE: SupportedModels.LOCK_LITE, + SwitchbotModel.LOCK_ULTRA: SupportedModels.LOCK_ULTRA, } NON_CONNECTABLE_SUPPORTED_MODEL_TYPES = { @@ -91,6 +95,8 @@ ENCRYPTED_MODELS = { SwitchbotModel.RELAY_SWITCH_1PM, SwitchbotModel.LOCK, SwitchbotModel.LOCK_PRO, + SwitchbotModel.LOCK_LITE, + SwitchbotModel.LOCK_ULTRA, } ENCRYPTED_SWITCHBOT_MODEL_TO_CLASS: dict[ @@ -100,6 +106,8 @@ ENCRYPTED_SWITCHBOT_MODEL_TO_CLASS: dict[ SwitchbotModel.LOCK_PRO: switchbot.SwitchbotLock, SwitchbotModel.RELAY_SWITCH_1PM: switchbot.SwitchbotRelaySwitch, SwitchbotModel.RELAY_SWITCH_1: switchbot.SwitchbotRelaySwitch, + SwitchbotModel.LOCK_LITE: switchbot.SwitchbotLock, + SwitchbotModel.LOCK_ULTRA: switchbot.SwitchbotLock, } HASS_SENSOR_TYPE_TO_SWITCHBOT_MODEL = { diff --git a/tests/components/switchbot/__init__.py b/tests/components/switchbot/__init__.py index e858d5a71c0..1e90b0bf1fe 100644 --- a/tests/components/switchbot/__init__.py +++ b/tests/components/switchbot/__init__.py @@ -715,3 +715,47 @@ HUB3_SERVICE_INFO = BluetoothServiceInfoBleak( connectable=True, tx_power=-127, ) + + +LOCK_LITE_SERVICE_INFO = BluetoothServiceInfoBleak( + name="Lock Lite", + manufacturer_data={2409: b"\xe9\xd5\x11\xb2kS\x17\x93\x08 "}, + service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"-\x80d"}, + service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"], + address="AA:BB:CC:DD:EE:FF", + rssi=-60, + source="local", + advertisement=generate_advertisement_data( + local_name="Lock Lite", + manufacturer_data={2409: b"\xe9\xd5\x11\xb2kS\x17\x93\x08 "}, + service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"-\x80d"}, + service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"], + ), + device=generate_ble_device("AA:BB:CC:DD:EE:FF", "Lock Lite"), + time=0, + connectable=True, + tx_power=-127, +) + + +LOCK_ULTRA_SERVICE_INFO = BluetoothServiceInfoBleak( + name="Lock Ultra", + manufacturer_data={2409: b"\xb0\xe9\xfe\xb6j=%\x8204\x00\x04"}, + service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"\x00\x804\x00\x10\xa5\xb8"}, + service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"], + address="AA:BB:CC:DD:EE:FF", + rssi=-60, + source="local", + advertisement=generate_advertisement_data( + local_name="Lock Ultra", + manufacturer_data={2409: b"\xb0\xe9\xfe\xb6j=%\x8204\x00\x04"}, + service_data={ + "0000fd3d-0000-1000-8000-00805f9b34fb": b"\x00\x804\x00\x10\xa5\xb8" + }, + service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"], + ), + device=generate_ble_device("AA:BB:CC:DD:EE:FF", "Lock Ultra"), + time=0, + connectable=True, + tx_power=-127, +) diff --git a/tests/components/switchbot/test_lock.py b/tests/components/switchbot/test_lock.py index 859c818a6e3..38b8d24523b 100644 --- a/tests/components/switchbot/test_lock.py +++ b/tests/components/switchbot/test_lock.py @@ -17,7 +17,12 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from . import LOCK_SERVICE_INFO, WOLOCKPRO_SERVICE_INFO +from . import ( + LOCK_LITE_SERVICE_INFO, + LOCK_SERVICE_INFO, + LOCK_ULTRA_SERVICE_INFO, + WOLOCKPRO_SERVICE_INFO, +) from tests.common import MockConfigEntry from tests.components.bluetooth import inject_bluetooth_service_info @@ -25,7 +30,12 @@ from tests.components.bluetooth import inject_bluetooth_service_info @pytest.mark.parametrize( ("sensor_type", "service_info"), - [("lock_pro", WOLOCKPRO_SERVICE_INFO), ("lock", LOCK_SERVICE_INFO)], + [ + ("lock_pro", WOLOCKPRO_SERVICE_INFO), + ("lock", LOCK_SERVICE_INFO), + ("lock_lite", LOCK_LITE_SERVICE_INFO), + ("lock_ultra", LOCK_ULTRA_SERVICE_INFO), + ], ) @pytest.mark.parametrize( ("service", "mock_method"), @@ -44,8 +54,8 @@ async def test_lock_services( entry = mock_entry_encrypted_factory(sensor_type=sensor_type) entry.add_to_hass(hass) - mocked_instance = AsyncMock(return_value=True) + with patch.multiple( "homeassistant.components.switchbot.lock.switchbot.SwitchbotLock", update=AsyncMock(return_value=None), @@ -68,7 +78,12 @@ async def test_lock_services( @pytest.mark.parametrize( ("sensor_type", "service_info"), - [("lock_pro", WOLOCKPRO_SERVICE_INFO), ("lock", LOCK_SERVICE_INFO)], + [ + ("lock_pro", WOLOCKPRO_SERVICE_INFO), + ("lock", LOCK_SERVICE_INFO), + ("lock_lite", LOCK_LITE_SERVICE_INFO), + ("lock_ultra", LOCK_ULTRA_SERVICE_INFO), + ], ) @pytest.mark.parametrize( ("service", "mock_method"), @@ -87,7 +102,6 @@ async def test_lock_services_with_night_latch_enabled( entry = mock_entry_encrypted_factory(sensor_type=sensor_type) entry.add_to_hass(hass) - mocked_instance = AsyncMock(return_value=True) with patch.multiple(