Skip to content

Commit 5012f9d

Browse files
committed
Address Copilot review feedback
- Raise BSBLANVersionError instead of crashing when firmware strings are not PEP 440 compliant (InvalidVersion); add a regression test - Remove a duplicate _available_circuits assertion in test_pps - Use assert_awaited_once_with for the AsyncMock request in test_state
1 parent 6ea2ed8 commit 5012f9d

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/bsblan/bsblan.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from aiohttp.hdrs import METH_POST
1616
from aiohttp.helpers import BasicAuth
1717
from packaging import version as pkg_version
18+
from packaging.version import InvalidVersion
1819
from yarl import URL
1920

2021
from .constants import (
@@ -581,7 +582,10 @@ def _set_api_version(self) -> None:
581582
if not self._firmware_version:
582583
raise BSBLANError(ErrorMsg.FIRMWARE_VERSION)
583584

584-
firmware_version = pkg_version.parse(self._firmware_version)
585+
try:
586+
firmware_version = pkg_version.parse(self._firmware_version)
587+
except InvalidVersion as exc:
588+
raise BSBLANVersionError(ErrorMsg.VERSION) from exc
585589
if firmware_version < pkg_version.parse("3.0.0"):
586590
raise BSBLANVersionError(ErrorMsg.VERSION)
587591
self._api_version = SUPPORTED_API_VERSION

tests/test_pps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ async def test_pps_circuit_discovery_returns_empty_without_mode(
369369

370370
assert circuits == []
371371
assert pps_bsblan._available_circuits == set()
372-
assert pps_bsblan._available_circuits == set()
373372

374373

375374
@pytest.mark.asyncio

tests/test_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def test_state(monkeypatch: Any) -> None:
8686
assert state.room1_temp_setpoint_boost.unit == "°C"
8787

8888
# Verify API call
89-
request_mock.assert_called_once_with(
89+
request_mock.assert_awaited_once_with(
9090
params={"Parameter": "700,710,900,902,8000,8740,770"}
9191
)
9292

tests/test_version_errors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ async def test_set_api_version_rejects_legacy_firmware() -> None:
4949
bsblan._set_api_version()
5050

5151

52+
@pytest.mark.asyncio
53+
async def test_set_api_version_invalid_firmware_string() -> None:
54+
"""Test non-PEP440 firmware strings raise BSBLANVersionError."""
55+
config = BSBLANConfig(host="example.com")
56+
bsblan = BSBLAN(config)
57+
58+
# Firmware strings with build metadata are not PEP 440 compliant
59+
bsblan._firmware_version = "1.0.38-not-a-version"
60+
61+
with pytest.raises(BSBLANVersionError):
62+
bsblan._set_api_version()
63+
64+
5265
@pytest.mark.asyncio
5366
async def test_set_api_version_v3() -> None:
5467
"""Test setting API version with v3 compatible firmware."""

0 commit comments

Comments
 (0)