Skip to content

Commit a91399d

Browse files
committed
Coverage
1 parent 1dcd392 commit a91399d

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

bellows/ezsp/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,13 @@ async def get_board_info(
351351
special, ver_info_bytes = t.uint8_t.deserialize(ver_info_bytes)
352352
version = f"{major}.{minor}.{patch}.{special} build {build}"
353353

354-
if xncp.FirmwareFeatures.BUILD_STRING in self._xncp_features:
355-
try:
356-
build_string = await self.xncp_get_build_string()
357-
except InvalidCommandError:
358-
build_string = None
354+
try:
355+
build_string = await self.xncp_get_build_string()
356+
except InvalidCommandError:
357+
build_string = None
359358

360-
if build_string:
361-
version = f"{version} ({build_string})"
359+
if build_string:
360+
version = f"{version} ({build_string})"
362361

363362
return (
364363
tokens[t.EzspMfgTokenId.MFG_STRING],
@@ -689,7 +688,7 @@ async def xncp_get_mfg_token_override(self, token: t.EzspMfgTokenId) -> bytes:
689688
rsp = await self.send_xncp_frame(xncp.GetMfgTokenOverrideReq(token=token))
690689
return rsp.value
691690

692-
async def xncp_get_build_string(self) -> bytes:
691+
async def xncp_get_build_string(self) -> str:
693692
"""Get build string."""
694693
rsp = await self.send_xncp_frame(xncp.GetBuildStringReq())
695694
return rsp.build_string.decode("utf-8")

tests/test_ezsp.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from bellows.ash import NcpFailure
1313
from bellows.exception import EzspError, InvalidCommandError
1414
from bellows.ezsp import EZSP, EZSP_LATEST
15+
from bellows.ezsp.xncp import FirmwareFeatures
1516
import bellows.types as t
1617

1718
if sys.version_info[:2] < (3, 11):
@@ -323,46 +324,60 @@ async def test_ezsp_newer_version(ezsp_f):
323324
(
324325
"mfg_board_name",
325326
"mfg_string",
327+
"xncp_build_string",
326328
"value_version_info",
327329
"expected",
328330
),
329331
[
330332
(
331333
(b"\xfe\xff\xff\xff",),
332334
(b"Manufacturer\xff\xff\xff",),
335+
(InvalidCommandError("XNCP is not supported"),),
333336
(t.EmberStatus.SUCCESS, b"\x01\x02\x03\x04\x05\x06"),
334337
("Manufacturer", "0xFE", "3.4.5.6 build 513"),
335338
),
336339
(
337340
(b"\xfe\xff\xff\xff",),
338341
(b"Manufacturer\xff\xff\xff",),
342+
(InvalidCommandError("XNCP is not supported"),),
339343
(t.EmberStatus.ERR_FATAL, b"\x01\x02\x03\x04\x05\x06"),
340344
("Manufacturer", "0xFE", None),
341345
),
342346
(
343347
(b"SkyBlue v0.1\x00\xff\xff\xff",),
344348
(b"Nabu Casa\x00\xff\xff\xff\xff\xff\xff",),
349+
(InvalidCommandError("XNCP is not supported"),),
345350
(t.EmberStatus.SUCCESS, b"\xbf\x00\x07\x01\x00\x00\xaa"),
346351
("Nabu Casa", "SkyBlue v0.1", "7.1.0.0 build 191"),
347352
),
348353
(
349354
(b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",),
350355
(b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",),
356+
(InvalidCommandError("XNCP is not supported"),),
351357
(t.EmberStatus.SUCCESS, b"\xbf\x00\x07\x01\x00\x00\xaa"),
352358
(None, None, "7.1.0.0 build 191"),
353359
),
354360
(
355361
(b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",),
356362
(b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00",),
363+
(InvalidCommandError("XNCP is not supported"),),
357364
(t.EmberStatus.SUCCESS, b")\x01\x06\n\x03\x00\xaa"),
358365
(None, None, "6.10.3.0 build 297"),
359366
),
367+
(
368+
(b"SkyBlue v0.1\x00\xff\xff\xff",),
369+
(b"Nabu Casa\x00\xff\xff\xff\xff\xff\xff",),
370+
("special build",),
371+
(t.EmberStatus.SUCCESS, b"\xbf\x00\x07\x01\x00\x00\xaa"),
372+
("Nabu Casa", "SkyBlue v0.1", "7.1.0.0 build 191 (special build)"),
373+
),
360374
],
361375
)
362376
async def test_board_info(
363377
ezsp_f,
364378
mfg_board_name: bytes,
365379
mfg_string: bytes,
380+
xncp_build_string: str | Exception,
366381
value_version_info: tuple[t.EmberStatus, bytes],
367382
expected: tuple[str | None, str | None, str],
368383
):
@@ -384,7 +399,7 @@ async def replacement(command_name, tokenId=None, valueId=None):
384399
("getValue", t.EzspValueId.VALUE_VERSION_INFO): value_version_info,
385400
}
386401
),
387-
):
402+
), patch.object(ezsp_f, "xncp_get_build_string", side_effect=xncp_build_string):
388403
mfg, brd, ver = await ezsp_f.get_board_info()
389404

390405
assert (mfg, brd, ver) == expected
@@ -432,6 +447,28 @@ async def _mock_cmd(*args, **kwargs):
432447
await ezsp_f.leaveNetwork(timeout=0.01)
433448

434449

450+
async def test_xncp_token_override(ezsp_f):
451+
ezsp_f.getMfgToken = AsyncMock(return_value=[b"firmware value"])
452+
ezsp_f.xncp_get_mfg_token_override = AsyncMock(return_value=b"xncp value")
453+
454+
# Without firmware support, the XNCP command isn't sent
455+
assert (
456+
await ezsp_f.get_mfg_token(t.EzspMfgTokenId.MFG_CUSTOM_EUI_64)
457+
) == b"firmware value"
458+
459+
# With firmware support, it is
460+
ezsp_f._xncp_features |= FirmwareFeatures.MFG_TOKEN_OVERRIDES
461+
assert (
462+
await ezsp_f.get_mfg_token(t.EzspMfgTokenId.MFG_CUSTOM_EUI_64)
463+
) == b"xncp value"
464+
465+
# Tokens without overrides are still read normally
466+
ezsp_f.xncp_get_mfg_token_override.side_effect = InvalidCommandError
467+
assert (
468+
await ezsp_f.get_mfg_token(t.EzspMfgTokenId.MFG_CUSTOM_EUI_64)
469+
) == b"firmware value"
470+
471+
435472
@pytest.mark.parametrize(
436473
"value, expected_result",
437474
[

0 commit comments

Comments
 (0)