Skip to content

Commit c42de55

Browse files
authored
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 devWaves/SwitchBot-MQTT-BLE-ESP32#80
1 parent e591eae commit c42de55

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

switchbot/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ def detection_callback(
114114
advertisement_data: bleak.backends.scanner.AdvertisementData,
115115
) -> None:
116116
"""BTLE adv scan callback."""
117+
_services = list(advertisement_data.service_data.values())
118+
if not _services:
119+
return
120+
_service_data = _services[0]
121+
117122
_device = device.address.replace(":", "").lower()
118-
_service_data = list(advertisement_data.service_data.values())[0]
119123
_model = chr(_service_data[0] & 0b01111111)
120124

121125
supported_types: dict[str, dict[str, Any]] = {
@@ -153,7 +157,8 @@ async def discover(
153157
devices = None
154158

155159
devices = bleak.BleakScanner(
156-
filters={"UUIDs": [str(_sb_uuid())]},
160+
# TODO: Find new UUIDs to filter on. For example, see
161+
# https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/4ad138bb09f0fbbfa41b152ca327a78c1d0b6ba9/devicetypes/meter.md
157162
adapter=self._interface,
158163
)
159164
devices.register_detection_callback(self.detection_callback)

0 commit comments

Comments
 (0)