2023-06-27 17:34:39 +08:00
|
|
|
import asyncio
|
2024-08-29 18:16:33 +08:00
|
|
|
from contextlib import suppress
|
2024-07-08 17:21:58 +08:00
|
|
|
from pytec.aioclient import AsyncioClient
|
2023-06-27 17:34:39 +08:00
|
|
|
|
2024-07-03 14:40:13 +08:00
|
|
|
|
2024-08-29 18:16:33 +08:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2023-06-27 17:34:39 +08:00
|
|
|
async def main():
|
2024-07-08 17:21:58 +08:00
|
|
|
tec = AsyncioClient()
|
2024-08-22 12:58:52 +08:00
|
|
|
await tec.connect() # (host="192.168.1.26", port=23)
|
2023-06-27 17:34:39 +08:00
|
|
|
await tec.set_param("s-h", 1, "t0", 20)
|
|
|
|
print(await tec.get_pwm())
|
|
|
|
print(await tec.get_pid())
|
|
|
|
print(await tec.get_pwm())
|
|
|
|
print(await tec.get_postfilter())
|
|
|
|
print(await tec.get_steinhart_hart())
|
2024-08-29 18:16:33 +08:00
|
|
|
|
|
|
|
polling_task = asyncio.create_task(poll_for_info(tec))
|
|
|
|
|
2023-06-27 17:34:39 +08:00
|
|
|
async for data in tec.report_mode():
|
|
|
|
print(data)
|
|
|
|
|
2024-08-29 18:16:33 +08:00
|
|
|
polling_task.cancel()
|
|
|
|
with suppress(asyncio.CancelledError):
|
|
|
|
await polling_task
|
2024-07-03 14:40:13 +08:00
|
|
|
|
2023-06-27 17:34:39 +08:00
|
|
|
asyncio.run(main())
|