Skip to content

Commit

Permalink
refactor to allow adding multiple devices (close #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarv committed Mar 5, 2024
1 parent 90dc0d2 commit c0c1d59
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 61 deletions.
23 changes: 22 additions & 1 deletion custom_components/bwt_perla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.entity_registry import async_migrate_entries

from .const import DOMAIN

Expand Down Expand Up @@ -42,3 +43,23 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await api.close()

return unload_ok


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

# Add entry id to unique id in order to allow multiple devices
if entry.version == 1:

@callback
def update_unique_id(entity_entry):
"""Update unique ID of entity entry."""
return {"new_unique_id": entry.entry_id + "_" + entity_entry.unique_id}

await async_migrate_entries(hass, entry.entry_id, update_unique_id)
entry.version = 2

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

return True
2 changes: 1 addition & 1 deletion custom_components/bwt_perla/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for BWT Perla."""

VERSION = 1
VERSION = 2

async def async_step_user(
self, user_input: dict[str, Any] | None = None
Expand Down
1 change: 1 addition & 0 deletions custom_components/bwt_perla/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"documentation": "https://github.com/dkarv/hacs-bwt-perla/blob/master/README.md",
"version": "0.5.0",
"homekit": {},
"integration_type": "device",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/dkarv/hacs-bwt-perla/issues",
"requirements": ["bwt_api==0.4.2"],
Expand Down
Loading

0 comments on commit c0c1d59

Please sign in to comment.