Skip to content

Commit

Permalink
Merge pull request #74 from gjohansson-ST/fix_migration
Browse files Browse the repository at this point in the history
Fix migration issue CONF_USERNAME
  • Loading branch information
gjohansson-ST authored Jun 5, 2022
2 parents 9fe2d82 + f4388f0 commit a5f8d22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
26 changes: 15 additions & 11 deletions custom_components/sector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CONF_CODE_FORMAT,
CONF_LOG_NAME,
CONF_TEMP,
CONF_USERID,
DOMAIN,
LOGGER,
PLATFORMS,
Expand All @@ -31,15 +32,19 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
new_data = {**entry.data, CONF_CODE_FORMAT: 6}
new_options = {**entry.options, UPDATE_INTERVAL: 60}

hass.config_entries.async_update_entry(
if hass.config_entries.async_update_entry(
entry, data=new_data, options=new_options
)

entry.version = 2
):
entry.version = 2

if entry.version == 2:
username = (
entry.data[CONF_USERNAME]
if entry.data.get(CONF_USERNAME)
else entry.data[CONF_USERID]
)
new_data = {
CONF_USERNAME: entry.data[CONF_USERNAME],
CONF_USERNAME: username,
CONF_PASSWORD: entry.data[CONF_PASSWORD],
CONF_TEMP: entry.data[CONF_TEMP],
}
Expand All @@ -51,15 +56,14 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
}
if new_options[CONF_CODE] == "":
new_options[CONF_CODE] = None
hass.config_entries.async_update_entry(
if hass.config_entries.async_update_entry(
entry,
data=new_data,
options=new_options,
title=entry.data[CONF_USERNAME],
unique_id=entry.data[CONF_USERNAME],
)

entry.version = 3
title=username,
unique_id=username,
):
entry.version = 3

LOGGER.info("Migration to version %s successful", entry.version)

Expand Down
1 change: 1 addition & 0 deletions custom_components/sector/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

API_URL = "https://mypagesapi.sectoralarm.net/api"

CONF_USERID = "userid"
CONF_CODE_FORMAT = "code_format"
CONF_CODE = "code"
CONF_TEMP = "temp"
Expand Down

0 comments on commit a5f8d22

Please sign in to comment.