diff --git a/homeassistant/components/onvif/__init__.py b/homeassistant/components/onvif/__init__.py index 6d90c5828f9..bb8008e1fef 100644 --- a/homeassistant/components/onvif/__init__.py +++ b/homeassistant/components/onvif/__init__.py @@ -82,13 +82,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): if device.capabilities.events and await device.events.async_start(): platforms += ["binary_sensor", "sensor"] - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.events.async_stop) for component in platforms: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, component) ) + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.async_stop) + return True diff --git a/homeassistant/components/onvif/device.py b/homeassistant/components/onvif/device.py index 0a35dadec26..d6f407f016d 100644 --- a/homeassistant/components/onvif/device.py +++ b/homeassistant/components/onvif/device.py @@ -8,7 +8,6 @@ from aiohttp.client_exceptions import ClientConnectionError, ServerDisconnectedE import onvif from onvif import ONVIFCamera from onvif.exceptions import ONVIFError -from zeep.asyncio import AsyncTransport from zeep.exceptions import Fault from homeassistant.config_entries import ConfigEntry @@ -20,7 +19,6 @@ from homeassistant.const import ( CONF_USERNAME, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.util.dt as dt_util from .const import ( @@ -141,6 +139,12 @@ class ONVIFDevice: return True + async def async_stop(self, event=None): + """Shut it all down.""" + if self.events: + await self.events.async_stop() + await self.device.close() + async def async_check_date_and_time(self) -> None: """Warns if device and system date not synced.""" LOGGER.debug("Setting up the ONVIF device management service") @@ -278,7 +282,7 @@ class ONVIFDevice: is not None, ) - ptz_service = self.device.get_service("ptz") + ptz_service = self.device.create_ptz_service() presets = await ptz_service.GetPresets(profile.token) profile.ptz.presets = [preset.token for preset in presets] @@ -326,7 +330,7 @@ class ONVIFDevice: LOGGER.warning("PTZ actions are not supported on device '%s'", self.name) return - ptz_service = self.device.get_service("ptz") + ptz_service = self.device.create_ptz_service() pan_val = distance * PAN_FACTOR.get(pan, 0) tilt_val = distance * TILT_FACTOR.get(tilt, 0) @@ -423,13 +427,11 @@ class ONVIFDevice: def get_device(hass, host, port, username, password) -> ONVIFCamera: """Get ONVIFCamera instance.""" - session = async_get_clientsession(hass) - transport = AsyncTransport(None, session=session) return ONVIFCamera( host, port, username, password, f"{os.path.dirname(onvif.__file__)}/wsdl/", - transport=transport, + no_cache=True, ) diff --git a/homeassistant/components/onvif/event.py b/homeassistant/components/onvif/event.py index 888fe5bd92b..183ad0ab532 100644 --- a/homeassistant/components/onvif/event.py +++ b/homeassistant/components/onvif/event.py @@ -91,7 +91,7 @@ class EventManager: return self.started - async def async_stop(self, event=None) -> None: + async def async_stop(self) -> None: """Unsubscribe from events.""" if not self._subscription: return @@ -110,7 +110,7 @@ class EventManager: async def async_pull_messages(self, _now: dt = None) -> None: """Pull messages from device.""" try: - pullpoint = self.device.get_service("pullpoint") + pullpoint = self.device.create_pullpoint_service() req = pullpoint.create_type("PullMessages") req.MessageLimit = 100 req.Timeout = dt.timedelta(seconds=60) diff --git a/homeassistant/components/onvif/manifest.json b/homeassistant/components/onvif/manifest.json index f291f9c6613..4214cf3ab5c 100644 --- a/homeassistant/components/onvif/manifest.json +++ b/homeassistant/components/onvif/manifest.json @@ -2,7 +2,7 @@ "domain": "onvif", "name": "ONVIF", "documentation": "https://www.home-assistant.io/integrations/onvif", - "requirements": ["onvif-zeep-async==0.3.0", "WSDiscovery==2.0.0"], + "requirements": ["onvif-zeep-async==0.4.0", "WSDiscovery==2.0.0"], "dependencies": ["ffmpeg"], "codeowners": ["@hunterjm"], "config_flow": true diff --git a/requirements_all.txt b/requirements_all.txt index 2754a985f36..04e3c9eb497 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -994,7 +994,7 @@ oemthermostat==1.1 onkyo-eiscp==1.2.7 # homeassistant.components.onvif -onvif-zeep-async==0.3.0 +onvif-zeep-async==0.4.0 # homeassistant.components.opengarage open-garage==0.1.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 95aceb77f8a..8e143ff875c 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -414,7 +414,7 @@ numpy==1.18.4 oauth2client==4.0.0 # homeassistant.components.onvif -onvif-zeep-async==0.3.0 +onvif-zeep-async==0.4.0 # homeassistant.components.openerz openerz-api==0.1.0