"""Scan the bus and list which Feetech servo IDs respond to ping.

Usage:
  python scan_ids.py [--max 15] [--port /dev/tty...]
"""
import argparse

from feetech_bus import Bus


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--max", type=int, default=15, help="highest id to probe (default 15)")
    ap.add_argument("--port", default=None)
    a = ap.parse_args()

    bus = Bus(a.port) if a.port else Bus()
    try:
        found = [mid for mid in range(a.max + 1) if bus.ping(mid)]
        print(f"found {len(found)} servo(s): {found}" if found else "no servos found")
    finally:
        bus.close()


if __name__ == "__main__":
    main()
