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
30 changes: 19 additions & 11 deletions homeassistant/components/onvif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@

from homeassistant.components.ffmpeg import CONF_EXTRA_ARGUMENTS
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
CONF_PASSWORD,
CONF_PORT,
CONF_USERNAME,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_per_platform

from .const import (
CONF_PROFILE,
CONF_RTSP_TRANSPORT,
DEFAULT_ARGUMENTS,
DEFAULT_PROFILE,
DEFAULT_NAME,
DEFAULT_PASSWORD,
DEFAULT_PORT,
DEFAULT_USERNAME,
DOMAIN,
RTSP_TRANS_PROTOCOLS,
)
Expand All @@ -32,12 +40,14 @@ async def async_setup(hass: HomeAssistant, config: dict):
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)
configs[config[CONF_HOST]] = {
CONF_HOST: config[CONF_HOST],
CONF_NAME: config.get(CONF_NAME, DEFAULT_NAME),
CONF_PASSWORD: config.get(CONF_PASSWORD, DEFAULT_PASSWORD),
CONF_PORT: config.get(CONF_PORT, DEFAULT_PORT),
CONF_USERNAME: config.get(CONF_USERNAME, DEFAULT_USERNAME),
}

for conf in configs.values():
hass.async_create_task(
Expand All @@ -64,7 +74,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
return all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
Expand All @@ -73,8 +83,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
)
)

return unload_ok


async def async_populate_options(hass, entry):
"""Populate default options for device."""
Expand Down
21 changes: 9 additions & 12 deletions homeassistant/components/onvif/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,20 @@ async def async_step_device(self, user_input=None):

discovery = await async_discovery(self.hass)
for device in discovery:
configured = False
for entry in self._async_current_entries():
if entry.unique_id == device[CONF_DEVICE_ID]:
configured = True
break
configured = any(
entry.unique_id == device[CONF_DEVICE_ID]
for entry in self._async_current_entries()
)

if not configured:
self.devices.append(device)

LOGGER.debug("Discovered ONVIF devices %s", pformat(self.devices))

if self.devices:
names = []

for device in self.devices:
names.append(f"{device[CONF_NAME]} ({device[CONF_HOST]})")
names = [
f"{device[CONF_NAME]} ({device[CONF_HOST]})" for device in self.devices
]

names.append(CONF_MANUAL_INPUT)

Expand Down Expand Up @@ -299,13 +298,11 @@ def get_device(hass, host, port, username, password) -> ONVIFCamera:
"""Get ONVIFCamera instance."""
session = async_get_clientsession(hass)
transport = AsyncTransport(None, session=session)
device = ONVIFCamera(
return ONVIFCamera(
host,
port,
username,
password,
f"{os.path.dirname(onvif.__file__)}/wsdl/",
transport=transport,
)

return device