From 5c8270834aa3e0ab4ecfcc7e8dc68b8a5cb138c5 Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 29 Aug 2024 18:16:33 +0800 Subject: [PATCH] aioexample: Show polling while report mode on WIP: handle KeyboardInterrupt --- pytec/examples/aioexample.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pytec/examples/aioexample.py b/pytec/examples/aioexample.py index 15fd483..f4a89e0 100644 --- a/pytec/examples/aioexample.py +++ b/pytec/examples/aioexample.py @@ -1,7 +1,19 @@ import asyncio +from contextlib import suppress from pytec.aioclient import AsyncioClient +async def poll_for_info(tec): + while True: + print(tec.get_pwm()) + print(tec.get_steinhart_hart()) + print(tec.get_pid()) + print(tec.get_postfilter()) + print(tec.get_fan()) + + await asyncio.sleep(1) + + async def main(): tec = AsyncioClient() await tec.connect() # (host="192.168.1.26", port=23) @@ -11,8 +23,14 @@ async def main(): print(await tec.get_pwm()) print(await tec.get_postfilter()) print(await tec.get_steinhart_hart()) + + polling_task = asyncio.create_task(poll_for_info(tec)) + async for data in tec.report_mode(): print(data) + polling_task.cancel() + with suppress(asyncio.CancelledError): + await polling_task asyncio.run(main())