Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary 📝
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 (home-assistant/core#94994 (review))
Details
The
parser
module has one class,VictronBluetoothDeviceData
, which parses Bleak advertisements and updates itself with the sensor data from the advertisement. Each instance ofVictronBluetoothDeviceData
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.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 (Add current flow support Bluetooth-Devices/sensor-state-data#47). For that reason, we need a custom extension ofsensor-state-data
, which is contained in thecustom-sensor-state.py
file.Checks