2 Commits dd6dcfcbea ... e9482cc659

Author SHA1 Message Date
  J. Nick Koston e9482cc659 0.20.8 1 year ago
  J. Nick Koston c2876a1c6d Clear the services cache when a characteristic is missing (#144) 1 year ago
2 changed files with 13 additions and 2 deletions
  1. 2 2
      setup.py
  2. 11 0
      switchbot/devices/device.py

+ 2 - 2
setup.py

@@ -3,8 +3,8 @@ 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"],
-    version="0.20.7",
+    install_requires=["async_timeout>=4.0.1", "bleak>=0.17.0", "bleak-retry-connector>=2.9.0"],
+    version="0.20.8",
     description="A library to communicate with Switchbot",
     author="Daniel Hjelseth Hoyer",
     url="https://github.com/Danielhiversen/pySwitchbot/",

+ 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)