Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ble client additions and fixes #5277

Merged
merged 35 commits into from
Dec 29, 2023
Merged

Ble client additions and fixes #5277

merged 35 commits into from
Dec 29, 2023

Conversation

clydebarrow
Copy link
Contributor

@clydebarrow clydebarrow commented Aug 18, 2023

What does this implement/fix?

  • Add new actions for the ble_client component - ble_client.connect and ble_client.disconnect;
  • Add new config option for ble_client - auto_connect;
  • Fix (at least) one bug;
  • Use play_complex() and play_next() in the new actions, and the existing ble_client.ble_write action so that they can be used sequentially in automation blocks.
  • General cleanup and refactor of the ble_client code with particular attention to correct handling of events, especially when multiple actions/triggers are active on the same client.

The ble_client modules for sensor, binary_sensor, switch and the various triggers have been tested on hardware. Other components for specific hardware that rely on the ble_client component have not been tested by me due to lack of access to that hardware, but compilation has been tested for a selection of these, and a careful code review has been performed to check for potential breaking changes in the BLEClient class.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes esphome/issues#4802

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#3138

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040

Example entry for config.yaml:

# Example config.yaml
ble_client:
  - id: ble_clock
    mac_address: 17:75:BC:F2:94:4D
    auto_connect: false
  - id: door
    mac_address: 00:0D:6F:F6:1C:B3
  - id: blout
    mac_address: 68:b6:b3:21:69:92

time:
  - platform: sntp
    id: sntp_time
    timezone: Australia/Sydney

interval :
  - interval: 60min
    then:
      - if:
          condition:
            time.has_time:
          then:
            - esp32_ble_tracker.stop_scan:
            - ble_client.connect: ble_clock
            - ble_client.ble_write:
                id: ble_clock
                service_uuid: EBE0CCB0-7A0A-4B0C-8A1A-6FF2997DA3A6
                characteristic_uuid: EBE0CCB7-7A0A-4B0C-8A1A-6FF2997DA3A6
                value: !lambda |-
                    uint32_t t = id(sntp_time).now().timestamp + ESPTime::timezone_offset();
                    return {(uint8_t)t, (uint8_t)(t >> 8), (uint8_t)(t >> 16), (uint8_t)(t >> 24), 0};
            - ble_client.disconnect: ble_clock
            - esp32_ble_tracker.start_scan:

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

Hey there @buxtronix, mind taking a look at this pull request as it has been labeled with an integration (ble_client) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

Hey there @jesserockz, mind taking a look at this pull request as it has been labeled with an integration (esp32_ble_client) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@clydebarrow
Copy link
Contributor Author

Not stale, just waiting for review.

@clydebarrow
Copy link
Contributor Author

Still not stale - just old :-)

@2m
Copy link

2m commented Nov 25, 2023

Eagerly waiting for this. :) Currently it is not convenient to control Valve Basestations with ESPHome, because when ESPHome is connected, then my PC can not see base stations at all.

@tvvalbonne
Copy link

Any chance to get this reviewed? waiting for it...

@kbx81 kbx81 merged commit 5ebb68f into esphome:dev Dec 29, 2023
49 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BLE Sensor notify config flag not working
6 participants