2019-03-17 03:44:05 +00:00
|
|
|
"""The foscam component."""
|
2021-01-13 15:09:05 +00:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2021-01-27 14:43:36 +00:00
|
|
|
from .const import DOMAIN, SERVICE_PTZ, SERVICE_PTZ_PRESET
|
2021-01-13 15:09:05 +00:00
|
|
|
|
|
|
|
PLATFORMS = ["camera"]
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, config: dict):
|
|
|
|
"""Set up the foscam component."""
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
|
|
"""Set up foscam from a config entry."""
|
|
|
|
for component in PLATFORMS:
|
|
|
|
hass.async_create_task(
|
|
|
|
hass.config_entries.async_forward_entry_setup(entry, component)
|
|
|
|
)
|
|
|
|
|
|
|
|
hass.data[DOMAIN][entry.unique_id] = entry.data
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
|
|
"""Unload a config entry."""
|
|
|
|
unload_ok = all(
|
|
|
|
await asyncio.gather(
|
|
|
|
*[
|
|
|
|
hass.config_entries.async_forward_entry_unload(entry, component)
|
|
|
|
for component in PLATFORMS
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN].pop(entry.unique_id)
|
|
|
|
|
|
|
|
if not hass.data[DOMAIN]:
|
|
|
|
hass.services.async_remove(domain=DOMAIN, service=SERVICE_PTZ)
|
2021-01-27 14:43:36 +00:00
|
|
|
hass.services.async_remove(domain=DOMAIN, service=SERVICE_PTZ_PRESET)
|
2021-01-13 15:09:05 +00:00
|
|
|
|
|
|
|
return unload_ok
|