import asyncio import logging from pathlib import Path import datetime from app.my_dataclasses import TION_MAC from app.tion import TionController, TionService from schedule import ( ScheduleService, load_schedule, ) logging.disable(logging.CRITICAL) PROJECT_ROOT = Path(__file__).resolve().parents[1] SCHEDULE_FILE = ( PROJECT_ROOT / "config" / "schedule.yaml" ) async def main(): config = load_schedule(SCHEDULE_FILE) controller = TionController(TION_MAC) tion = TionService( controller, poll_interval=5, ) schedule = ScheduleService( config, tion, check_interval=5, ) await tion.start() await schedule.start() print("Schedule started. Ctrl+C to stop.") try: while True: await asyncio.sleep(5) if tion.state: print( f"{datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S")} " f"power={tion.state.power} " f"speed={tion.state.fan_speed} " f"heater={tion.state.heater} " f"target_temp={tion.state.target_temp} " f"last_error={tion.last_error} " ) finally: await schedule.stop() await tion.stop() if __name__ == "__main__": asyncio.run(main())