Skip to content

Commit

Permalink
Merge pull request #84 from WillCodeForCats/83-detected-blocking-call…
Browse files Browse the repository at this point in the history
…-to-open-inside-the-event-loop

Use HA storage helper for stored settings
  • Loading branch information
WillCodeForCats authored Jun 15, 2024
2 parents 0ef6599 + 4562e84 commit 1a38193
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 85 deletions.
18 changes: 17 additions & 1 deletion custom_components/tekmar_482/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""The Tekmar 482 Gateway Integration."""

import asyncio
from typing import Any

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.storage import Store

from . import hub
from .const import CONF_SETBACK_ENABLE, DOMAIN
from .const import CONF_SETBACK_ENABLE, DOMAIN, STORAGE_KEY, STORAGE_VERSION_MAJOR

PLATFORMS: list[str] = [
Platform.SENSOR,
Expand Down Expand Up @@ -68,3 +70,17 @@ async def async_remove_config_entry_device(
"""Allow the user to delete a device from the UI."""

return True


async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle removal of an entry."""

store: Store[dict[str, Any]] = Store(
hass,
STORAGE_VERSION_MAJOR,
STORAGE_KEY,
)

data = await store.async_load()
del data[entry.entry_id]
await store.async_save(data)
3 changes: 3 additions & 0 deletions custom_components/tekmar_482/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class StrEnum(str, Enum):
DEFAULT_SETBACK_ENABLE = False
CONF_SETBACK_ENABLE = "setback_enable"

STORAGE_VERSION_MAJOR = 1
STORAGE_KEY = DOMAIN

# from voluptuous/validators.py
DOMAIN_REGEX = re.compile(
# start anchor, because fullmatch is not available in python 2.7
Expand Down
Loading

0 comments on commit 1a38193

Please sign in to comment.