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

Add support for sleepy BTHome devices #92991

Merged
merged 5 commits into from May 21, 2023

Conversation

Ernst79
Copy link
Contributor

@Ernst79 Ernst79 commented May 12, 2023

Proposed change

This PR adds support for "sleepy" BTHome devices. Sleepy devices are sensors that do not send BLE data on a regular basis, but only when e.g. pushing a button or opening a door. BTHome has added a flag in the BLE advertisement that tells the receiver (HA) that the device isn't sending updates on a regular basis. This PR makes sure that these "sleepy" devices remain availalable.

bthome-ble change logs

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@bdraco bdraco marked this pull request as draft May 19, 2023 16:42
@bdraco
Copy link
Member

bdraco commented May 19, 2023

    @property
    def available(self) -> bool:
        """Return True if entity is available."""
        coordinator: BTHomePassiveBluetoothProcessorCoordinator = self.processor.coordinator
        return coordinator.device_data.sleepy_device or super().available

Leaving as draft until the following can be made

@Ernst79 Ernst79 marked this pull request as ready for review May 20, 2023 13:45
@bdraco
Copy link
Member

bdraco commented May 20, 2023

Looks good. I think we can copy the xiaomi ble test and modify it a bit and than this is good to go

@Ernst79
Copy link
Contributor Author

Ernst79 commented May 20, 2023

I’ll take care of Xiaomi-ble in a separate PR

@bdraco
Copy link
Member

bdraco commented May 20, 2023

I think we still need the test that it is treated as sleepy there though.

@Ernst79
Copy link
Contributor Author

Ernst79 commented May 21, 2023

Ah, sorry, I wasn't reading right, I thought you said we should copy this change to xiaomi-ble, but you meant copying the tests from xiaomi-ble to bthome for the sleepy_devices.

I have added the tests.

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Thanks @Ernst79

Looks much better now 👍

@bdraco bdraco merged commit 40c74ad into home-assistant:dev May 21, 2023
52 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2023
@frenck frenck added the noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label May 30, 2023
@Ernst79 Ernst79 deleted the bthome_improvements branch January 20, 2024 10:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
by-code-owner cla-signed dependency has-tests integration: bthome new-feature noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) Quality Scale: No score small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants