forked from M-Labs/thermostat
36 lines
933 B
Python
36 lines
933 B
Python
"""aioclient usage example"""
|
|
|
|
import asyncio
|
|
from contextlib import suppress
|
|
from pythermostat.aioclient import AsyncioClient
|
|
|
|
|
|
async def poll_for_settings(thermostat_async):
|
|
while True:
|
|
print(await thermostat_async.get_output())
|
|
print(await thermostat_async.get_b_parameter())
|
|
print(await thermostat_async.get_pid())
|
|
print(await thermostat_async.get_postfilter())
|
|
print(await thermostat_async.get_fan())
|
|
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
async def main():
|
|
thermostat_async = AsyncioClient()
|
|
await thermostat_async.connect()
|
|
await thermostat_async.set_param("b-p", 1, "t0", 20)
|
|
|
|
polling_task = asyncio.create_task(poll_for_settings(thermostat_async))
|
|
|
|
while True:
|
|
print(await thermostat_async.get_report())
|
|
await asyncio.sleep(0.05)
|
|
|
|
polling_task.cancel()
|
|
with suppress(asyncio.CancelledError):
|
|
await polling_task
|
|
|
|
|
|
asyncio.run(main())
|