Repository navigation
Add exception for unsupported provisioning methods #1586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2474886
db3feb8
f21fb36
9d4be81
4e71ac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| from kasa.protocols.iotprotocol import REDACTORS as IOT_REDACTORS | ||
| from kasa.protocols.protocol import redact_data | ||
|
|
||
| from ..exceptions import UnsupportedAuthenticationError | ||
| from ..json import dumps as json_dumps | ||
| from .common import echo, error | ||
|
|
||
|
|
@@ -70,14 +71,20 @@ async def detail(ctx: click.Context) -> DeviceDict: | |
| async def print_unsupported(unsupported_exception: UnsupportedDeviceError) -> None: | ||
| unsupported.append(unsupported_exception) | ||
| async with sem: | ||
| echo("== Unsupported device ==") | ||
| echo(f"\t{unsupported_exception}") | ||
| echo() | ||
|
|
||
| if unsupported_exception.discovery_result: | ||
| echo("== Unsupported device ==") | ||
| _echo_discovery_info(unsupported_exception.discovery_result) | ||
| echo() | ||
| else: | ||
| echo("== Unsupported device ==") | ||
| echo(f"\t{unsupported_exception}") | ||
| echo() | ||
| if isinstance(unsupported_exception, UnsupportedAuthenticationError): | ||
| obd_src = unsupported_exception.discovery_result.get("obd_src") | ||
| echo( | ||
| f"\t[red bold]Provisioned using unsupported" | ||
| f" '{obd_src}'.[/red bold]" | ||
| ) | ||
| echo("\tTo fix, reset and provision manually.") | ||
|
|
||
| from .device import state | ||
|
|
||
|
|
@@ -87,6 +94,8 @@ async def print_discovered(dev: Device) -> None: | |
| async with sem: | ||
| try: | ||
| await dev.update() | ||
| except UnsupportedAuthenticationError as ex: | ||
| await print_unsupported(ex) | ||
| except AuthenticationError: | ||
| if TYPE_CHECKING: | ||
| assert dev._discovery_info | ||
|
|
@@ -159,6 +168,8 @@ async def print_discovered(dev: Device): | |
| async with sem: | ||
| try: | ||
| await dev.update() | ||
| except UnsupportedAuthenticationError as ex: | ||
| await print_unsupported(ex) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, right? |
||
| except AuthenticationError: | ||
| echo(f"{infostr} - Authentication failed") | ||
| except TimeoutError: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,14 @@ | |
| from ..device import Device, DeviceInfo, WifiNetwork | ||
| from ..device_type import DeviceType | ||
| from ..deviceconfig import DeviceConfig | ||
| from ..exceptions import AuthenticationError, DeviceError, KasaException, SmartErrorCode | ||
| from ..exceptions import ( | ||
| SUPPORTED_OBD_SRCS, | ||
| AuthenticationError, | ||
| DeviceError, | ||
| KasaException, | ||
| SmartErrorCode, | ||
| UnsupportedAuthenticationError, | ||
| ) | ||
| from ..feature import Feature | ||
| from ..module import Module | ||
| from ..modulemapping import ModuleMapping, ModuleName | ||
|
|
@@ -263,6 +270,20 @@ async def update(self, update_children: bool = True) -> None: | |
| if self.credentials is None and self.credentials_hash is None: | ||
| raise AuthenticationError("Tapo plug requires authentication.") | ||
|
|
||
| try: | ||
| await self._update(update_children) | ||
| except AuthenticationError as ex: | ||
| obd_src = self._discovery_info and self._discovery_info.get("obd_src") | ||
|
Comment on lines
+273
to
+276
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done here as we do not know during the discovery time, pre-update, if the credentials are wrong or if we do not just support the authentication. The known good sources are based on our fixtures, tss and amazon's obd are not supported, but maybe there exists also others, so we do not want to raise during the discovery to avoid raising unnecessarily.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be fine for now and when we go through the discovery process completely, we can handle authentication and unsupported errors separately. |
||
| if obd_src and obd_src not in SUPPORTED_OBD_SRCS: | ||
| raise UnsupportedAuthenticationError( | ||
| f"Device at {self.host} uses unsupported onboarding '{obd_src}'.", | ||
| discovery_result=self._discovery_info, | ||
| host=self.host, | ||
| ) from ex | ||
| raise | ||
|
|
||
| async def _update(self, update_children: bool = True) -> None: | ||
| """Update implementation.""" | ||
| first_update = self._last_update_time is None | ||
| now = time.monotonic() | ||
| self._last_update_time = now | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If print_discovered already holds the sem, calling print_unsupported will try to grab the same sem and cause a deadlock.