Skip to content

Commit

Permalink
Use runtime_data for apsystems_local
Browse files Browse the repository at this point in the history
  • Loading branch information
mawoka-myblock committed May 13, 2024
1 parent 13c637d commit 1972fe5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
12 changes: 3 additions & 9 deletions homeassistant/components/apsystems_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from homeassistant.const import CONF_IP_ADDRESS, Platform
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .coordinator import ApSystemsDataCoordinator

_LOGGER = logging.getLogger(__name__)
Expand All @@ -20,21 +19,16 @@

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up this integration using UI."""
hass.data.setdefault(DOMAIN, {})
entry.runtime_data = {}
api = APsystemsEZ1M(ip_address=entry.data[CONF_IP_ADDRESS], timeout=8)
coordinator = ApSystemsDataCoordinator(hass, api)
await coordinator.async_config_entry_first_refresh()
hass.data[DOMAIN][entry.entry_id] = {**entry.data, "COORDINATOR": coordinator}
entry.runtime_data = {**entry.data, "COORDINATOR": coordinator}
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
3 changes: 1 addition & 2 deletions homeassistant/components/apsystems_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from homeassistant.helpers.typing import DiscoveryInfoType
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DOMAIN
from .coordinator import ApSystemsDataCoordinator


Expand Down Expand Up @@ -115,7 +114,7 @@ async def async_setup_entry(
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the sensor platform."""
config = hass.data[DOMAIN][config_entry.entry_id]
config = config_entry.runtime_data
coordinator = config["COORDINATOR"]
device_name = config_entry.title
device_id: str = config_entry.unique_id # type: ignore[assignment]
Expand Down

0 comments on commit 1972fe5

Please sign in to comment.