11from typing import Any
22from typing import Iterable
3+ from typing import cast
34from unittest .mock import MagicMock
45
56import pytest
1112from syrupy .assertion import SnapshotAssertion
1213from syrupy .extensions .json import JSONSnapshotExtension
1314
15+ from custom_components .foxess_modbus .common .entity_controller import ModbusControllerEntity
1416from custom_components .foxess_modbus .common .types import ConnectionType
1517from custom_components .foxess_modbus .common .types import InverterModel
1618from custom_components .foxess_modbus .const import ENTITY_ID_PREFIX
@@ -33,7 +35,7 @@ async def test_creates_all_entities(hass: HomeAssistant) -> None:
3335 controller .hass = hass
3436
3537 for profile in INVERTER_PROFILES .values ():
36- for connection_type in profile .connection_types :
38+ for connection_type , connection_type_profile in profile .connection_types . items () :
3739 for entity_type in [SensorEntity , BinarySensorEntity , SelectEntity , NumberEntity ]:
3840 controller .inverter_details = {
3941 INVERTER_BASE : profile .model ,
@@ -45,7 +47,16 @@ async def test_creates_all_entities(hass: HomeAssistant) -> None:
4547 # Asserts if e.g. the ModbusAddressSpecs match
4648 # We can't test IntegrationSensors (which have depends_on_other_entities=True), as HA throws up saying
4749 # that the entity it depends on doesn't exist (as we're not actually creating entities).
48- create_entities (entity_type , controller , filter_depends_on_other_entites = False )
50+ entities = create_entities (entity_type , controller , filter_depends_on_other_entites = False )
51+
52+ for entity in entities :
53+ for address in cast (ModbusControllerEntity , entity ).addresses :
54+ for start , end in connection_type_profile .special_registers .invalid_register_ranges :
55+ if start <= address <= end :
56+ raise AssertionError (
57+ f"Profile { profile .model } Entity { entity .unique_id } address { address } lies in "
58+ f"range ({ start } , { end } )"
59+ )
4960
5061
5162def pytest_generate_tests (metafunc : pytest .Metafunc ) -> None :
0 commit comments