Browse Source

Clear the services cache when a characteristic is missing

J. Nick Koston 1 year ago
parent
commit
20a616f5ac
2 changed files with 12 additions and 1 deletions
  1. 1 1
      setup.py
  2. 11 0
      switchbot/devices/device.py

+ 1 - 1
setup.py

@@ -3,7 +3,7 @@ from setuptools import setup
 setup(
     name="PySwitchbot",
     packages=["switchbot", "switchbot.devices", "switchbot.adv_parsers"],
-    install_requires=["async_timeout>=4.0.1", "bleak>=0.17.0", "bleak-retry-connector>=1.17.1"],
+    install_requires=["async_timeout>=4.0.1", "bleak>=0.17.0", "bleak-retry-connector>=2.9.0"],
     version="0.20.7",
     description="A library to communicate with Switchbot",
     author="Daniel Hjelseth Hoyer",

+ 11 - 0
switchbot/devices/device.py

@@ -307,6 +307,17 @@ class SwitchbotBaseDevice:
         await self._ensure_connected()
         try:
             return await self._execute_command_locked(key, command)
+        except CharacteristicMissingError as ex:
+            _LOGGER.debug(
+                "%s: characteristic missing, clearing cache: %s; RSSI: %s",
+                self.name,
+                ex,
+                self.rssi,
+                exc_info=True,
+            )
+            await self._client.clear_cache()
+            await self._execute_forced_disconnect()
+            raise
         except BleakDBusError as ex:
             # Disconnect so we can reset state and try again
             await asyncio.sleep(0.25)