Skip to content

Conversation

Gibstick
Copy link
Contributor

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

I don't really know Bluetooth so this is just a total hack that seemed to work. But from reading of the rest of the code, it's still handling advertisement data and making sure it's a supported model, so this change shouldn't hurt.

In theory, this should be backwards compatible with the old firmware since the rest of the discovery and initialization is exactly the same, but I don't have many devices to test with. Running a scan, I was able to find my own SwitchBot thermometer, and a neighbour's "WoHand" device, which I'm assuming is a switch. Before, I wasn't able to find any devices.

See also devWaves/SwitchBot-MQTT-BLE-ESP32#80

This seems to address home-assistant/core#70262, since after this patch I was able to have HomeAssistant discover my neighbour's switch.

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
@caddyblack
Copy link

Any chance this will be implemented?

@mike1627
Copy link

Worked perfectly, thank you!

Copy link

@mike1627 mike1627 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored functionality to my switchbot curtains with firmware rev 4.6 update

@EWK1
Copy link

EWK1 commented Jul 18, 2022

@Danielhiversen Could you please merge and publish this quickly? Thank you!

@Gibstick Gibstick changed the title HACK: Handle new UUIDs in SwitchBot firmware Remove filter to handle new UUIDs in SwitchBot firmware Jul 18, 2022
@asucrews
Copy link

@RenierM26 are you about to help out?

@MickL
Copy link

MickL commented Jul 19, 2022

Does a maintainer may have time to review? :)
@murtas @RenierM26 @Danielhiversen

@Danielhiversen
Copy link
Collaborator

Will look into it later this week

@Danielhiversen Danielhiversen merged commit c42de55 into sblibs:master Jul 20, 2022
@MickL
Copy link

MickL commented Jul 23, 2022

I do now get "Unexpected error" when adding the HA integration:

Bildschirmfoto 2022-07-23 um 13 46 47

Is it related to this changes? The error before the update was "failed to connect" with no logs at all.

Raspberry Pi 3
Homeassistant OS (core-2022.7.6)
SwitchBot Meter Plus

Logs:

Logger: homeassistant.components.switchbot.config_flow
Source: components/switchbot/config_flow.py:34 
Integration: SwitchBot (documentation, issues) 
First occurred: 21 July 2022, 13:11:29 (6 occurrences) 
Last logged: 13:46:44

Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 89, in async_step_user
    self._discovered_devices = await self._get_switchbots()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 55, in _get_switchbots
    _btle_adv_data = await _btle_connect()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 34, in _btle_connect
    switchbot_devices = await GetSwitchbotDevices().discover()
  File "/usr/local/lib/python3.10/site-packages/switchbot/__init__.py", line 169, in discover
    await devices.stop()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 177, in stop
    assert_reply(reply)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] Operation already in progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants