Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions devtools/dump_devinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
import asyncclick as click

from devtools.helpers.smartrequests import COMPONENT_REQUESTS, SmartRequest
from kasa import AuthenticationException, Credentials, Discover, SmartDevice
from kasa import (
AuthenticationException,
Credentials,
Discover,
SmartDevice,
SmartDeviceException,
TimeoutException,
)
from kasa.discover import DiscoveryResult
from kasa.exceptions import SmartErrorCode
from kasa.tapo.tapodevice import TapoDevice
Expand Down Expand Up @@ -227,11 +234,7 @@ async def get_legacy_fixture(device):
try:
final = await device.protocol.query(final_query)
except Exception as ex:
click.echo(
click.style(
f"Unable to query all successes at once: {ex}", bold=True, fg="red"
)
)
_echo_error(f"Unable to query all successes at once: {ex}", bold=True, fg="red")

if device._discovery_info and not device._discovery_info.get("system"):
# Need to recreate a DiscoverResult here because we don't want the aliases
Expand All @@ -254,6 +257,16 @@ async def get_legacy_fixture(device):
return save_filename, copy_folder, final


def _echo_error(msg: str):
click.echo(
click.style(
msg,
bold=True,
fg="red",
)
)


async def _make_requests_or_exit(
device: SmartDevice,
requests: List[SmartRequest],
Expand All @@ -277,17 +290,25 @@ async def _make_requests_or_exit(
final[method] = result
return final
except AuthenticationException as ex:
click.echo(
click.style(
f"Unable to query the device due to an authentication error: {ex}",
bold=True,
fg="red",
)
_echo_error(
f"Unable to query the device due to an authentication error: {ex}",
)
exit(1)
except SmartDeviceException as ex:
_echo_error(
f"Unable to query {name} at once: {ex}",
)
if (
isinstance(ex, TimeoutException)
or ex.error_code == SmartErrorCode.SESSION_TIMEOUT_ERROR
):
_echo_error(
"Timeout, try reducing the batch size via --batch-size option.",
)
exit(1)
except Exception as ex:
click.echo(
click.style(f"Unable to query {name} at once: {ex}", bold=True, fg="red")
_echo_error(
f"Unexpected exception querying {name} at once: {ex}",
)
exit(1)

Expand Down Expand Up @@ -361,12 +382,8 @@ async def get_smart_fixture(device: TapoDevice, batch_size: int):
SmartRequest._create_request_dict(test_call.request)
)
except AuthenticationException as ex:
click.echo(
click.style(
f"Unable to query the device due to an authentication error: {ex}",
bold=True,
fg="red",
)
_echo_error(
f"Unable to query the device due to an authentication error: {ex}",
)
exit(1)
except Exception as ex:
Expand Down