2020-05-12 18:26:44 -04:00
|
|
|
"""Zerproc lights integration."""
|
|
|
|
|
|
|
|
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2021-03-22 00:08:09 -05:00
|
|
|
from .const import DATA_ADDRESSES, DATA_DISCOVERY_SUBSCRIPTION, DOMAIN
|
2020-05-12 18:26:44 -04:00
|
|
|
|
|
|
|
PLATFORMS = ["light"]
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup(hass, config):
|
|
|
|
"""Set up the Zerproc platform."""
|
|
|
|
hass.async_create_task(
|
|
|
|
hass.config_entries.flow.async_init(DOMAIN, context={"source": SOURCE_IMPORT})
|
|
|
|
)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-05-27 11:39:06 -04:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-05-12 18:26:44 -04:00
|
|
|
"""Set up Zerproc from a config entry."""
|
2021-03-05 13:14:03 -06:00
|
|
|
if DOMAIN not in hass.data:
|
|
|
|
hass.data[DOMAIN] = {}
|
2021-03-22 00:08:09 -05:00
|
|
|
if DATA_ADDRESSES not in hass.data[DOMAIN]:
|
|
|
|
hass.data[DOMAIN][DATA_ADDRESSES] = set()
|
2021-03-05 13:14:03 -06:00
|
|
|
|
2021-04-27 10:51:11 -10:00
|
|
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
2020-05-12 18:26:44 -04:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-10-06 10:48:11 +02:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-05-12 18:26:44 -04:00
|
|
|
"""Unload a config entry."""
|
2021-03-22 00:08:09 -05:00
|
|
|
# Stop discovery
|
|
|
|
unregister_discovery = hass.data[DOMAIN].pop(DATA_DISCOVERY_SUBSCRIPTION, None)
|
|
|
|
if unregister_discovery:
|
|
|
|
unregister_discovery()
|
|
|
|
|
2021-03-05 13:14:03 -06:00
|
|
|
hass.data.pop(DOMAIN, None)
|
2021-03-22 00:08:09 -05:00
|
|
|
|
2021-04-27 10:51:11 -10:00
|
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|