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
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ omit =
homeassistant/components/onewire/sensor.py
homeassistant/components/onkyo/media_player.py
homeassistant/components/onvif/__init__.py
homeassistant/components/onvif/base.py
homeassistant/components/onvif/camera.py
homeassistant/components/onvif/device.py
homeassistant/components/opencv/*
homeassistant/components/openevse/sensor.py
homeassistant/components/openexchangerates/sensor.py
Expand Down
15 changes: 15 additions & 0 deletions homeassistant/components/onvif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CONF_USERNAME,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_per_platform

from .const import (
Expand All @@ -25,6 +26,7 @@
DOMAIN,
RTSP_TRANS_PROTOCOLS,
)
from .device import ONVIFDevice

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

Expand Down Expand Up @@ -61,9 +63,22 @@ async def async_setup(hass: HomeAssistant, config: dict):

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up ONVIF from a config entry."""
if DOMAIN not in hass.data:
hass.data[DOMAIN] = {}

if not entry.options:
await async_populate_options(hass, entry)

device = ONVIFDevice(hass, entry)

if not await device.async_setup():
return False
Comment thread
hunterjm marked this conversation as resolved.

if not device.available:
raise ConfigEntryNotReady()

hass.data[DOMAIN][entry.unique_id] = device

for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
Expand Down
31 changes: 31 additions & 0 deletions homeassistant/components/onvif/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Base classes for ONVIF entities."""
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.entity import Entity

from .device import ONVIFDevice
from .models import Profile


class ONVIFBaseEntity(Entity):
"""Base class common to all ONVIF entities."""

def __init__(self, device: ONVIFDevice, profile: Profile) -> None:
"""Initialize the ONVIF entity."""
self.device = device
self.profile = profile

@property
def available(self):
"""Return True if device is available."""
return self.device.available

@property
def device_info(self):
"""Return a device description for device registry."""
return {
"connections": {(CONNECTION_NETWORK_MAC, self.device.info.mac)},
"manufacturer": self.device.info.manufacturer,
"model": self.device.info.model,
"name": self.device.name,
"sw_version": self.device.info.fw_version,
}
Loading