mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-22 12:05:12 +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:
|
||||
"""Handle an incorrect preamble."""
|
||||
explanation = msg[1:].decode()
|
||||
if explanation == "Handshake MAC failure":
|
||||
self._handle_error_and_close(
|
||||
InvalidEncryptionKeyAPIError(
|
||||
f"{self._log_name}: Invalid encryption key", self._server_name
|
||||
)
|
||||
if explanation != "Handshake MAC failure":
|
||||
exc = HandshakeAPIError(
|
||||
f"{self._log_name}: Handshake failure: {explanation}"
|
||||
)
|
||||
return
|
||||
self._handle_error_and_close(
|
||||
HandshakeAPIError(f"{self._log_name}: Handshake failure: {explanation}")
|
||||
)
|
||||
else:
|
||||
exc = InvalidEncryptionKeyAPIError(
|
||||
f"{self._log_name}: Invalid encryption key", self._server_name
|
||||
)
|
||||
self._handle_error_and_close(exc)
|
||||
|
||||
def _handle_handshake(self, msg: bytes) -> None:
|
||||
if msg[0] != 0:
|
||||
|
Loading…
Reference in New Issue
Block a user