Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion plugp100/new/device_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,23 @@ async def _guess_protocol(
KlapProtocol(config.credentials, config.url, klap_handshake_v2(), session),
]
device_info_request = TapoRequest.get_device_info()
work_protocol = None
for protocol in protocols:
info = await protocol.send_request(device_info_request)
if info.is_success():
_LOGGER.debug(f"Found working protocol {type(protocol)}")
return protocol
work_protocol = protocol
else:
_LOGGER.debug(f"Protocol {type(protocol)} not working, trying next...")

# close sessions which we don't need
for protocol in protocols:
if protocol != work_protocol:
await protocol.close()

if work_protocol:
return work_protocol

_LOGGER.error("None of available protocol is working, maybe invalid credentials")
raise InvalidAuthentication(config.host, config.device_type)

Expand Down
2 changes: 1 addition & 1 deletion plugp100/new/errors/invalid_authentication.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class InvalidAuthentication(Exception):
def __init__(self, host: str, device_type: str):
super(f"Invalid authentication error for ${host}, ${device_type}")
super().__init__(f"Invalid authentication error for ${host}, ${device_type}")