Skip to content

Commit

Permalink
Merge pull request #79 from gjohansson-ST/migration_error
Browse files Browse the repository at this point in the history
Address migrations errors and entry data errors
  • Loading branch information
gjohansson-ST committed Jun 6, 2022
2 parents 2d734f0 + 0d5fae0 commit 6f589e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions custom_components/sector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .coordinator import SectorAlarmHub


async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Migrate old entry."""
LOGGER.debug("Migrating from version %s", entry.version)

Expand Down Expand Up @@ -56,17 +56,17 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
}
if new_options[CONF_CODE] == "":
new_options[CONF_CODE] = None
if hass.config_entries.async_update_entry(
if success := hass.config_entries.async_update_entry(
entry,
data=new_data,
options=new_options,
title=username,
unique_id=username,
):
entry.version = 3

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

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

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Sector Alarm as config entry."""
Expand Down
4 changes: 2 additions & 2 deletions custom_components/sector/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def async_setup_entry(
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
"coordinator"
]
code: str = entry.data[CONF_CODE]
code: str = entry.options.get(CONF_CODE)

async_add_entities([SectorAlarmPanel(sector_hub, coordinator, code)])

Expand All @@ -58,7 +58,7 @@ def __init__(
"""Initialize the Alarm panel."""
self._hub = hub
super().__init__(coordinator)
self._code: str = code if code != "" else None
self._code: str | None = code
self._displayname: str = self._hub.alarm_displayname
self._isonline: str = self._hub.alarm_isonline
self._attr_name = f"Sector Alarmpanel {self._hub.alarm_id}"
Expand Down
10 changes: 5 additions & 5 deletions custom_components/sector/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ async def async_setup_entry(
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
"coordinator"
]
code: str = entry.data[CONF_CODE]
code_format: int = entry.data[CONF_CODE_FORMAT]
code: str = entry.options.get(CONF_CODE)
code_format: int = entry.options.get(CONF_CODE_FORMAT)

locks = await sector_hub.get_locks()
if not locks:
Expand Down Expand Up @@ -60,8 +60,8 @@ def __init__(
self,
hub: SectorAlarmHub,
coordinator: DataUpdateCoordinator,
code: str,
code_format: int,
code: str | None,
code_format: int | None,
serial: str,
autolock: str,
description: LockEntityDescription,
Expand All @@ -71,7 +71,7 @@ def __init__(
super().__init__(coordinator)
self._attr_name = description.name
self._attr_unique_id: str = "sa_lock_" + str(description.key)
self._attr_code_format: str = f"^\\d{code_format}$"
self._attr_code_format: str = f"^\\d{code_format}$" if code_format else None
self._attr_is_locked = bool(
self._hub.lock_state[description.key] == STATE_LOCKED
)
Expand Down

0 comments on commit 6f589e4

Please sign in to comment.