import asyncio
from bleak import BleakScanner, BleakError

async def main():
    print("Scanning for BLE devices...")
    try:
        devices = await BleakScanner.discover()
        print(f"Found {len(devices)} devices:")
        for device in devices:
            print(f"MAC Address: {device.address}, Name: {device.name}")
    except BleakError as e:
        print(f"Error: {e}")
        print("Make sure Bluetooth is enabled and a Bluetooth adapter is present.")

if __name__ == "__main__":
    asyncio.run(main())