from __future__ import annotations

import sys
from pathlib import Path


ROOT = next(parent for parent in Path(__file__).resolve().parents if (parent / "cosmic_driver").is_dir())
sys.path.insert(0, str(ROOT))

from cosmic_driver import CosmicPySDK
from example_helpers import print_device_info, assert_status


def main() -> None:
    boot_mode_requested = False
    with CosmicPySDK(timeout_ms=2000) as device:
        if not device.open():
            raise RuntimeError("Failed to connect to a Binho device.")

        status, info = device.get_device_info()
        assert_status(status, "get_device_info")
        assert info is not None
        print_device_info(info)

        status, _ = device.enter_boot_mode()
        assert_status(status, "enter_boot_mode")
        boot_mode_requested = True
        print("Boot mode command sent successfully")

    if not boot_mode_requested:
        raise RuntimeError("Boot mode was not requested.")


if __name__ == "__main__":
    main()
