Files
core/homeassistant/components/foscam/__init__.py
Sergio Conde Gómez 83b210061d Add config_flow and stream selection to foscam (#41429)
* Add config_flow and stream selection to foscam

* Simplify config_flow steps

* Make debug log entry more useful

* Deprecate config and platform schemas

* Simplify config loading

* Add config flow testing

* Remove unneeded CONFIG_SCHEMA deprecation

* Improve test coverage

* Unload service by tracking loaded entries

* Address comment

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-01-13 16:09:05 +01:00

52 lines
1.3 KiB
Python

"""The foscam component."""
import asyncio
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .const import DOMAIN, SERVICE_PTZ
PLATFORMS = ["camera"]
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
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)
return unload_ok