#!/usr/bin/env python3
"""
Power cycle the ECU via MUM
"""
import argparse
import time
from pymumclient import MelexisUniversalMaster
from config import MUM_HOST, MUM_POWER_DEVICE, POWER_CYCLE_WAIT_TIME

def main():
    parser = argparse.ArgumentParser(description='Power cycle ECU via MUM')
    parser.add_argument('--host', default=MUM_HOST,
                       help=f'MUM IP address (default: {MUM_HOST})')
    parser.add_argument('--wait', type=float, default=POWER_CYCLE_WAIT_TIME,
                       help=f'Wait time in seconds (default: {POWER_CYCLE_WAIT_TIME})')
    args = parser.parse_args()

    print(f"Connecting to MUM at {args.host}...")
    mum = MelexisUniversalMaster()
    mum.open_all(args.host)

    power_control = mum.get_device(MUM_POWER_DEVICE)

    print("Powering down ECU...")
    power_control.power_down()
    print(f"Waiting {args.wait} seconds...")
    time.sleep(args.wait)

    print("Powering up ECU...")
    power_control.power_up()
    print(f"Waiting {args.wait} seconds for ECU to boot...")
    time.sleep(args.wait)

    print("Power cycle complete!")

if __name__ == "__main__":
    main()
