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

Implement text_sensor based on ble_client #3079

Merged
merged 1 commit into from Feb 19, 2022
Merged

Conversation

ashald
Copy link
Contributor

@ashald ashald commented Jan 20, 2022

What does this implement/fix?

This PR implements text_sensor based on ble_client similarly to existing sensor component.

Currently, reading a string characteristic is possible via an obscure workaround:

ble_client:
  - mac_address: !secret ble_server_mac_address
    id: basement

text_sensor:
  - id: basement_last_activity
    platform: template

sensor:
  - name: "Ignored"
    platform: ble_client
    ble_client_id: basement
    service_uuid: !secret ble_service
    characteristic_uuid: !secret ble_characteristic_time
    lambda: |-
      std::string value(x.begin(), x.end());
      id(read_time).publish_state(value);
      return 0;

With this PR the above snippet can be simplified to what is show below.

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

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

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266

Example entry for config.yaml:

ble_client:
  - mac_address: !secret ble_server_mac_address
    id: basement

text_sensor:
  - id: basement_last_activity
    platform: ble_client
    ble_client_id: basement
    service_uuid: !secret ble_service
    characteristic_uuid: !secret ble_characteristic_time

Example log output

...
[01:14:52][C][ble_text_sensor:021]: BLE Text Sensor 'basement_last_activity'
[01:14:52][C][ble_text_sensor:022]:   MAC address        : ab:cd:de:00:11:22
[01:14:52][C][ble_text_sensor:023]:   Service UUID       : 9774321A-DEC1-461E-BD8D-D06902E9D950
[01:14:52][C][ble_text_sensor:024]:   Characteristic UUID: 64309E42-064B-4F39-80E4-A6DAD556CD5B
[01:14:52][C][ble_text_sensor:025]:   Descriptor UUID    : 00000000-0000-0000-0000-000000000000
[01:14:52][C][ble_text_sensor:026]:   Notifications      : NO
[01:14:52][C][ble_text_sensor:027]:   Update Interval: 60.0s
...
[01:15:23][D][text_sensor:067]: 'basement_last_activity': Sending state '2022-01-20T01:15:17'

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)

@buxtronix
Copy link
Contributor

looks good.

@ashald
Copy link
Contributor Author

ashald commented Jan 25, 2022

@buxtronix thanks for the review!
What would be the next step to get it merged?
Thanks!

@ashald
Copy link
Contributor Author

ashald commented Feb 10, 2022

Is there anyone who can merge this PR?

Copy link
Member

@OttoWinter OttoWinter left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. Just one minor issue 👍

Co-authored-by: Otto Winter <otto@otto-winter.com>
@OttoWinter OttoWinter merged commit 231908f into esphome:dev Feb 19, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2022
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.

None yet

3 participants