Skip to content

Commit 7af2eca

Browse files
authored
Add function to backup/restore NVM in base64 format (#1182)
1 parent d960c5b commit 7af2eca

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

test/model/test_controller.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,37 @@ async def test_restore_nvm(controller, uuid4, mock_command):
17801780
}
17811781

17821782

1783+
async def test_backup_nvm_raw_base64(controller, uuid4, mock_command):
1784+
"""Test backup NVM raw with base64 return."""
1785+
ack_commands = mock_command(
1786+
{"command": "controller.backup_nvm_raw"},
1787+
{"nvmData": "AAAAAAAAAAAAAA=="},
1788+
)
1789+
assert await controller.async_backup_nvm_raw_base64() == "AAAAAAAAAAAAAA=="
1790+
1791+
assert len(ack_commands) == 1
1792+
assert ack_commands[0] == {
1793+
"command": "controller.backup_nvm_raw",
1794+
"messageId": uuid4,
1795+
}
1796+
1797+
1798+
async def test_restore_nvm_base64(controller, uuid4, mock_command):
1799+
"""Test restore NVM with base64 input."""
1800+
ack_commands = mock_command(
1801+
{"command": "controller.restore_nvm"},
1802+
{},
1803+
)
1804+
await controller.async_restore_nvm_base64("AAAAAAAAAAAAAA==")
1805+
1806+
assert len(ack_commands) == 1
1807+
assert ack_commands[0] == {
1808+
"command": "controller.restore_nvm",
1809+
"nvmData": "AAAAAAAAAAAAAA==",
1810+
"messageId": uuid4,
1811+
}
1812+
1813+
17831814
async def test_set_power_level(controller, uuid4, mock_command):
17841815
"""Test set powerlevel."""
17851816
ack_commands = mock_command(

zwave_js_server/model/controller/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,23 @@ async def async_restore_nvm(self, file: bytes) -> None:
753753
require_schema=14,
754754
)
755755

756+
async def async_backup_nvm_raw_base64(self) -> str:
757+
"""Send backupNVMRaw command to Controller and return base64 string directly."""
758+
data = await self.client.async_send_command(
759+
{"command": "controller.backup_nvm_raw"}, require_schema=14
760+
)
761+
return data["nvmData"]
762+
763+
async def async_restore_nvm_base64(self, base64_data: str) -> None:
764+
"""Send restoreNVM command to Controller with base64 data directly."""
765+
await self.client.async_send_command(
766+
{
767+
"command": "controller.restore_nvm",
768+
"nvmData": base64_data,
769+
},
770+
require_schema=14,
771+
)
772+
756773
async def async_get_power_level(self) -> dict[str, int]:
757774
"""Send getPowerlevel command to Controller."""
758775
data = await self.client.async_send_command(

0 commit comments

Comments
 (0)