2020-05-17 10:15:06 +00:00
|
|
|
"""The Rollease Acmeda Automate integration."""
|
2022-01-19 17:00:34 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-03 16:51:30 +00:00
|
|
|
from homeassistant.const import Platform
|
2022-01-19 17:00:34 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-05-17 10:15:06 +00:00
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
from .hub import PulseHub
|
|
|
|
|
|
|
|
CONF_HUBS = "hubs"
|
|
|
|
|
2021-12-03 16:51:30 +00:00
|
|
|
PLATFORMS = [Platform.COVER, Platform.SENSOR]
|
2020-05-17 10:15:06 +00:00
|
|
|
|
|
|
|
|
2022-01-19 17:00:34 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
2020-05-17 10:15:06 +00:00
|
|
|
"""Set up Rollease Acmeda Automate hub from a config entry."""
|
|
|
|
hub = PulseHub(hass, config_entry)
|
|
|
|
|
|
|
|
if not await hub.async_setup():
|
|
|
|
return False
|
|
|
|
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
hass.data[DOMAIN][config_entry.entry_id] = hub
|
|
|
|
|
2021-04-26 17:46:55 +00:00
|
|
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
2020-05-17 10:15:06 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-01-19 17:00:34 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
2020-05-17 10:15:06 +00:00
|
|
|
"""Unload a config entry."""
|
|
|
|
hub = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
|
2021-04-26 17:46:55 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
|
|
|
config_entry, PLATFORMS
|
2020-05-17 10:15:06 +00:00
|
|
|
)
|
2021-04-26 17:46:55 +00:00
|
|
|
|
2020-05-17 10:15:06 +00:00
|
|
|
if not await hub.async_reset():
|
|
|
|
return False
|
|
|
|
|
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
|
|
|
|
|
|
|
return unload_ok
|