Browse Source

fix: reject advertisement updates that are missing data if we already have it (#93)

J. Nick Koston 2 years ago
parent
commit
1ebcc8cabe
1 changed files with 4 additions and 1 deletions
  1. 4 1
      switchbot/devices/device.py

+ 4 - 1
switchbot/devices/device.py

@@ -357,7 +357,10 @@ class SwitchbotDevice:
 
     def update_from_advertisement(self, advertisement: SwitchBotAdvertisement) -> None:
         """Update device data from advertisement."""
-        self._sb_adv_data = advertisement
+        # Only accept advertisements if the data is not missing
+        # if we already have an advertisement with data
+        if advertisement.data.get("data") or not self._sb_adv_data.data.get("data"):
+            self._sb_adv_data = advertisement
         self._override_adv_data = None
         if self._device and ble_device_has_changed(self._device, advertisement.device):
             self._cached_services = None