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)
|
await asyncio.sleep(continuous_duration)
|
||||||
req = ptz_service.create_type("Stop")
|
req = ptz_service.create_type("Stop")
|
||||||
req.ProfileToken = profile.token
|
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:
|
elif move_mode == RELATIVE_MOVE:
|
||||||
# Guard against unsupported operation
|
# Guard against unsupported operation
|
||||||
if not profile.ptz.relative:
|
if not profile.ptz.relative:
|
||||||
|
|
|
@ -76,11 +76,13 @@ class EventManager:
|
||||||
if await self.device.create_pullpoint_subscription():
|
if await self.device.create_pullpoint_subscription():
|
||||||
# Initialize events
|
# Initialize events
|
||||||
pullpoint = self.device.create_pullpoint_service()
|
pullpoint = self.device.create_pullpoint_service()
|
||||||
await pullpoint.SetSynchronizationPoint()
|
try:
|
||||||
req = pullpoint.create_type("PullMessages")
|
await pullpoint.SetSynchronizationPoint()
|
||||||
req.MessageLimit = 100
|
except SUBSCRIPTION_ERRORS:
|
||||||
req.Timeout = dt.timedelta(seconds=5)
|
pass
|
||||||
response = await pullpoint.PullMessages(req)
|
response = await pullpoint.PullMessages(
|
||||||
|
{"MessageLimit": 100, "Timeout": dt.timedelta(seconds=5)}
|
||||||
|
)
|
||||||
|
|
||||||
# Parse event initialization
|
# Parse event initialization
|
||||||
await self.async_parse_messages(response.NotificationMessage)
|
await self.async_parse_messages(response.NotificationMessage)
|
||||||
|
@ -157,10 +159,9 @@ class EventManager:
|
||||||
if self.hass.state == CoreState.running:
|
if self.hass.state == CoreState.running:
|
||||||
try:
|
try:
|
||||||
pullpoint = self.device.create_pullpoint_service()
|
pullpoint = self.device.create_pullpoint_service()
|
||||||
req = pullpoint.create_type("PullMessages")
|
response = await pullpoint.PullMessages(
|
||||||
req.MessageLimit = 100
|
{"MessageLimit": 100, "Timeout": dt.timedelta(seconds=60)}
|
||||||
req.Timeout = dt.timedelta(seconds=60)
|
)
|
||||||
response = await pullpoint.PullMessages(req)
|
|
||||||
|
|
||||||
# Renew subscription if less than two hours is left
|
# Renew subscription if less than two hours is left
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -214,6 +214,37 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event:
|
||||||
return None
|
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")
|
@PARSERS.register("tns1:RuleEngine/TamperDetector/Tamper")
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
async def async_parse_tamper_detector(uid: str, msg) -> Event:
|
async def async_parse_tamper_detector(uid: str, msg) -> Event:
|
||||||
|
|
Loading…
Add table
Reference in a new issue