Fix onvif sensor detection and onvif stop service call (#41949)
* Fix stop service call after movement, add new parser for topic: tns1:RuleEngine/MotionRegionDetector/Motion * Fix PullMessages call and formatting Stop call * Fix timeout on pullmessages call * Fix black and flake8 detected issues * add SetSynchronizationPoint with try/except block
This commit is contained in:
parent
4459c843ea
commit
d01a96d1ce
3 changed files with 44 additions and 10 deletions
|
@ -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:
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue