Skip to content

Commit 0adeb9b

Browse files
committed
Make NVRAM reads and writes produce consistent logging output
1 parent e2d08e8 commit 0adeb9b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

zigpy_znp/tools/nvram_read.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def nvram_read(znp: ZNP):
4040
except KeyError:
4141
break
4242

43-
LOGGER.info("%s = %s", key, value)
43+
LOGGER.info("%s = %r", key, value.hex())
4444
data["LEGACY"][key] = value.hex()
4545
else:
4646
try:
@@ -51,7 +51,7 @@ async def nvram_read(znp: ZNP):
5151
LOGGER.warning("Read disallowed for %s", nwk_nvid)
5252
continue
5353

54-
LOGGER.info("%s = %s", nwk_nvid, value)
54+
LOGGER.info("%s = %r", nwk_nvid, value.hex())
5555
data["LEGACY"][nwk_nvid.name] = value.hex()
5656

5757
for nvid in ExNvIds:
@@ -71,7 +71,7 @@ async def nvram_read(znp: ZNP):
7171
# Once a read fails, no later reads will succeed
7272
break
7373

74-
LOGGER.info("%s[0x%04X] = %s", nvid.name, sub_id, value)
74+
LOGGER.info("%s[0x%04X] = %r", nvid.name, sub_id, value.hex())
7575
data.setdefault(nvid.name, {})[f"0x{sub_id:04X}"] = value.hex()
7676

7777
return data

zigpy_znp/tools/nvram_write.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ async def nvram_write(znp: ZNP, backup):
2020
nvid = OsalNvIds[nwk_nvid] + offset
2121
else:
2222
nvid = OsalNvIds[nwk_nvid]
23+
offset = None
2324

24-
value = bytes.fromhex(value)
25-
await znp.nvram.osal_write(nvid, value, create=True)
25+
if offset is not None:
26+
LOGGER.info("%s+%s = %r", OsalNvIds[nwk_nvid].name, offset, value)
27+
else:
28+
LOGGER.info("%s = %r", OsalNvIds[nwk_nvid].name, value)
29+
30+
await znp.nvram.osal_write(nvid, bytes.fromhex(value), create=True)
2631

2732
for item_name, sub_ids in backup.items():
2833
item_id = ExNvIds[item_name]
@@ -32,12 +37,12 @@ async def nvram_write(znp: ZNP, backup):
3237

3338
for sub_id, value in sub_ids.items():
3439
sub_id = int(sub_id, 16)
35-
value = bytes.fromhex(value)
40+
LOGGER.info("%s[0x%04X] = %r", item_id.name, sub_id, value)
3641

3742
await znp.nvram.write(
3843
item_id=item_id,
3944
sub_id=sub_id,
40-
value=value,
45+
value=bytes.fromhex(value),
4146
create=True,
4247
)
4348

0 commit comments

Comments
 (0)