From cce9c3f6063351af5bedc037b6480237786c5347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 30 Nov 2018 14:50:08 +0100 Subject: [PATCH] Adds get_bluetooth_devices to CLI (#19) --- googledevices/cli/commands.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/googledevices/cli/commands.py b/googledevices/cli/commands.py index d7ff550..d3abe4b 100644 --- a/googledevices/cli/commands.py +++ b/googledevices/cli/commands.py @@ -26,6 +26,22 @@ async def get_device_info(): LOOP.run_until_complete(get_device_info()) +@commands.command() +@click.argument('ip_address', required=1) +def get_bluetooth_devices(ip_address): + """Get bluetooth devices from a unit.""" + from googledevices.api.bluetooth import Bluetooth + + async def bluetooth_scan(): + """Get nearby bluetooth devices.""" + async with aiohttp.ClientSession() as session: + googledevices = Bluetooth(LOOP, session, ip_address) + await googledevices.scan_for_devices() + await googledevices.get_scan_result() + print(json.dumps(googledevices.devices, indent=4, sort_keys=True)) + LOOP.run_until_complete(bluetooth_scan()) + + @commands.command() @click.option('--subnet', type=str, default=None, help="Format 0.0.0.0/00") def get_all_devices(subnet):