Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule parser for onvif LineDetector and CountAggregation #91885

Merged
merged 2 commits into from
Apr 24, 2023
Merged
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
64 changes: 64 additions & 0 deletions homeassistant/components/onvif/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,67 @@ async def async_parse_jobstate(uid: str, msg) -> Event | None:
)
except (AttributeError, KeyError):
return None


@PARSERS.register("tns1:RuleEngine/LineDetector/Crossed")
# pylint: disable=protected-access
async def async_parse_linedetector_crossed(uid: str, msg) -> Event | None:
"""Handle parsing event message.

Topic: tns1:RuleEngine/LineDetector/Crossed
"""
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}",
"Line Detector Crossed",
"sensor",
None,
None,
msg.Message._value_1.Data.SimpleItem[0].Value,
EntityCategory.DIAGNOSTIC,
)
except (AttributeError, KeyError):
return None


@PARSERS.register("tns1:RuleEngine/CountAggregation/Counter")
# pylint: disable=protected-access
async def async_parse_count_aggregation_counter(uid: str, msg) -> Event | None:
"""Handle parsing event message.

Topic: tns1:RuleEngine/CountAggregation/Counter
"""
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}",
"Count Aggregation Counter",
"sensor",
None,
None,
msg.Message._value_1.Data.SimpleItem[0].Value,
EntityCategory.DIAGNOSTIC,
)
except (AttributeError, KeyError):
return None