Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ omit =
homeassistant/components/ombi/*
homeassistant/components/onewire/sensor.py
homeassistant/components/onkyo/media_player.py
homeassistant/components/onvif/__init__.py
homeassistant/components/onvif/camera.py
homeassistant/components/opencv/*
homeassistant/components/openevse/sensor.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ homeassistant/components/ohmconnect/* @robbiet480
homeassistant/components/ombi/* @larssont
homeassistant/components/onboarding/* @home-assistant/core
homeassistant/components/onewire/* @garbled1
homeassistant/components/onvif/* @hunterjm
homeassistant/components/openerz/* @misialq
homeassistant/components/opentherm_gw/* @mvn23
homeassistant/components/openuv/* @bachya
Expand Down
87 changes: 86 additions & 1 deletion homeassistant/components/onvif/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,86 @@
"""The onvif component."""
"""The ONVIF integration."""
import asyncio

import voluptuous as vol

from homeassistant.components.ffmpeg import CONF_EXTRA_ARGUMENTS
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_per_platform

from .const import (
CONF_PROFILE,
CONF_RTSP_TRANSPORT,
DEFAULT_ARGUMENTS,
DEFAULT_PROFILE,
DOMAIN,
RTSP_TRANS_PROTOCOLS,
)

CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)

PLATFORMS = ["camera"]


async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the ONVIF component."""
# Import from yaml
configs = {}
for p_type, p_config in config_per_platform(config, "camera"):
if p_type != DOMAIN:
continue

config = p_config.copy()
profile = config.get(CONF_PROFILE, DEFAULT_PROFILE)
if config[CONF_HOST] not in configs.keys():
configs[config[CONF_HOST]] = config
configs[config[CONF_HOST]][CONF_PROFILE] = [profile]
else:
configs[config[CONF_HOST]][CONF_PROFILE].append(profile)

for conf in configs.values():
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf
)
)

return True


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up ONVIF from a config entry."""
if not entry.options:
await async_populate_options(hass, entry)

for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)

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
]
)
)

return unload_ok


async def async_populate_options(hass, entry):
"""Populate default options for device."""
options = {
CONF_EXTRA_ARGUMENTS: DEFAULT_ARGUMENTS,
CONF_RTSP_TRANSPORT: RTSP_TRANS_PROTOCOLS[0],
}

hass.config_entries.async_update_entry(entry, options=options)
Loading