Skip to content

Commit

Permalink
Add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Nov 5, 2024
1 parent 02c5feb commit 703315b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_flasher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import asyncio
from unittest.mock import call, patch

import zigpy.types as t

from universal_silabs_flasher.common import Version
from universal_silabs_flasher.flasher import Flasher, ProbeResult


async def test_write_emberznet_eui64():
flasher = Flasher(device="/dev/ttyMOCK")

with patch.object(
flasher, "probe_gecko_bootloader", side_effect=asyncio.TimeoutError
), patch.object(
flasher,
"probe_ezsp",
return_value=ProbeResult(
version=Version("7.4.4.0 build 0"), continue_probing=False, baudrate=115200
),
), patch.object(flasher, "_connect_ezsp") as mock_connect_ezsp:
ezsp = mock_connect_ezsp.return_value.__aenter__.return_value

ezsp.getEui64.return_value = (t.EUI64.convert("00:11:22:33:44:55:66:77"),)
ezsp.write_custom_eui64.return_value = None

await flasher.write_emberznet_eui64(
new_ieee=t.EUI64.convert("11:22:33:44:55:66:77:88"), force=True
)

assert ezsp.write_custom_eui64.mock_calls == [
call(ieee=t.EUI64.convert("11:22:33:44:55:66:77:88"), burn_into_userdata=True)
]
2 changes: 2 additions & 0 deletions universal_silabs_flasher/flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ async def probe_app_type(
except asyncio.TimeoutError:
continue

_LOGGER.debug("Probe result: %s", result)

# Keep track of the bootloader version for later
if probe_method == ApplicationType.GECKO_BOOTLOADER:
_LOGGER.info("Detected bootloader version %s", result.version)
Expand Down

0 comments on commit 703315b

Please sign in to comment.