Skip to content

Commit

Permalink
Merge pull request #59 from zouppen/single_line_output
Browse files Browse the repository at this point in the history
Output JSON which is on a single line
  • Loading branch information
keshavdv authored Oct 9, 2024
2 parents 9a7f6cd + 705a663 commit a227b77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion victron_ble/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def read(device_keys: List[Tuple[str, str]]):
loop = asyncio.get_event_loop()

async def scan(keys):
scanner = Scanner(keys)
scanner = Scanner(keys, indent=None)
await scanner.start()

asyncio.ensure_future(scan({k: v for k, v in device_keys}))
Expand Down
5 changes: 3 additions & 2 deletions victron_ble/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}, indent = 2):
super().__init__()
self._device_keys = {k.lower(): v for k, v in device_keys.items()}
self._known_devices: dict[str, Device] = {}
self._indent = indent

async def start(self):
logger.info(f"Reading data for {list(self._device_keys.keys())}")
Expand Down Expand Up @@ -112,7 +113,7 @@ def callback(self, ble_device: BLEDevice, raw_data: bytes):
"rssi": ble_device.rssi,
"payload": parsed,
}
print(json.dumps(blob, cls=DeviceDataEncoder, indent=2))
print(json.dumps(blob, cls=DeviceDataEncoder, indent=self._indent), flush=True)


class DiscoveryScanner(BaseScanner):
Expand Down

0 comments on commit a227b77

Please sign in to comment.