mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-08 22:07:06 +00:00
Add --batch-size hint to timeout errors in dump_devinfo (#696)
* Add --batch-size hint to timeout errors in dump_devinfo * Add _echo_error function for displaying critical errors
This commit is contained in:
parent
bab40d43e6
commit
f7c04bcef8
@ -20,7 +20,14 @@ from typing import Dict, List, Union
|
|||||||
import asyncclick as click
|
import asyncclick as click
|
||||||
|
|
||||||
from devtools.helpers.smartrequests import COMPONENT_REQUESTS, SmartRequest
|
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.discover import DiscoveryResult
|
||||||
from kasa.exceptions import SmartErrorCode
|
from kasa.exceptions import SmartErrorCode
|
||||||
from kasa.tapo.tapodevice import TapoDevice
|
from kasa.tapo.tapodevice import TapoDevice
|
||||||
@ -227,11 +234,7 @@ async def get_legacy_fixture(device):
|
|||||||
try:
|
try:
|
||||||
final = await device.protocol.query(final_query)
|
final = await device.protocol.query(final_query)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
click.echo(
|
_echo_error(f"Unable to query all successes at once: {ex}", bold=True, fg="red")
|
||||||
click.style(
|
|
||||||
f"Unable to query all successes at once: {ex}", bold=True, fg="red"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if device._discovery_info and not device._discovery_info.get("system"):
|
if device._discovery_info and not device._discovery_info.get("system"):
|
||||||
# Need to recreate a DiscoverResult here because we don't want the aliases
|
# Need to recreate a DiscoverResult here because we don't want the aliases
|
||||||
@ -254,6 +257,16 @@ async def get_legacy_fixture(device):
|
|||||||
return save_filename, copy_folder, final
|
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(
|
async def _make_requests_or_exit(
|
||||||
device: SmartDevice,
|
device: SmartDevice,
|
||||||
requests: List[SmartRequest],
|
requests: List[SmartRequest],
|
||||||
@ -277,17 +290,25 @@ async def _make_requests_or_exit(
|
|||||||
final[method] = result
|
final[method] = result
|
||||||
return final
|
return final
|
||||||
except AuthenticationException as ex:
|
except AuthenticationException as ex:
|
||||||
click.echo(
|
_echo_error(
|
||||||
click.style(
|
|
||||||
f"Unable to query the device due to an authentication error: {ex}",
|
f"Unable to query the device due to an authentication error: {ex}",
|
||||||
bold=True,
|
|
||||||
fg="red",
|
|
||||||
)
|
)
|
||||||
|
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)
|
exit(1)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
click.echo(
|
_echo_error(
|
||||||
click.style(f"Unable to query {name} at once: {ex}", bold=True, fg="red")
|
f"Unexpected exception querying {name} at once: {ex}",
|
||||||
)
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
@ -361,12 +382,8 @@ async def get_smart_fixture(device: TapoDevice, batch_size: int):
|
|||||||
SmartRequest._create_request_dict(test_call.request)
|
SmartRequest._create_request_dict(test_call.request)
|
||||||
)
|
)
|
||||||
except AuthenticationException as ex:
|
except AuthenticationException as ex:
|
||||||
click.echo(
|
_echo_error(
|
||||||
click.style(
|
|
||||||
f"Unable to query the device due to an authentication error: {ex}",
|
f"Unable to query the device due to an authentication error: {ex}",
|
||||||
bold=True,
|
|
||||||
fg="red",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
Loading…
Reference in New Issue
Block a user