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 Snooz BLE devices #78790

Merged
merged 42 commits into from
Oct 10, 2022
Merged

Conversation

AustinBrunkhorst
Copy link
Contributor

@AustinBrunkhorst AustinBrunkhorst commented Sep 19, 2022

Proposed change

Add support for Snooz BLE devices.

Thoroughly tested on multiple generations of the White Noise Machine model.

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

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
  • 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.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@bdraco
Copy link
Member

bdraco commented Oct 1, 2022

Ideally the user knows nothing about the connected state of the device.

I'm not sure how these devices work as I don't have one, but since the esphome devices have low connection limits and most bluetooth dongles start to fail with > 3-4 usually we don't stay connected to the device unless we know we are going to send commands.

At least for switchbots we disconnect after 20s if they haven't sent any more commands https://github.com/Danielhiversen/pySwitchbot/blob/36b03594762311942558c364ccb6b9aa6731d84a/switchbot/devices/device.py#L207

I haven't checked the lib to see if you are holding the connection for a long time or not but given the disconnect call I expect it is.

If you can't get the state from the advertisements, you are probably stuck with an always connected state like led_ble

@AustinBrunkhorst
Copy link
Contributor Author

AustinBrunkhorst commented Oct 2, 2022

Ideally the user knows nothing about the connected state of the device.

I'm not sure how these devices work as I don't have one, but since the esphome devices have low connection limits and most bluetooth dongles start to fail with > 3-4 usually we don't stay connected to the device unless we know we are going to send commands.

At least for switchbots we disconnect after 20s if they haven't sent any more commands https://github.com/Danielhiversen/pySwitchbot/blob/36b03594762311942558c364ccb6b9aa6731d84a/switchbot/devices/device.py#L207

I haven't checked the lib to see if you are holding the connection for a long time or not but given the disconnect call I expect it is.

If you can't get the state from the advertisements, you are probably stuck with an always connected state like led_ble

@bdraco Unfortunately, the state isn't included in the advertisements. The lib does hold a connection for a long time - how about a config setting "use persistent connection"? When disabled, it would disconnect devices after a specified command timeout like you mentioned for switchbot.

I originally spent a good amount of time adding connection resilience to the lib since in testing it was somewhat painful for a 5-6 second command delay for "cold start" connections. I understand that not all users may want to have a persistent connection especially if the hardware is limited.

@bdraco
Copy link
Member

bdraco commented Oct 2, 2022

If the device pushes updates via notify it is ok to hold the connection. If it doesn't it might be better to poll every so often instead.

It looks like it gets push updates https://github.com/AustinBrunkhorst/pysnooz/blob/61d5ffe1a115acd567781d22664e9998bf3fbf77/src/pysnooz/api.py#L98

I wouldn't add an option to disable the connection since it will make the integration more complex and probably not the best UX. Instead, maybe document that it needs a persistent connection

Co-authored-by: J. Nick Koston <nick@koston.org>
AustinBrunkhorst and others added 4 commits October 9, 2022 12:27
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@koston.org>
@bdraco
Copy link
Member

bdraco commented Oct 9, 2022

I think the code may pass all the mypy checks or is really close to it so you could add it to .strict-typing

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.

Retested with library bump 👍

@bdraco bdraco merged commit 7d097d1 into home-assistant:dev Oct 10, 2022
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please address the comments in a new PR. Thanks!

homeassistant/components/snooz/config_flow.py Show resolved Hide resolved
tests/components/snooz/test_config.py Show resolved Hide resolved
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 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.

4 participants