Skip to content

Commit f5390ed

Browse files
authored
Make resilient inverter wrapper default: True (#399)
* Initial plan * Make resilient_wrapper default True for release 0.7.0 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent b662776 commit f5390ed

6 files changed

Lines changed: 27 additions & 4 deletions

File tree

config/batcontrol_config_dummy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ inverter:
105105
# Only affects mode 8; ignored in other modes.
106106
# fronius_inverter_id: '1' # Optional: ID of the inverter in Fronius API (default: '1')
107107
# fronius_controller_id: '0' # Optional: ID of the controller in Fronius API (default: '0')
108-
enable_resilient_wrapper: false # Skip a control cycle on transient inverter outages instead of terminating (default: false)
108+
enable_resilient_wrapper: true # Skip a control cycle on transient inverter outages instead of terminating (default: true)
109109
outage_tolerance_minutes: 24 # Minutes to tolerate inverter outages before terminating (default: 24)
110110

111111
#--------------------------

docs/configuration/inverter-configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Why not just let batcontrol crash and rely on the container restart policy? With
3030

3131
Default:
3232
```
33-
enable_resilient_wrapper: false
33+
enable_resilient_wrapper: true
3434
```
3535

3636
### outage_tolerance_minutes

src/batcontrol/inverter/inverter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ def create_inverter(config: dict) -> InverterInterface:
106106
inverter.inverter_num = Inverter.num_inverters
107107
Inverter.num_inverters += 1
108108

109-
# Check if resilient wrapper is enabled (default: False)
110-
enable_resilient_wrapper = config.get('enable_resilient_wrapper', False)
109+
# Check if resilient wrapper is enabled (default: True)
110+
enable_resilient_wrapper = config.get('enable_resilient_wrapper', True)
111111

112112
if not enable_resilient_wrapper:
113113
logger.info('Resilient wrapper disabled by configuration')

tests/batcontrol/inverter/test_dummy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ def test_dummy_energy_calculations(self):
110110
free_capacity = dummy.get_free_capacity()
111111
assert free_capacity == 3000 # (95% - 65%) of 10000 Wh
112112

113+
def test_dummy_factory_with_resilient_wrapper_default(self):
114+
"""Test that factory returns wrapped inverter by default (enable_resilient_wrapper not set)"""
115+
config = {
116+
'type': 'dummy',
117+
'max_grid_charge_rate': 3000,
118+
}
119+
120+
inverter = Inverter.create_inverter(config)
121+
# Default is now True, so factory returns ResilientInverterWrapper
122+
assert isinstance(inverter, ResilientInverterWrapper)
123+
assert isinstance(inverter.wrapped_inverter, Dummy)
124+
assert inverter.max_grid_charge_rate == 3000
125+
113126
def test_dummy_factory_with_resilient_wrapper_disabled(self):
114127
"""Test that factory returns unwrapped inverter when resilient wrapper is disabled"""
115128
config = {

tests/batcontrol/inverter/test_fronius_modbus_factory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_factory_creates_fronius_modbus_inverter_with_expected_defaults(mocker):
2727
"address": "192.168.1.100",
2828
"capacity": 10000,
2929
"max_grid_charge_rate": 5000,
30+
"enable_resilient_wrapper": False,
3031
}
3132

3233
inverter = Inverter.create_inverter(config)
@@ -57,6 +58,7 @@ def test_factory_passes_explicit_fronius_modbus_config_values(mocker):
5758
"max_soc": 95,
5859
"max_grid_charge_rate": 6000,
5960
"revert_seconds": 900,
61+
"enable_resilient_wrapper": False,
6062
}
6163

6264
inverter = Inverter.create_inverter(config)
@@ -82,6 +84,7 @@ def test_factory_accepts_fronius_modbus_type_case_insensitively(mocker):
8284
"address": "192.168.1.100",
8385
"capacity": 10000,
8486
"max_grid_charge_rate": 5000,
87+
"enable_resilient_wrapper": False,
8588
}
8689

8790
inverter = Inverter.create_inverter(config)
@@ -126,6 +129,7 @@ def test_factory_accepts_legacy_max_charge_rate_alias_for_fronius_modbus(mocker)
126129
"address": "192.168.1.100",
127130
"capacity": 10000,
128131
"max_charge_rate": 4200,
132+
"enable_resilient_wrapper": False,
129133
}
130134

131135
inverter = Inverter.create_inverter(config)

tests/batcontrol/inverter/test_inverter_factory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_factory_creates_mqtt_inverter():
2020
"type": "mqtt",
2121
"capacity": 10000,
2222
"max_grid_charge_rate": 5000,
23+
"enable_resilient_wrapper": False,
2324
}
2425

2526
inverter = Inverter.create_inverter(config)
@@ -35,6 +36,7 @@ def test_factory_uses_max_charge_rate_alias_for_mqtt():
3536
"type": "mqtt",
3637
"capacity": 10000,
3738
"max_charge_rate": 4200,
39+
"enable_resilient_wrapper": False,
3840
}
3941

4042
inverter = Inverter.create_inverter(config)
@@ -50,6 +52,7 @@ def test_factory_prefers_max_grid_charge_rate_over_alias():
5052
"capacity": 10000,
5153
"max_grid_charge_rate": 5000,
5254
"max_charge_rate": 4200,
55+
"enable_resilient_wrapper": False,
5356
}
5457

5558
inverter = Inverter.create_inverter(config)
@@ -64,6 +67,7 @@ def test_factory_accepts_mqtt_type_case_insensitively():
6467
"type": "MQTT",
6568
"capacity": 10000,
6669
"max_grid_charge_rate": 5000,
70+
"enable_resilient_wrapper": False,
6771
}
6872

6973
inverter = Inverter.create_inverter(config)
@@ -77,6 +81,7 @@ def test_factory_applies_mqtt_defaults():
7781
"type": "mqtt",
7882
"capacity": 10000,
7983
"max_grid_charge_rate": 5000,
84+
"enable_resilient_wrapper": False,
8085
}
8186

8287
inverter = Inverter.create_inverter(config)
@@ -115,6 +120,7 @@ def test_factory_builds_fronius_with_expected_config(mocker):
115120
"max_pv_charge_rate": 1700,
116121
"fronius_inverter_id": 3,
117122
"fronius_controller_id": 4,
123+
"enable_resilient_wrapper": False,
118124
}
119125

120126
inverter = Inverter.create_inverter(config)

0 commit comments

Comments
 (0)