Skip to content

Commit c2876a1

Browse files
authored
Clear the services cache when a characteristic is missing (#144)
1 parent dd6dcfc commit c2876a1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name="PySwitchbot",
55
packages=["switchbot", "switchbot.devices", "switchbot.adv_parsers"],
6-
install_requires=["async_timeout>=4.0.1", "bleak>=0.17.0", "bleak-retry-connector>=1.17.1"],
6+
install_requires=["async_timeout>=4.0.1", "bleak>=0.17.0", "bleak-retry-connector>=2.9.0"],
77
version="0.20.7",
88
description="A library to communicate with Switchbot",
99
author="Daniel Hjelseth Hoyer",

switchbot/devices/device.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ async def _send_command_locked(self, key: str, command: bytes) -> bytes:
307307
await self._ensure_connected()
308308
try:
309309
return await self._execute_command_locked(key, command)
310+
except CharacteristicMissingError as ex:
311+
_LOGGER.debug(
312+
"%s: characteristic missing, clearing cache: %s; RSSI: %s",
313+
self.name,
314+
ex,
315+
self.rssi,
316+
exc_info=True,
317+
)
318+
await self._client.clear_cache()
319+
await self._execute_forced_disconnect()
320+
raise
310321
except BleakDBusError as ex:
311322
# Disconnect so we can reset state and try again
312323
await asyncio.sleep(0.25)

0 commit comments

Comments
 (0)