Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Android IP Webcam integration."""
2 
3 from __future__ import annotations
4 
5 from pydroid_ipcam import PyDroidIPCam
6 
7 from homeassistant.const import (
8  CONF_HOST,
9  CONF_PASSWORD,
10  CONF_PORT,
11  CONF_USERNAME,
12  Platform,
13 )
14 from homeassistant.core import HomeAssistant
15 from homeassistant.helpers.aiohttp_client import async_get_clientsession
16 
17 from .coordinator import AndroidIPCamConfigEntry, AndroidIPCamDataUpdateCoordinator
18 
19 PLATFORMS: list[Platform] = [
20  Platform.BINARY_SENSOR,
21  Platform.CAMERA,
22  Platform.SENSOR,
23  Platform.SWITCH,
24 ]
25 
26 
28  hass: HomeAssistant, entry: AndroidIPCamConfigEntry
29 ) -> bool:
30  """Set up Android IP Webcam from a config entry."""
31  websession = async_get_clientsession(hass)
32  cam = PyDroidIPCam(
33  websession,
34  entry.data[CONF_HOST],
35  entry.data[CONF_PORT],
36  username=entry.data.get(CONF_USERNAME),
37  password=entry.data.get(CONF_PASSWORD),
38  ssl=False,
39  )
40  coordinator = AndroidIPCamDataUpdateCoordinator(hass, entry, cam)
41  await coordinator.async_config_entry_first_refresh()
42 
43  entry.runtime_data = coordinator
44 
45  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
46 
47  return True
48 
49 
51  hass: HomeAssistant, entry: AndroidIPCamConfigEntry
52 ) -> bool:
53  """Unload a config entry."""
54  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, AndroidIPCamConfigEntry entry)
Definition: __init__.py:52
bool async_setup_entry(HomeAssistant hass, AndroidIPCamConfigEntry entry)
Definition: __init__.py:29
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)