소스 검색

HACK: Handle new UUIDs in SwitchBot firmware (#48)

The new SwitchBot firmware advertises its services differently, making
the old UUID filter not find any SwitchBot devices. This commit is a
quick-fix to remove the filter and simply allow the rest of the
discovery code to handle it as before.

This should be backwards compatible with the old firmware since the rest
of the discovery and initialization is exactly the same.

See also https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32/issues/80
Charlie Wang 1 년 전
부모
커밋
c42de55b91
1개의 변경된 파일7개의 추가작업 그리고 2개의 파일을 삭제
  1. 7 2
      switchbot/__init__.py

+ 7 - 2
switchbot/__init__.py

@@ -114,8 +114,12 @@ class GetSwitchbotDevices:
         advertisement_data: bleak.backends.scanner.AdvertisementData,
     ) -> None:
         """BTLE adv scan callback."""
+        _services = list(advertisement_data.service_data.values())
+        if not _services:
+            return
+        _service_data = _services[0]
+
         _device = device.address.replace(":", "").lower()
-        _service_data = list(advertisement_data.service_data.values())[0]
         _model = chr(_service_data[0] & 0b01111111)
 
         supported_types: dict[str, dict[str, Any]] = {
@@ -153,7 +157,8 @@ class GetSwitchbotDevices:
         devices = None
 
         devices = bleak.BleakScanner(
-            filters={"UUIDs": [str(_sb_uuid())]},
+            # TODO: Find new UUIDs to filter on. For example, see
+            # https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/4ad138bb09f0fbbfa41b152ca327a78c1d0b6ba9/devicetypes/meter.md
             adapter=self._interface,
         )
         devices.register_detection_callback(self.detection_callback)