diff --git a/victron_ble/scanner.py b/victron_ble/scanner.py index d01310e..cbac316 100644 --- a/victron_ble/scanner.py +++ b/victron_ble/scanner.py @@ -64,10 +64,11 @@ def default(self, obj): class Scanner(BaseScanner): - def __init__(self, device_keys: dict[str, str] = {}): + def __init__(self, device_keys: dict[str, str] = {}, output_callback=None): super().__init__() self._device_keys = {k.lower(): v for k, v in device_keys.items()} self._known_devices: dict[str, Device] = {} + self._output_callback = output_callback async def start(self): logger.info(f"Reading data for {list(self._device_keys.keys())}") @@ -112,7 +113,10 @@ def callback(self, ble_device: BLEDevice, raw_data: bytes): "rssi": ble_device.rssi, "payload": parsed, } - print(json.dumps(blob, cls=DeviceDataEncoder, indent=2)) + if self._output_callback is not None: + self._output_callback(blob) + else: + print(json.dumps(blob, cls=DeviceDataEncoder, indent=2)) class DiscoveryScanner(BaseScanner):