async def fetch_all_devices_sys_info():
devices = await device_manager.get_devices()
fetch_tasks = []
for device in devices:
async def get_info(device):
print(f'Found {device.model_type.name} device: {device.get_alias()}')
print("SYS INFO")
print(json.dumps(device.device_info, indent=2, default=lambda x: vars(x)
if hasattr(x, "dict") else x.name if hasattr(x, "name") else None))
print(json.dumps(await device.get_sys_info(), indent=2, default=lambda x: vars(x)
if hasattr(x, "dict") else x.name if hasattr(x, "name") else None))
tasks.append(get_info(device))
await asyncio.gather(*fetch_tasks)
asyncio.run(fetch_all_devices_sys_info())
Starting "kasa.py" nothing happens , because the Login-Credentials are wrong, it returns to the Prompt.
But if i start with valid Kasa-Credentials:
pi@bullseye:/ram/lookout $ python3 kasa.py
Traceback (most recent call last):
File "/ram/lookout/kasa.py", line 24, in
asyncio.run(fetch_all_devices_sys_info())
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/ram/lookout/kasa.py", line 21, in fetch_all_devices_sys_info
tasks.append(get_info(device))
NameError: name 'tasks' is not defined
Please, please be gentle, this is my first Entry ever on GitHub.
Copied this into kasa.py:
from tplinkcloud import TPLinkDeviceManager
import asyncio import json
username = 'kasa@email.com' password = 'secure' device_manager = TPLinkDeviceManager(username, password)
async def fetch_all_devices_sys_info(): devices = await device_manager.get_devices() fetch_tasks = [] for device in devices: async def get_info(device): print(f'Found {device.model_type.name} device: {device.get_alias()}') print("SYS INFO") print(json.dumps(device.device_info, indent=2, default=lambda x: vars(x) if hasattr(x, "dict") else x.name if hasattr(x, "name") else None)) print(json.dumps(await device.get_sys_info(), indent=2, default=lambda x: vars(x) if hasattr(x, "dict") else x.name if hasattr(x, "name") else None)) tasks.append(get_info(device)) await asyncio.gather(*fetch_tasks)
asyncio.run(fetch_all_devices_sys_info())
Starting "kasa.py" nothing happens , because the Login-Credentials are wrong, it returns to the Prompt.
But if i start with valid Kasa-Credentials:
pi@bullseye:/ram/lookout $ python3 kasa.py Traceback (most recent call last): File "/ram/lookout/kasa.py", line 24, in
asyncio.run(fetch_all_devices_sys_info())
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/ram/lookout/kasa.py", line 21, in fetch_all_devices_sys_info
tasks.append(get_info(device))
NameError: name 'tasks' is not defined
What is happening here?