keshavdv / victron-ble

A Python API to parse Victron Instant Readout BLE advertisements
The Unlicense
88 stars 30 forks source link

Parser for Home Assistant #34

Closed rajlaud closed 9 months ago

rajlaud commented 1 year ago

Summary :memo:

To integrate with Home Assistant core, they've asked that I move some of the logic from the HA component to the Python library. This PR does that by creating a new module called parser that handles incoming Bluetooth advertisements in a way that integrates cleanly with HA.

If you'd rather I spin this into a separate project I can do that too, but I thought it would be cleaner to have everything in one dependency.

I've tested locally with these changes, and once this is merged and a new version released, I can push my local changes to the PR for HA core (https://github.com/home-assistant/core/pull/94994#pullrequestreview-1498141714)

Details

  1. The parser module has one class, VictronBluetoothDeviceData, which parses Bleak advertisements and updates itself with the sensor data from the advertisement. Each instance of VictronBluetoothDeviceData should be fed advertisements from exactly one Victron device (based on the MAC address) and the instance needs to be initiated with the encryption key of the device that is going to be sending updates. If the encryption key is set correctly everything else will be figured out automatically.

  2. There is a handy package from maintainers of the HA project called sensor-state-data to make it easy to automate ingesting sensor state updates like this. Unfortunately, we need to use a unit (amp-hours) not supported by the module and my PR to include amp-hours was rejected because they are not a common unit (https://github.com/Bluetooth-Devices/sensor-state-data/pull/47). For that reason, we need a custom extension of sensor-state-data, which is contained in the custom-sensor-state.py file.

Checks

rajlaud commented 11 months ago

@keshavdv just curious if you are interested in incorporating this or if you'd prefer I spin it off into a separate project.

keshavdv commented 10 months ago

I think it might be best to put these in a dedicated repo!