diff --git a/homeassistant/components/onvif/device.py b/homeassistant/components/onvif/device.py index 1717b8cccb5..8ede2ab24cd 100644 --- a/homeassistant/components/onvif/device.py +++ b/homeassistant/components/onvif/device.py @@ -379,7 +379,9 @@ class ONVIFDevice: await asyncio.sleep(continuous_duration) req = ptz_service.create_type("Stop") req.ProfileToken = profile.token - await ptz_service.Stop({"ProfileToken": req.ProfileToken}) + await ptz_service.Stop( + {"ProfileToken": req.ProfileToken, "PanTilt": True, "Zoom": False} + ) elif move_mode == RELATIVE_MOVE: # Guard against unsupported operation if not profile.ptz.relative: diff --git a/homeassistant/components/onvif/event.py b/homeassistant/components/onvif/event.py index d8f1e268386..eb61cbb4b71 100644 --- a/homeassistant/components/onvif/event.py +++ b/homeassistant/components/onvif/event.py @@ -76,11 +76,13 @@ class EventManager: if await self.device.create_pullpoint_subscription(): # Initialize events pullpoint = self.device.create_pullpoint_service() - await pullpoint.SetSynchronizationPoint() - req = pullpoint.create_type("PullMessages") - req.MessageLimit = 100 - req.Timeout = dt.timedelta(seconds=5) - response = await pullpoint.PullMessages(req) + try: + await pullpoint.SetSynchronizationPoint() + except SUBSCRIPTION_ERRORS: + pass + response = await pullpoint.PullMessages( + {"MessageLimit": 100, "Timeout": dt.timedelta(seconds=5)} + ) # Parse event initialization await self.async_parse_messages(response.NotificationMessage) @@ -157,10 +159,9 @@ class EventManager: if self.hass.state == CoreState.running: try: pullpoint = self.device.create_pullpoint_service() - req = pullpoint.create_type("PullMessages") - req.MessageLimit = 100 - req.Timeout = dt.timedelta(seconds=60) - response = await pullpoint.PullMessages(req) + response = await pullpoint.PullMessages( + {"MessageLimit": 100, "Timeout": dt.timedelta(seconds=60)} + ) # Renew subscription if less than two hours is left if ( diff --git a/homeassistant/components/onvif/parsers.py b/homeassistant/components/onvif/parsers.py index 438601106b5..cad2b3c8cab 100644 --- a/homeassistant/components/onvif/parsers.py +++ b/homeassistant/components/onvif/parsers.py @@ -214,6 +214,37 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event: return None +@PARSERS.register("tns1:RuleEngine/MotionRegionDetector/Motion") +# pylint: disable=protected-access +async def async_parse_motion_region_detector(uid: str, msg) -> Event: + """Handle parsing event message. + + Topic: tns1:RuleEngine/MotionRegionDetector/Motion + """ + try: + video_source = "" + video_analytics = "" + rule = "" + for source in msg.Message._value_1.Source.SimpleItem: + if source.Name == "VideoSourceConfigurationToken": + video_source = source.Value + if source.Name == "VideoAnalyticsConfigurationToken": + video_analytics = source.Value + if source.Name == "Rule": + rule = source.Value + + return Event( + f"{uid}_{msg.Topic._value_1}_{video_source}_{video_analytics}_{rule}", + f"{rule} Motion Region Detection", + "binary_sensor", + "motion", + None, + msg.Message._value_1.Data.SimpleItem[0].Value == "true", + ) + except (AttributeError, KeyError): + return None + + @PARSERS.register("tns1:RuleEngine/TamperDetector/Tamper") # pylint: disable=protected-access async def async_parse_tamper_detector(uid: str, msg) -> Event: