Create function to extract onvif message (#101036)
Create extract message function
This commit is contained in:
parent
3db7bdc630
commit
4a73ccb7db
1 changed files with 104 additions and 125 deletions
|
@ -20,6 +20,11 @@ VIDEO_SOURCE_MAPPING = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def extract_message(msg: Any) -> tuple[str, Any]:
|
||||||
|
"""Extract the message content and the topic."""
|
||||||
|
return msg.Topic._value_1, msg.Message._value_1 # pylint: disable=protected-access
|
||||||
|
|
||||||
|
|
||||||
def _normalize_video_source(source: str) -> str:
|
def _normalize_video_source(source: str) -> str:
|
||||||
"""Normalize video source.
|
"""Normalize video source.
|
||||||
|
|
||||||
|
@ -48,16 +53,15 @@ async def async_parse_motion_alarm(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:VideoSource/MotionAlarm
|
Topic: tns1:VideoSource/MotionAlarm
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Motion Alarm",
|
"Motion Alarm",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -72,16 +76,15 @@ async def async_parse_image_too_blurry(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:VideoSource/ImageTooBlurry/*
|
Topic: tns1:VideoSource/ImageTooBlurry/*
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Image Too Blurry",
|
"Image Too Blurry",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"problem",
|
"problem",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -97,16 +100,15 @@ async def async_parse_image_too_dark(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:VideoSource/ImageTooDark/*
|
Topic: tns1:VideoSource/ImageTooDark/*
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Image Too Dark",
|
"Image Too Dark",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"problem",
|
"problem",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -122,16 +124,15 @@ async def async_parse_image_too_bright(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:VideoSource/ImageTooBright/*
|
Topic: tns1:VideoSource/ImageTooBright/*
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Image Too Bright",
|
"Image Too Bright",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"problem",
|
"problem",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -147,16 +148,15 @@ async def async_parse_scene_change(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:VideoSource/GlobalSceneChange/*
|
Topic: tns1:VideoSource/GlobalSceneChange/*
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Global Scene Change",
|
"Global Scene Change",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"problem",
|
"problem",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -172,9 +172,8 @@ async def async_parse_detected_sound(uid: str, msg) -> Event | None:
|
||||||
audio_source = ""
|
audio_source = ""
|
||||||
audio_analytics = ""
|
audio_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "AudioSourceConfigurationToken":
|
if source.Name == "AudioSourceConfigurationToken":
|
||||||
audio_source = source.Value
|
audio_source = source.Value
|
||||||
if source.Name == "AudioAnalyticsConfigurationToken":
|
if source.Name == "AudioAnalyticsConfigurationToken":
|
||||||
|
@ -183,12 +182,12 @@ async def async_parse_detected_sound(uid: str, msg) -> Event | None:
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{audio_source}_{audio_analytics}_{rule}",
|
f"{uid}_{topic}_{audio_source}_{audio_analytics}_{rule}",
|
||||||
"Detected Sound",
|
"Detected Sound",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"sound",
|
"sound",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -204,9 +203,8 @@ async def async_parse_field_detector(uid: str, msg) -> Event | None:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "VideoSourceConfigurationToken":
|
if source.Name == "VideoSourceConfigurationToken":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
if source.Name == "VideoAnalyticsConfigurationToken":
|
if source.Name == "VideoAnalyticsConfigurationToken":
|
||||||
|
@ -215,12 +213,12 @@ async def async_parse_field_detector(uid: str, msg) -> Event | None:
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
evt = Event(
|
evt = Event(
|
||||||
f"{uid}_{topic_value}_{video_source}_{video_analytics}_{rule}",
|
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
||||||
"Field Detection",
|
"Field Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
return evt
|
return evt
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -237,9 +235,8 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event | None:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "VideoSourceConfigurationToken":
|
if source.Name == "VideoSourceConfigurationToken":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
if source.Name == "VideoAnalyticsConfigurationToken":
|
if source.Name == "VideoAnalyticsConfigurationToken":
|
||||||
|
@ -248,12 +245,12 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event | None:
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}_{video_analytics}_{rule}",
|
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
||||||
"Cell Motion Detection",
|
"Cell Motion Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -269,9 +266,8 @@ async def async_parse_motion_region_detector(uid: str, msg) -> Event | None:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "VideoSourceConfigurationToken":
|
if source.Name == "VideoSourceConfigurationToken":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
if source.Name == "VideoAnalyticsConfigurationToken":
|
if source.Name == "VideoAnalyticsConfigurationToken":
|
||||||
|
@ -280,12 +276,12 @@ async def async_parse_motion_region_detector(uid: str, msg) -> Event | None:
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}_{video_analytics}_{rule}",
|
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
||||||
"Motion Region Detection",
|
"Motion Region Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value in ["1", "true"],
|
payload.Data.SimpleItem[0].Value in ["1", "true"],
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -301,9 +297,8 @@ async def async_parse_tamper_detector(uid: str, msg) -> Event | None:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "VideoSourceConfigurationToken":
|
if source.Name == "VideoSourceConfigurationToken":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
if source.Name == "VideoAnalyticsConfigurationToken":
|
if source.Name == "VideoAnalyticsConfigurationToken":
|
||||||
|
@ -312,12 +307,12 @@ async def async_parse_tamper_detector(uid: str, msg) -> Event | None:
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}_{video_analytics}_{rule}",
|
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
||||||
"Tamper Detection",
|
"Tamper Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"problem",
|
"problem",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -332,19 +327,18 @@ async def async_parse_dog_cat_detector(uid: str, msg) -> Event | None:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "Source":
|
if source.Name == "Source":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}",
|
f"{uid}_{topic}_{video_source}",
|
||||||
"Pet Detection",
|
"Pet Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -358,19 +352,18 @@ async def async_parse_vehicle_detector(uid: str, msg) -> Event | None:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "Source":
|
if source.Name == "Source":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}",
|
f"{uid}_{topic}_{video_source}",
|
||||||
"Vehicle Detection",
|
"Vehicle Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -384,19 +377,18 @@ async def async_parse_person_detector(uid: str, msg) -> Event | None:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "Source":
|
if source.Name == "Source":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}",
|
f"{uid}_{topic}_{video_source}",
|
||||||
"Person Detection",
|
"Person Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -410,19 +402,18 @@ async def async_parse_face_detector(uid: str, msg) -> Event | None:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "Source":
|
if source.Name == "Source":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}",
|
f"{uid}_{topic}_{video_source}",
|
||||||
"Face Detection",
|
"Face Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"motion",
|
"motion",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -436,19 +427,18 @@ async def async_parse_visitor_detector(uid: str, msg) -> Event | None:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "Source":
|
if source.Name == "Source":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}",
|
f"{uid}_{topic}_{video_source}",
|
||||||
"Visitor Detection",
|
"Visitor Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"occupancy",
|
"occupancy",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -461,16 +451,15 @@ async def async_parse_digital_input(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:Device/Trigger/DigitalInput
|
Topic: tns1:Device/Trigger/DigitalInput
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Digital Input",
|
"Digital Input",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -483,16 +472,15 @@ async def async_parse_relay(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:Device/Trigger/Relay
|
Topic: tns1:Device/Trigger/Relay
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Relay Triggered",
|
"Relay Triggered",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "active",
|
payload.Data.SimpleItem[0].Value == "active",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
@ -505,16 +493,15 @@ async def async_parse_storage_failure(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:Device/HardwareFailure/StorageFailure
|
Topic: tns1:Device/HardwareFailure/StorageFailure
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Storage Failure",
|
"Storage Failure",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
"problem",
|
"problem",
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -528,14 +515,13 @@ async def async_parse_processor_usage(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:Monitoring/ProcessorUsage
|
Topic: tns1:Monitoring/ProcessorUsage
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
usage = float(payload.Data.SimpleItem[0].Value)
|
||||||
usage = float(message_value.Data.SimpleItem[0].Value)
|
|
||||||
if usage <= 1:
|
if usage <= 1:
|
||||||
usage *= 100
|
usage *= 100
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}",
|
f"{uid}_{topic}",
|
||||||
"Processor Usage",
|
"Processor Usage",
|
||||||
"sensor",
|
"sensor",
|
||||||
None,
|
None,
|
||||||
|
@ -554,11 +540,10 @@ async def async_parse_last_reboot(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastReboot
|
Topic: tns1:Monitoring/OperatingTime/LastReboot
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
date_time = local_datetime_or_none(message_value.Data.SimpleItem[0].Value)
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}",
|
f"{uid}_{topic}",
|
||||||
"Last Reboot",
|
"Last Reboot",
|
||||||
"sensor",
|
"sensor",
|
||||||
"timestamp",
|
"timestamp",
|
||||||
|
@ -577,11 +562,10 @@ async def async_parse_last_reset(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastReset
|
Topic: tns1:Monitoring/OperatingTime/LastReset
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
date_time = local_datetime_or_none(message_value.Data.SimpleItem[0].Value)
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}",
|
f"{uid}_{topic}",
|
||||||
"Last Reset",
|
"Last Reset",
|
||||||
"sensor",
|
"sensor",
|
||||||
"timestamp",
|
"timestamp",
|
||||||
|
@ -602,11 +586,10 @@ async def async_parse_backup_last(uid: str, msg) -> Event | None:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
date_time = local_datetime_or_none(message_value.Data.SimpleItem[0].Value)
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}",
|
f"{uid}_{topic}",
|
||||||
"Last Backup",
|
"Last Backup",
|
||||||
"sensor",
|
"sensor",
|
||||||
"timestamp",
|
"timestamp",
|
||||||
|
@ -626,11 +609,10 @@ async def async_parse_last_clock_sync(uid: str, msg) -> Event | None:
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastClockSynchronization
|
Topic: tns1:Monitoring/OperatingTime/LastClockSynchronization
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
date_time = local_datetime_or_none(message_value.Data.SimpleItem[0].Value)
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}",
|
f"{uid}_{topic}",
|
||||||
"Last Clock Synchronization",
|
"Last Clock Synchronization",
|
||||||
"sensor",
|
"sensor",
|
||||||
"timestamp",
|
"timestamp",
|
||||||
|
@ -651,16 +633,15 @@ async def async_parse_jobstate(uid: str, msg) -> Event | None:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
source = payload.Source.SimpleItem[0].Value
|
||||||
source = message_value.Source.SimpleItem[0].Value
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{source}",
|
f"{uid}_{topic}_{source}",
|
||||||
"Recording Job State",
|
"Recording Job State",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value == "Active",
|
payload.Data.SimpleItem[0].Value == "Active",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -677,9 +658,8 @@ async def async_parse_linedetector_crossed(uid: str, msg) -> Event | None:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "VideoSourceConfigurationToken":
|
if source.Name == "VideoSourceConfigurationToken":
|
||||||
video_source = source.Value
|
video_source = source.Value
|
||||||
if source.Name == "VideoAnalyticsConfigurationToken":
|
if source.Name == "VideoAnalyticsConfigurationToken":
|
||||||
|
@ -688,12 +668,12 @@ async def async_parse_linedetector_crossed(uid: str, msg) -> Event | None:
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}_{video_analytics}_{rule}",
|
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
||||||
"Line Detector Crossed",
|
"Line Detector Crossed",
|
||||||
"sensor",
|
"sensor",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value,
|
payload.Data.SimpleItem[0].Value,
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -710,9 +690,8 @@ async def async_parse_count_aggregation_counter(uid: str, msg) -> Event | None:
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
message_value = msg.Message._value_1 # pylint: disable=protected-access
|
topic, payload = extract_message(msg)
|
||||||
topic_value = msg.Topic._value_1 # pylint: disable=protected-access
|
for source in payload.Source.SimpleItem:
|
||||||
for source in message_value.Source.SimpleItem:
|
|
||||||
if source.Name == "VideoSourceConfigurationToken":
|
if source.Name == "VideoSourceConfigurationToken":
|
||||||
video_source = _normalize_video_source(source.Value)
|
video_source = _normalize_video_source(source.Value)
|
||||||
if source.Name == "VideoAnalyticsConfigurationToken":
|
if source.Name == "VideoAnalyticsConfigurationToken":
|
||||||
|
@ -721,12 +700,12 @@ async def async_parse_count_aggregation_counter(uid: str, msg) -> Event | None:
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
return Event(
|
return Event(
|
||||||
f"{uid}_{topic_value}_{video_source}_{video_analytics}_{rule}",
|
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
||||||
"Count Aggregation Counter",
|
"Count Aggregation Counter",
|
||||||
"sensor",
|
"sensor",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
message_value.Data.SimpleItem[0].Value,
|
payload.Data.SimpleItem[0].Value,
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue