File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 99from cryptography .hazmat .primitives .ciphers import Cipher , algorithms , modes
1010
1111from ..const import LockStatus
12- from .device import SwitchbotDevice
12+ from .device import SwitchbotDevice , SwitchbotOperationError
1313
1414COMMAND_HEADER = "57"
1515COMMAND_GET_CK_IV = f"{ COMMAND_HEADER } 0f2103"
@@ -52,6 +52,23 @@ def __init__(
5252 self ._notifications_enabled : bool = False
5353 super ().__init__ (device , None , interface , ** kwargs )
5454
55+ @staticmethod
56+ async def verify_encryption_key (
57+ device : BLEDevice , key_id : str , encryption_key : str
58+ ) -> bool :
59+ try :
60+ lock = SwitchbotLock (
61+ device = device , key_id = key_id , encryption_key = encryption_key
62+ )
63+ except ValueError :
64+ return False
65+ try :
66+ lock_info = await lock .get_basic_info ()
67+ except SwitchbotOperationError :
68+ return False
69+
70+ return lock_info is not None
71+
5572 async def lock (self ) -> bool :
5673 """Send lock command."""
5774 return await self ._lock_unlock (
You can’t perform that action at this time.
0 commit comments