Skip to content

Commit 6e459f1

Browse files
jthunJan Thunqvistlbbrhzndrc38
authored
Support for multiple connectors per charger (#1689)
* Update .gitignore for HA dev. Use symlinks for integration. * Handle multiple connectors, initial framework. * Fix sensor updates and placement on proper devices. * Add test for v2x multi connector. Handle meter values properly. max_current working per connector. * Fix per connector set charge rate. Clean up swenglish comments. * Remove separate connector device breaking change. Fix test race condition. CodeRabbit fixes. * Fix max_current per connector bug. Remove ChargerSession sensors (used for debugging). Fix Charge Control naming when only one connector. More CodeRabbit suggestions. * Fix Connector naming. More CodeRabbit suggestions. * Add more tests. More CodeRabbit suggestions. * Test fixes. CodeRabbit suggestions. * Fix tests. * Split stop transaction test in separate tests. * Change entity id to include charger. Add session sensors to connectors. Clear charger-level entities after connector creation. Add num_connector changes to reload logic. Remove not used functions from chargepoint.py. Revert to original config flow due to automatic discovery of number of connectors. Add more tests. * Change port on test to fix crash. * Add missing sensors. Convert features value in sensor. Add num_connectors to config entry. Migration to config 2.1. --------- Co-authored-by: Jan Thunqvist <[email protected]> Co-authored-by: lbbrhzn <[email protected]> Co-authored-by: drc38 <[email protected]>
1 parent d3ef669 commit 6e459f1

25 files changed

+5762
-948
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,7 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# HA Development
132+
/config/
133+
.DS_Store

custom_components/ocpp/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
CONF_METER_INTERVAL,
2626
CONF_MONITORED_VARIABLES,
2727
CONF_MONITORED_VARIABLES_AUTOCONFIG,
28+
CONF_NUM_CONNECTORS,
2829
CONF_SKIP_SCHEMA_VALIDATION,
2930
CONF_FORCE_SMART_CHARGING,
3031
CONF_HOST,
@@ -44,6 +45,7 @@
4445
DEFAULT_METER_INTERVAL,
4546
DEFAULT_MONITORED_VARIABLES,
4647
DEFAULT_MONITORED_VARIABLES_AUTOCONFIG,
48+
DEFAULT_NUM_CONNECTORS,
4749
DEFAULT_SKIP_SCHEMA_VALIDATION,
4850
DEFAULT_FORCE_SMART_CHARGING,
4951
DEFAULT_HOST,
@@ -192,6 +194,36 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
192194
config_entry, data=new_data, minor_version=0, version=2
193195
)
194196

197+
if config_entry.version == 2 and config_entry.minor_version == 0:
198+
data = {**config_entry.data}
199+
cpids = data.get(CONF_CPIDS, [])
200+
201+
changed = False
202+
for idx, cp_map in enumerate(cpids):
203+
if not isinstance(cp_map, dict) or not cp_map:
204+
continue
205+
cp_id, cp_data = next(iter(cp_map.items()))
206+
if CONF_NUM_CONNECTORS not in cp_data:
207+
cp_data = {**cp_data, CONF_NUM_CONNECTORS: DEFAULT_NUM_CONNECTORS}
208+
cpids[idx] = {cp_id: cp_data}
209+
changed = True
210+
211+
if changed:
212+
data[CONF_CPIDS] = cpids
213+
hass.config_entries.async_update_entry(
214+
config_entry,
215+
data=data,
216+
version=2,
217+
minor_version=1,
218+
)
219+
else:
220+
hass.config_entries.async_update_entry(
221+
config_entry,
222+
data=data,
223+
version=2,
224+
minor_version=1,
225+
)
226+
195227
_LOGGER.info(
196228
"Migration to configuration version %s.%s successful",
197229
config_entry.version,

0 commit comments

Comments
 (0)