From ca61291c40eec4f82db5fc1a0b3abc9d499a802d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Apr 2023 22:28:46 -0500 Subject: [PATCH 1/2] Add rule parser for onvif LineDetector fixes #49280 --- homeassistant/components/onvif/parsers.py | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/homeassistant/components/onvif/parsers.py b/homeassistant/components/onvif/parsers.py index c2d1aa379b99df..5fd3a5d28cad97 100644 --- a/homeassistant/components/onvif/parsers.py +++ b/homeassistant/components/onvif/parsers.py @@ -611,3 +611,35 @@ 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 From 1883d24ede4a70481014f6aab68578a43199704e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Apr 2023 23:02:27 -0500 Subject: [PATCH 2/2] one more --- homeassistant/components/onvif/parsers.py | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/homeassistant/components/onvif/parsers.py b/homeassistant/components/onvif/parsers.py index 5fd3a5d28cad97..443254e125a0ea 100644 --- a/homeassistant/components/onvif/parsers.py +++ b/homeassistant/components/onvif/parsers.py @@ -643,3 +643,35 @@ async def async_parse_linedetector_crossed(uid: str, msg) -> Event | None: ) 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