"""Step 2 - Find the robot car.

This script only looks. It does not move the car.

Run it:
    Windows:  python find.py
    Mac:      python3 find.py

Install bleak first:
    Windows:  python -m pip install bleak
    Mac:      python3 -m pip install bleak

On a Mac, say yes when it asks for Bluetooth.
If you miss it: System Settings > Privacy and Security >
Bluetooth > turn on your Terminal app.
"""
import asyncio

from bleak import BleakScanner


async def main():
    print("Looking for the robot...")
    devices = await BleakScanner.discover(timeout=10)

    found = False
    for d in devices:
        if d.name and "micro:bit" in d.name:
            print("Found it:", d.name)
            found = True

    if not found:
        print("No robot.")
        print("Is the car on?")
        print("Is the phone app closed?")
        print("Are you near the car?")


asyncio.run(main())
