Implement bridge-backed Home Assistant integration
This commit is contained in:
@@ -4,17 +4,34 @@ from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN
|
||||
from .api import BridgeClient
|
||||
from .const import CONF_TOKEN, PLATFORMS
|
||||
from .coordinator import MBSecureCoordinator
|
||||
from .devices import async_setup_devices
|
||||
|
||||
type MBSecureConfigEntry = ConfigEntry[MBSecureCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: MBSecureConfigEntry) -> bool:
|
||||
"""Set up MB-Secure from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = None
|
||||
client = BridgeClient(
|
||||
async_get_clientsession(hass),
|
||||
host=entry.data["host"],
|
||||
port=entry.data["port"],
|
||||
token=entry.data[CONF_TOKEN],
|
||||
)
|
||||
coordinator = MBSecureCoordinator(hass, entry, client)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
entry.runtime_data = coordinator
|
||||
async_setup_devices(hass, entry)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
coordinator.async_start_event_listener()
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: MBSecureConfigEntry) -> bool:
|
||||
"""Unload an MB-Secure config entry."""
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
return True
|
||||
await entry.runtime_data.async_shutdown()
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
Reference in New Issue
Block a user