Skip to content

Commit

Permalink
Add more logging on errors #39
Browse files Browse the repository at this point in the history
  • Loading branch information
amosyuen committed Mar 4, 2022
1 parent 29fedd0 commit e2b9733
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions custom_components/tplink_deco/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,32 @@ async def async_list_clients(self) -> dict:
data = self._decrypt_data("List Devices", response_json["data"])
error_code = data.get("error_code")
if error_code != 0:
_LOGGER.debug("list devices error data=%s", data)
raise Exception(f"List devices error {error_code}")

# Store the devices in dict based on mac address
deco_devices = {x["mac"]: x["nickname"] for x in data["result"]["device_list"]}

clients = {}
for deco_mac, deco_name in deco_devices.items():
context = f"List Clients {deco_mac}"
client_payload = {"operation": "read", "params": {"device_mac": deco_mac}}
response_json = await self._async_post(
"List Clients",
context,
f"http://{self.host}/cgi-bin/luci/;stok={self._stok}/admin/client",
params={"form": "client_list"},
data=self._encode_payload(client_payload),
)

data = self._decrypt_data("List Clients", response_json["data"])
data = self._decrypt_data(context, response_json["data"])
error_code = data.get("error_code")
if error_code != 0:
_LOGGER.debug("list clients error data=%s", data)
raise Exception(f"List clients error {error_code}")

client_list = data["result"]["client_list"]
# client_list is only the connected clients
_LOGGER.debug("%s::len(client_list)=%d", deco_name, len(client_list))
_LOGGER.debug("%s len(client_list)=%d", context, len(client_list))

for client in client_list:
clients[client["mac"]] = client
Expand Down

0 comments on commit e2b9733

Please sign in to comment.