thermostat/pythermostat/aioexample.py

34 lines
793 B
Python
Raw Permalink Normal View History

2024-11-04 11:57:02 +08:00
import asyncio
from contextlib import suppress
from pythermostat.aioclient import AsyncioClient
async def poll_for_settings(tec):
while True:
print(await tec.get_output())
print(await tec.get_b_parameter())
print(await tec.get_pid())
print(await tec.get_postfilter())
print(await tec.get_fan())
await asyncio.sleep(1)
async def main():
tec = AsyncioClient()
await tec.connect() # (host="192.168.1.26", port=23)
await tec.set_param("b-p", 1, "t0", 20)
polling_task = asyncio.create_task(poll_for_settings(tec))
while True:
print(await tec.get_report())
await asyncio.sleep(0.05)
polling_task.cancel()
with suppress(asyncio.CancelledError):
await polling_task
asyncio.run(main())