1 """The foscam component."""
3 from libpyfoscam
import FoscamCamera
16 from .config_flow
import DEFAULT_RTSP_PORT
17 from .const
import CONF_RTSP_PORT, DOMAIN, LOGGER, SERVICE_PTZ, SERVICE_PTZ_PRESET
18 from .coordinator
import FoscamCoordinator
20 PLATFORMS = [Platform.CAMERA, Platform.SWITCH]
24 """Set up foscam from a config entry."""
26 session = FoscamCamera(
27 entry.data[CONF_HOST],
28 entry.data[CONF_PORT],
29 entry.data[CONF_USERNAME],
30 entry.data[CONF_PASSWORD],
35 await coordinator.async_config_entry_first_refresh()
37 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
39 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
45 """Unload a config entry."""
46 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
48 hass.data[DOMAIN].pop(entry.entry_id)
50 if not hass.data[DOMAIN]:
51 hass.services.async_remove(domain=DOMAIN, service=SERVICE_PTZ)
52 hass.services.async_remove(domain=DOMAIN, service=SERVICE_PTZ_PRESET)
58 """Migrate old entry."""
59 LOGGER.debug(
"Migrating from version %s", entry.version)
61 if entry.version == 1:
65 return {
"new_unique_id": entry.entry_id}
70 camera = FoscamCamera(
71 entry.data[CONF_HOST],
72 entry.data[CONF_PORT],
73 entry.data[CONF_USERNAME],
74 entry.data[CONF_PASSWORD],
78 ret, response = await hass.async_add_executor_job(camera.get_port_info)
80 rtsp_port = DEFAULT_RTSP_PORT
83 rtsp_port = response.get(
"rtspPort")
or response.get(
"mediaPort")
85 hass.config_entries.async_update_entry(
87 data={**entry.data, CONF_RTSP_PORT: rtsp_port},
92 LOGGER.debug(
"Migration to version %s successful", entry.version)
None async_migrate_entries(HomeAssistant hass, dict[str, AdapterDetails] adapters, str default_adapter)
dict[str, str]|None update_unique_id(er.RegistryEntry entity_entry, str unique_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_migrate_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)