work: Реализована работа расписания. Проведен первый тест.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
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"power={tion.state.power} "
|
||||
f"speed={tion.state.fan_speed} "
|
||||
f"heater={tion.state.heater}"
|
||||
)
|
||||
|
||||
finally:
|
||||
await schedule.stop()
|
||||
await tion.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user