Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ dmypy.json

# Pyre type checker
.pyre/

# HA Development
/config/
.DS_Store
32 changes: 32 additions & 0 deletions custom_components/ocpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CONF_METER_INTERVAL,
CONF_MONITORED_VARIABLES,
CONF_MONITORED_VARIABLES_AUTOCONFIG,
CONF_NUM_CONNECTORS,
CONF_SKIP_SCHEMA_VALIDATION,
CONF_FORCE_SMART_CHARGING,
CONF_HOST,
Expand All @@ -44,6 +45,7 @@
DEFAULT_METER_INTERVAL,
DEFAULT_MONITORED_VARIABLES,
DEFAULT_MONITORED_VARIABLES_AUTOCONFIG,
DEFAULT_NUM_CONNECTORS,
DEFAULT_SKIP_SCHEMA_VALIDATION,
DEFAULT_FORCE_SMART_CHARGING,
DEFAULT_HOST,
Expand Down Expand Up @@ -192,6 +194,36 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
config_entry, data=new_data, minor_version=0, version=2
)

if config_entry.version == 2 and config_entry.minor_version == 0:
data = {**config_entry.data}
cpids = data.get(CONF_CPIDS, [])

changed = False
for idx, cp_map in enumerate(cpids):
if not isinstance(cp_map, dict) or not cp_map:
continue
cp_id, cp_data = next(iter(cp_map.items()))
if CONF_NUM_CONNECTORS not in cp_data:
cp_data = {**cp_data, CONF_NUM_CONNECTORS: DEFAULT_NUM_CONNECTORS}
cpids[idx] = {cp_id: cp_data}
changed = True

if changed:
data[CONF_CPIDS] = cpids
hass.config_entries.async_update_entry(
config_entry,
data=data,
version=2,
minor_version=1,
)
else:
hass.config_entries.async_update_entry(
config_entry,
data=data,
version=2,
minor_version=1,
)

_LOGGER.info(
"Migration to configuration version %s.%s successful",
config_entry.version,
Expand Down
Loading
Loading