2020-01-30 18:21:51 +00:00
|
|
|
"""The Mikrotik component."""
|
2022-05-30 13:34:28 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-02 15:28:14 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-05-17 19:22:15 +00:00
|
|
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
2019-12-09 13:20:40 +00:00
|
|
|
|
2022-05-30 13:34:28 +00:00
|
|
|
from .const import ATTR_MANUFACTURER, DOMAIN, PLATFORMS
|
2022-06-29 13:32:29 +00:00
|
|
|
from .hub import MikrotikDataUpdateCoordinator
|
2019-08-08 11:58:13 +00:00
|
|
|
|
2022-05-30 13:34:28 +00:00
|
|
|
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
2020-01-30 18:21:51 +00:00
|
|
|
|
|
|
|
|
2022-01-02 15:28:14 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
2020-01-30 18:21:51 +00:00
|
|
|
"""Set up the Mikrotik component."""
|
2019-08-08 11:58:13 +00:00
|
|
|
|
2022-06-29 13:32:29 +00:00
|
|
|
hub = MikrotikDataUpdateCoordinator(hass, config_entry)
|
2020-01-30 18:21:51 +00:00
|
|
|
if not await hub.async_setup():
|
2019-08-08 11:58:13 +00:00
|
|
|
return False
|
2020-01-30 18:21:51 +00:00
|
|
|
|
2022-06-29 13:32:29 +00:00
|
|
|
await hub.async_config_entry_first_refresh()
|
|
|
|
|
2020-01-30 18:21:51 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = hub
|
2022-06-29 13:32:29 +00:00
|
|
|
|
|
|
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
|
|
|
|
2022-05-17 19:22:15 +00:00
|
|
|
device_registry = dr.async_get(hass)
|
2020-01-30 18:21:51 +00:00
|
|
|
device_registry.async_get_or_create(
|
|
|
|
config_entry_id=config_entry.entry_id,
|
|
|
|
connections={(DOMAIN, hub.serial_num)},
|
|
|
|
manufacturer=ATTR_MANUFACTURER,
|
|
|
|
model=hub.model,
|
|
|
|
name=hub.hostname,
|
|
|
|
sw_version=hub.firmware,
|
|
|
|
)
|
|
|
|
|
2019-08-08 11:58:13 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-01-02 15:28:14 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
2020-01-30 18:21:51 +00:00
|
|
|
"""Unload a config entry."""
|
2021-04-27 16:49:13 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
|
|
|
config_entry, PLATFORMS
|
|
|
|
)
|
2019-08-08 11:58:13 +00:00
|
|
|
|
2020-01-30 18:21:51 +00:00
|
|
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
|
|
|
|
2021-04-27 16:49:13 +00:00
|
|
|
return unload_ok
|