38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""The MB-Secure integration."""
|
|
|
|
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 .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: MBSecureConfigEntry) -> bool:
|
|
"""Set up MB-Secure from a config entry."""
|
|
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: MBSecureConfigEntry) -> bool:
|
|
"""Unload an MB-Secure config entry."""
|
|
await entry.runtime_data.async_shutdown()
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|