mirror of
https://github.com/esphome/esphome.git
synced 2026-05-30 07:16:11 +08:00
[ota] Improve error message when device closes connection without responding (#13562)
This commit is contained in:
@@ -154,6 +154,12 @@ def check_error(data: list[int] | bytes, expect: int | list[int] | None) -> None
|
|||||||
"""
|
"""
|
||||||
if not expect:
|
if not expect:
|
||||||
return
|
return
|
||||||
|
if not data:
|
||||||
|
raise OTAError(
|
||||||
|
"Error: Device closed connection without responding. "
|
||||||
|
"This may indicate the device ran out of memory, "
|
||||||
|
"a network issue, or the connection was interrupted."
|
||||||
|
)
|
||||||
dat = data[0]
|
dat = data[0]
|
||||||
if dat == RESPONSE_ERROR_MAGIC:
|
if dat == RESPONSE_ERROR_MAGIC:
|
||||||
raise OTAError("Error: Invalid magic byte")
|
raise OTAError("Error: Invalid magic byte")
|
||||||
|
|||||||
@@ -192,6 +192,20 @@ def test_check_error_unexpected_response() -> None:
|
|||||||
espota2.check_error([0x7F], [espota2.RESPONSE_OK, espota2.RESPONSE_AUTH_OK])
|
espota2.check_error([0x7F], [espota2.RESPONSE_OK, espota2.RESPONSE_AUTH_OK])
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_error_empty_data() -> None:
|
||||||
|
"""Test check_error raises error when device closes connection without responding."""
|
||||||
|
with pytest.raises(
|
||||||
|
espota2.OTAError, match="Device closed connection without responding"
|
||||||
|
):
|
||||||
|
espota2.check_error([], [espota2.RESPONSE_OK])
|
||||||
|
|
||||||
|
# Also test with empty bytes
|
||||||
|
with pytest.raises(
|
||||||
|
espota2.OTAError, match="Device closed connection without responding"
|
||||||
|
):
|
||||||
|
espota2.check_error(b"", [espota2.RESPONSE_OK])
|
||||||
|
|
||||||
|
|
||||||
def test_send_check_with_various_data_types(mock_socket: Mock) -> None:
|
def test_send_check_with_various_data_types(mock_socket: Mock) -> None:
|
||||||
"""Test send_check handles different data types."""
|
"""Test send_check handles different data types."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user