|
| 1 | +from dataclasses import dataclass |
| 2 | +from types import SimpleNamespace |
| 3 | +from typing import Any |
| 4 | + |
| 5 | +from custom_components.solax_modbus.plugin_sofar import plugin_instance |
| 6 | + |
| 7 | + |
| 8 | +@dataclass |
| 9 | +class MockEntityDescription: |
| 10 | + native_min_value: int |
| 11 | + native_max_value: int |
| 12 | + |
| 13 | + |
| 14 | +class MockNumberEntity: |
| 15 | + def __init__(self) -> None: |
| 16 | + self._attr_native_min_value = 0 |
| 17 | + self._attr_native_max_value = 20000 |
| 18 | + self.entity_description = MockEntityDescription( |
| 19 | + native_min_value=0, |
| 20 | + native_max_value=20000, |
| 21 | + ) |
| 22 | + |
| 23 | + |
| 24 | +def make_hub(parallel_setting: str, inverter_power_kw: int) -> Any: |
| 25 | + return SimpleNamespace( |
| 26 | + data={"parallel_masterslave": parallel_setting}, |
| 27 | + inverterPowerKw=inverter_power_kw, |
| 28 | + numberEntities={"feedin_max_power": MockNumberEntity()}, |
| 29 | + ) |
| 30 | + |
| 31 | + |
| 32 | +def test_parallel_master_uses_total_system_power_for_feedin_limit() -> None: |
| 33 | + hub = make_hub("Master", 40) |
| 34 | + |
| 35 | + assert plugin_instance.localDataCallback(hub) is True |
| 36 | + |
| 37 | + entity = hub.numberEntities["feedin_max_power"] |
| 38 | + assert entity._attr_native_min_value == 0 |
| 39 | + assert entity._attr_native_max_value == 40000 |
| 40 | + assert entity.entity_description.native_min_value == 0 |
| 41 | + assert entity.entity_description.native_max_value == 40000 |
| 42 | + |
| 43 | + |
| 44 | +def test_single_or_slave_inverter_keeps_existing_feedin_limit() -> None: |
| 45 | + hub = make_hub("Slave", 100) |
| 46 | + |
| 47 | + assert plugin_instance.localDataCallback(hub) is True |
| 48 | + |
| 49 | + entity = hub.numberEntities["feedin_max_power"] |
| 50 | + assert entity._attr_native_max_value == 20000 |
| 51 | + assert entity.entity_description.native_max_value == 20000 |
0 commit comments