Skip to content

Commit ecb23be

Browse files
committed
include new feature in testing
1 parent 1f7fbff commit ecb23be

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_usb.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
24452445
assert test_sense.temperature_upper_bound == 25
24462446
assert test_sense.temperature_lower_bound == 25
24472447
assert test_sense.temperature_direction
2448+
assert test_sense.report_interval == 15
24482449

24492450
# test humidity upper bound
24502451
with pytest.raises(ValueError):
@@ -2585,6 +2586,43 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
25852586
assert not test_sense.hysteresis_config_dirty
25862587
assert test_sense.temperature_lower_bound == 24
25872588

2589+
# test report interval
2590+
with pytest.raises(ValueError):
2591+
await test_sense.set_report_interval(0)
2592+
with pytest.raises(ValueError):
2593+
await test_sense.set_report_interval(61)
2594+
assert not await test_sense.set_report_interval(15)
2595+
assert not test_sense.hysteresis_config_dirty
2596+
assert await test_sense.set_report_interval(5)
2597+
assert test_sense.hysteresis_config_dirty
2598+
assert test_sense.hysteresis_config_dirty
2599+
assert test_sense.report_interval == 5
2600+
2601+
# Failed config
2602+
mock_stick_controller.append_response(sense_config_accepted)
2603+
mock_stick_controller.append_response(sense_config_accepted)
2604+
mock_stick_controller.append_response(sense_config_report_interval_failed)
2605+
awake_response1.timestamp = awake_response1.timestamp + td(
2606+
seconds=pw_sed.AWAKE_RETRY
2607+
)
2608+
await test_sense._awake_response(awake_response1) # pylint: disable=protected-access
2609+
assert test_sense._delayed_task is not None # pylint: disable=protected-access
2610+
await asyncio.wait_for(asyncio.shield(test_sense._delayed_task), timeout=2)
2611+
assert test_sense.hysteresis_config_dirty
2612+
2613+
# Successful config
2614+
mock_stick_controller.append_response(sense_config_accepted)
2615+
mock_stick_controller.append_response(sense_config_accepted)
2616+
mock_stick_controller.append_response(sense_config_report_interval_accepted)
2617+
awake_response1.timestamp = awake_response1.timestamp + td(
2618+
seconds=pw_sed.AWAKE_RETRY
2619+
)
2620+
await test_sense._awake_response(awake_response1) # pylint: disable=protected-access
2621+
assert test_sense._delayed_task is not None # pylint: disable=protected-access
2622+
await asyncio.wait_for(asyncio.shield(test_sense._delayed_task), timeout=2)
2623+
assert not test_sense.hysteresis_config_dirty
2624+
assert test_sense.report_interval == 5
2625+
25882626
@pytest.mark.asyncio
25892627
async def test_switch_node(self, monkeypatch: pytest.MonkeyPatch) -> None:
25902628
"""Testing properties of switch."""

0 commit comments

Comments
 (0)