|
2 | 2 | from unittest import mock
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from zigpy.exceptions import FormationFailure |
5 | 6 |
|
6 | 7 | import zigpy_znp.types as t
|
| 8 | +import zigpy_znp.commands as c |
7 | 9 | from zigpy_znp.types.nvids import ExNvIds, OsalNvIds
|
8 | 10 |
|
9 | 11 | from ..conftest import (
|
@@ -114,3 +116,33 @@ async def test_write_settings_fast(device, make_connected_znp):
|
114 | 116 |
|
115 | 117 | # We don't waste time writing device info
|
116 | 118 | assert len(mock_write_devices.mock_awaits) == 0
|
| 119 | + |
| 120 | + |
| 121 | +@pytest.mark.parametrize("device", FORMED_DEVICES) |
| 122 | +async def test_formation_failure_on_corrupted_nvram(device, make_connected_znp): |
| 123 | + formed_znp, _ = await make_connected_znp(server_cls=FormedLaunchpadCC26X2R1) |
| 124 | + await formed_znp.load_network_info() |
| 125 | + formed_znp.close() |
| 126 | + |
| 127 | + znp, znp_server = await make_connected_znp(server_cls=device) |
| 128 | + |
| 129 | + # Instead of accepting the write, fail |
| 130 | + write_reset_rsp = znp_server.reply_once_to( |
| 131 | + request=c.SYS.OSALNVWriteExt.Req( |
| 132 | + Id=OsalNvIds.STARTUP_OPTION, |
| 133 | + Offset=0, |
| 134 | + Value=t.ShortBytes( |
| 135 | + (t.StartupOptions.ClearState | t.StartupOptions.ClearConfig).serialize() |
| 136 | + ), |
| 137 | + ), |
| 138 | + responses=[c.SYS.OSALNVWriteExt.Rsp(Status=t.Status.NV_OPER_FAILED)], |
| 139 | + override=True, |
| 140 | + ) |
| 141 | + |
| 142 | + with pytest.raises(FormationFailure): |
| 143 | + await znp.write_network_info( |
| 144 | + network_info=formed_znp.network_info, |
| 145 | + node_info=formed_znp.node_info, |
| 146 | + ) |
| 147 | + |
| 148 | + await write_reset_rsp |
0 commit comments