1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
"""QNAP QSW basic example."""
import asyncio
import json
import timeit
import _config
import aiohttp
from aioqsw.exceptions import APIError
from aioqsw.localapi import QnapQswApi
async def main():
"""QNAP QSW basic example."""
async with aiohttp.ClientSession() as aiohttp_session:
qsw = QnapQswApi(aiohttp_session, _config.QNAP_QSW_OPTIONS)
try:
system_board = await qsw.validate()
if system_board is not None:
print(f"System Board: {system_board.data()}")
print("***")
update_start = timeit.default_timer()
await qsw.update()
update_end = timeit.default_timer()
print(json.dumps(qsw.data(), indent=4, sort_keys=True))
print(f"Update time: {update_end - update_start}")
print("***")
print("Waiting 5 seconds to gather speed data")
await asyncio.sleep(5)
print("***")
update_start = timeit.default_timer()
await qsw.update()
update_end = timeit.default_timer()
print(json.dumps(qsw.data(), indent=4, sort_keys=True))
print(f"Update time: {update_end - update_start}")
except APIError:
print("Invalid host.")
if __name__ == "__main__":
asyncio.run(main())
|