keshavdv / victron-ble

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

Can we add a "get_payload" to each parsed_data-object? #7

Closed ctschach closed 1 year ago

ctschach commented 1 year ago

So I want to use the decoder library in my own application - using it in the documented way:

from victron_ble.devices import detect_device_type

data = <ble advertisement data>
parser = detect_device_type(data)
parsed_data = parser(<key>).parse(<ble advertisement data>)

I do need to call every single value to construct an dict:

result = {'temperature': parsed_data.get_temperature(), 'soc': parsed_data.get_soc() }      # and so on...

Wouldn't it be an option to add a "get_payload" to each of the DeviceData class which will deliver the complete payload with one call? So something like:

class BatteryMonitorData(DeviceData):
    def __init__(self, data: Dict[str, Any]) -> None:
        self._data = data

    def get_payload(self):
        return self._data
keshavdv commented 1 year ago

I avoided doing this intentionally at first to try and make the API more typing friendly and defer some of the legwork to consumers of the library. If this is critical, we could add explicit data types to encode the entire payload for each device and still maintain the type safety when adding something like this.

ctschach commented 1 year ago

Okay, got your point...then let's leave this for later....