Skip to content

Commit 2b31070

Browse files
authored
Merge pull request #903 from canton7/bugfix/h3-pro-invalid-range
Fix invalid register ranges for H3-PRO
2 parents 1b62156 + 9ce4d4b commit 2b31070

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

custom_components/foxess_modbus/inverter_profiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(
8585
)
8686
# H3_REGISTERS with an extra range, see https://github.com/nathanmarlor/foxess_modbus/issues/692
8787
H3_PRO_REGISTERS = SpecialRegisterConfig(
88-
invalid_register_ranges=[(37633, 37700), (41001, 41006), (41012, 41013), (41015, 41015)],
88+
invalid_register_ranges=[(37633, 37699), (41001, 41006), (41012, 41013), (41015, 41015)],
8989
individual_read_register_ranges=[(41000, 41999)],
9090
)
9191
# See https://github.com/nathanmarlor/foxess_modbus/discussions/792

tests/test_entity_descriptions.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any
22
from typing import Iterable
3+
from typing import cast
34
from unittest.mock import MagicMock
45

56
import pytest
@@ -11,6 +12,7 @@
1112
from syrupy.assertion import SnapshotAssertion
1213
from syrupy.extensions.json import JSONSnapshotExtension
1314

15+
from custom_components.foxess_modbus.common.entity_controller import ModbusControllerEntity
1416
from custom_components.foxess_modbus.common.types import ConnectionType
1517
from custom_components.foxess_modbus.common.types import InverterModel
1618
from 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

5162
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:

0 commit comments

Comments
 (0)