Skip to content

Commit 0f6ad34

Browse files
committed
Fix unit tests
1 parent bcf2774 commit 0f6ad34

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

bellows/ezsp/__init__.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ async def startup_reset(self) -> None:
128128
await self.reset()
129129

130130
await self.version()
131+
await self.get_xncp_features()
131132

132133
@classmethod
133134
async def initialize(cls, zigpy_config: dict) -> EZSP:
@@ -180,24 +181,21 @@ async def version(self):
180181
self._switch_protocol_version(ver)
181182
await self._command("version", ver)
182183

183-
try:
184-
self._xncp_features = await self.xncp_get_supported_firmware_features()
185-
except InvalidCommandError:
186-
self._xncp_features = xncp.FirmwareFeatures.NONE
187-
188184
LOGGER.debug(
189-
(
190-
"EZSP Stack Type: %s"
191-
", Stack Version: %04x"
192-
", Protocol version: %s"
193-
", XNCP features: %s"
194-
),
185+
("EZSP Stack Type: %s" ", Stack Version: %04x" ", Protocol version: %s"),
195186
stack_type,
196187
stack_version,
197188
ver,
198-
self._xncp_features,
199189
)
200190

191+
async def get_xncp_features(self) -> None:
192+
try:
193+
self._xncp_features = await self.xncp_get_supported_firmware_features()
194+
except InvalidCommandError:
195+
self._xncp_features = xncp.FirmwareFeatures.NONE
196+
197+
LOGGER.debug("XNCP features: %s", self._xncp_features)
198+
201199
def close(self):
202200
self.stop_ezsp()
203201
if self._gw:
@@ -426,7 +424,7 @@ async def get_mfg_token(self, token: t.EzspMfgTokenId) -> bytes:
426424

427425
async def _get_mfg_custom_eui_64(self) -> t.EUI64 | None:
428426
"""Get the custom EUI 64 manufacturing token, if it has a valid value."""
429-
(data,) = await self.get_mfg_token(t.EzspMfgTokenId.MFG_CUSTOM_EUI_64)
427+
data = await self.get_mfg_token(t.EzspMfgTokenId.MFG_CUSTOM_EUI_64)
430428

431429
# Manufacturing tokens do not exist in RCP firmware: all reads are empty
432430
if not data:

tests/test_application.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def ezsp_mock(ieee):
7676
)
7777
mock_ezsp.add_transient_link_key = AsyncMock(return_value=t.EmberStatus.SUCCESS)
7878
mock_ezsp._protocol = AsyncMock()
79-
mock_ezsp.get_supported_firmware_features = AsyncMock(
79+
mock_ezsp.xncp_get_supported_firmware_features = AsyncMock(
8080
return_value=FirmwareFeatures.NONE
8181
)
82+
mock_ezsp._xncp_features = FirmwareFeatures.NONE
8283

8384
type(mock_ezsp).types = ezsp_t7
8485
type(mock_ezsp).is_ezsp_running = PropertyMock(return_value=True)
@@ -226,9 +227,10 @@ async def nop_mock():
226227
]
227228
)
228229
ezsp_mock.setMulticastTableEntry = AsyncMock(return_value=[t.EmberStatus.SUCCESS])
229-
ezsp_mock.get_supported_firmware_features = AsyncMock(
230+
ezsp_mock.xncp_get_supported_firmware_features = AsyncMock(
230231
return_value=FirmwareFeatures.NONE
231232
)
233+
ezsp_mock._xncp_features = FirmwareFeatures.NONE
232234

233235
app.permit = AsyncMock()
234236

tests/test_ezsp.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ async def test_no_close_without_callback(ezsp_f):
282282

283283
@patch.object(ezsp.EZSP, "version", new_callable=AsyncMock)
284284
@patch.object(ezsp.EZSP, "reset", new_callable=AsyncMock)
285+
@patch.object(ezsp.EZSP, "get_xncp_features", new_callable=AsyncMock)
285286
@patch("bellows.uart.connect", return_value=MagicMock(spec_set=uart.Gateway))
286-
async def test_ezsp_init(conn_mock, reset_mock, version_mock):
287+
async def test_ezsp_init(conn_mock, xncp_mock, reset_mock, version_mock):
287288
"""Test initialize method."""
288289
zigpy_config = config.CONFIG_SCHEMA({"device": DEVICE_CONFIG})
289290
await ezsp.EZSP.initialize(zigpy_config)
@@ -643,8 +644,9 @@ async def test_write_custom_eui64_rcp(ezsp_f):
643644

644645
@patch.object(ezsp.EZSP, "version", new_callable=AsyncMock)
645646
@patch.object(ezsp.EZSP, "reset", new_callable=AsyncMock)
647+
@patch.object(ezsp.EZSP, "get_xncp_features", new_callable=AsyncMock)
646648
@patch("bellows.uart.connect", return_value=MagicMock(spec_set=uart.Gateway))
647-
async def test_ezsp_init_zigbeed(conn_mock, reset_mock, version_mock):
649+
async def test_ezsp_init_zigbeed(conn_mock, xncp_mock, reset_mock, version_mock):
648650
"""Test initialize method with a received startup reset frame."""
649651
zigpy_config = config.CONFIG_SCHEMA(
650652
{
@@ -667,9 +669,12 @@ async def test_ezsp_init_zigbeed(conn_mock, reset_mock, version_mock):
667669

668670
@patch.object(ezsp.EZSP, "version", new_callable=AsyncMock)
669671
@patch.object(ezsp.EZSP, "reset", new_callable=AsyncMock)
672+
@patch.object(ezsp.EZSP, "get_xncp_features", new_callable=AsyncMock)
670673
@patch("bellows.uart.connect", return_value=MagicMock(spec_set=uart.Gateway))
671674
@patch("bellows.ezsp.NETWORK_COORDINATOR_STARTUP_RESET_WAIT", 0.01)
672-
async def test_ezsp_init_zigbeed_timeout(conn_mock, reset_mock, version_mock):
675+
async def test_ezsp_init_zigbeed_timeout(
676+
conn_mock, xncp_mock, reset_mock, version_mock
677+
):
673678
"""Test initialize method with a received startup reset frame."""
674679
zigpy_config = config.CONFIG_SCHEMA(
675680
{

0 commit comments

Comments
 (0)