【发布时间】:2021-10-28 00:15:18
【问题描述】:
我正在编写一个快速例程来检查我的 SamsungTV 的状态(开/关/待机)。电视关闭时它似乎在大约 60 秒后超时,但它在打开或待机时非常快。所以我试图在 10 秒后超时。我遇到了一个错误,正在努力找出等待:
sys.path.append('../')
async def tryit():
# Normal constructor
tv = SamsungTVWS('192.168.1.209')
# Autosave token to file
token_file = os.path.dirname(os.path.realpath(__file__)) + '/tv-token.txt'
tv = SamsungTVWS(host='192.168.1.209', port=8002, token_file=token_file)
# Get device info (device name, model, supported features..)
try:
with async_timeout(10):
info = await tv.rest_device_info()
tvState = info['device']['PowerState']
except asyncio.TimeoutError as err:
tvState = 'off'
print(tvState)
return tvState
tryit()
我收到以下错误:我在哪里出错了?
/usr/local/bin/python3.8 /Users/ryanbuckner/PycharmProjects/samsungtvw/tv.py
/Users/ryanbuckner/PycharmProjects/samsungtvw/tv.py:37: RuntimeWarning: coroutine 'tryit' was never awaited
tryit()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
【问题讨论】: