mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-26 12:45:26 +01:00
Refactor noise _error_on_incorrect_preamble to improve coverage (#683)
This commit is contained in:
parent
39aba56958
commit
b31472c569
@ -253,16 +253,15 @@ class APINoiseFrameHelper(APIFrameHelper):
|
|||||||
def _error_on_incorrect_preamble(self, msg: bytes) -> None:
|
def _error_on_incorrect_preamble(self, msg: bytes) -> None:
|
||||||
"""Handle an incorrect preamble."""
|
"""Handle an incorrect preamble."""
|
||||||
explanation = msg[1:].decode()
|
explanation = msg[1:].decode()
|
||||||
if explanation == "Handshake MAC failure":
|
if explanation != "Handshake MAC failure":
|
||||||
self._handle_error_and_close(
|
exc = HandshakeAPIError(
|
||||||
InvalidEncryptionKeyAPIError(
|
f"{self._log_name}: Handshake failure: {explanation}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
exc = InvalidEncryptionKeyAPIError(
|
||||||
f"{self._log_name}: Invalid encryption key", self._server_name
|
f"{self._log_name}: Invalid encryption key", self._server_name
|
||||||
)
|
)
|
||||||
)
|
self._handle_error_and_close(exc)
|
||||||
return
|
|
||||||
self._handle_error_and_close(
|
|
||||||
HandshakeAPIError(f"{self._log_name}: Handshake failure: {explanation}")
|
|
||||||
)
|
|
||||||
|
|
||||||
def _handle_handshake(self, msg: bytes) -> None:
|
def _handle_handshake(self, msg: bytes) -> None:
|
||||||
if msg[0] != 0:
|
if msg[0] != 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user