Skip to content

Commit 3555501

Browse files
dsypniewskibdraco
andauthored
Allow low battery status responses for lock (#182)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent a2889dc commit 3555501

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

switchbot/devices/lock.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
_LOGGER = logging.getLogger(__name__)
3838

3939

40+
COMMAND_RESULT_EXPECTED_VALUES = {1, 6}
41+
# The return value of the command is 1 when the command is successful.
42+
# The return value of the command is 6 when the command is successful but the battery is low.
43+
44+
4045
class SwitchbotLock(SwitchbotDevice):
4146
"""Representation of a Switchbot Lock."""
4247

@@ -183,7 +188,7 @@ async def _lock_unlock(
183188

184189
await self._enable_notifications()
185190
result = await self._send_command(command)
186-
status = self._check_command_result(result, 0, {1})
191+
status = self._check_command_result(result, 0, COMMAND_RESULT_EXPECTED_VALUES)
187192

188193
# Also update the battery and firmware version
189194
if basic_data := await self._get_basic_info():
@@ -235,7 +240,7 @@ async def _get_lock_info(self) -> bytes | None:
235240
"""Return lock info of device."""
236241
_data = await self._send_command(key=COMMAND_LOCK_INFO, retry=self._retry_count)
237242

238-
if not self._check_command_result(_data, 0, {1}):
243+
if not self._check_command_result(_data, 0, COMMAND_RESULT_EXPECTED_VALUES):
239244
_LOGGER.error("Unsuccessful, please try again")
240245
return None
241246

@@ -245,15 +250,15 @@ async def _enable_notifications(self) -> bool:
245250
if self._notifications_enabled:
246251
return True
247252
result = await self._send_command(COMMAND_ENABLE_NOTIFICATIONS)
248-
if self._check_command_result(result, 0, {1}):
253+
if self._check_command_result(result, 0, COMMAND_RESULT_EXPECTED_VALUES):
249254
self._notifications_enabled = True
250255
return self._notifications_enabled
251256

252257
async def _disable_notifications(self) -> bool:
253258
if not self._notifications_enabled:
254259
return True
255260
result = await self._send_command(COMMAND_DISABLE_NOTIFICATIONS)
256-
if self._check_command_result(result, 0, {1}):
261+
if self._check_command_result(result, 0, COMMAND_RESULT_EXPECTED_VALUES):
257262
self._notifications_enabled = False
258263
return not self._notifications_enabled
259264

@@ -306,7 +311,7 @@ async def _ensure_encryption_initialized(self) -> bool:
306311
result = await self._send_command(
307312
COMMAND_GET_CK_IV + self._key_id, encrypt=False
308313
)
309-
ok = self._check_command_result(result, 0, {0x01})
314+
ok = self._check_command_result(result, 0, COMMAND_RESULT_EXPECTED_VALUES)
310315
if ok:
311316
self._iv = result[4:]
312317

0 commit comments

Comments
 (0)