core icon indicating copy to clipboard operation
core copied to clipboard

RuuviTag BLE sensor support

Open akx opened this issue 1 year ago • 9 comments

Proposed change

This PR adds HA native BLE support for RuuviTag sensors.

It's cold around here: Screenshot 2022-10-31 at 22 47 33

Type of change

  • [ ] Dependency upgrade
  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [x] 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

The code for the component is mostly copy-pasted from the tilt_ble component (it would seem that the various *_ble components could use some deduplication...). Similarly, the ruuvitag-ble parser component has been adapted from https://github.com/Bluetooth-Devices/xiaomi-ble; the code from which ruuvitag-ble==0.1.0rc1 has been built from is https://github.com/akx/ruuvitag-ble/tree/initial-dev.

This is my first real HA contribution, so hand-holding would be welcome. I suspect @bdraco might be the person best suited to look at this BLE stuff...

Checklist

  • [x] The code change is tested and works locally.
    • I've tested that the RuuviTags around my house and garden are detected by HA; see screenshot above.
  • [x] Local tests pass. Your PR cannot be merged unless tests pass
  • [x] There is no commented out code in this PR.
  • [x] I have followed the development checklist
    • Communication code is encapsulated into ruuvitag-ble. PR to merge it into the Bluetooth-Devices repo: https://github.com/Bluetooth-Devices/ruuvitag-ble/pull/2
  • [x] The code has been formatted using Black (black --fast homeassistant tests)
  • [x] Tests have been added to verify that the new code works.

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

  • [x] Documentation added/updated for www.home-assistant.io
    • https://github.com/home-assistant/home-assistant.io/pull/24767

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

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

To help with the load of incoming pull requests:

akx avatar Oct 31 '22 20:10 akx

Hi akx

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

home-assistant[bot] avatar Oct 31 '22 20:10 home-assistant[bot]

I’m traveling this week but I can try to give you some initial feedback when I’m making connections.

If I don’t get back to this by Saturday feel free to ping me

bdraco avatar Nov 01 '22 14:11 bdraco

@bdraco Hope your travels went fine! Post-Saturday ping :)

akx avatar Nov 06 '22 14:11 akx

CI started

bdraco avatar Nov 06 '22 14:11 bdraco

We do need 100% coverage on the config flow before we can merge this.

bdraco avatar Nov 06 '22 14:11 bdraco

We do need 100% coverage on the config flow before we can merge this.

@bdraco I copied a config flow test from tilt_ble (since the config flow itself was copied from there) and just adapted the constants. I'm not going to pretend I understand how the config flow system works in depth, so I hope that's okay.

akx avatar Nov 06 '22 18:11 akx

Looks like the tests are failing because the conftest.py file was removed

bdraco avatar Nov 07 '22 13:11 bdraco

@bdraco Bleh, right. Didn't notice the implicit autouse fixture there. Funnily, tests pass just fine on my macOS machine without it.

Fixed...

akx avatar Nov 07 '22 14:11 akx

@bdraco Unrelated test seems to segfault 😞

akx avatar Nov 07 '22 17:11 akx

Oh hey @bdraco, one more question – I realized that the movement_counter wasn't visible because I had set native_unit_of_measurement to None... what would be the correct native_unit_of_measurement for a dimensionless quantity like that?

akx avatar Nov 08 '22 08:11 akx