mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Move redundant attribute and key error handling to event parser caller (#140630)
This commit is contained in:
parent
537302ce56
commit
11e15b1405
@ -174,11 +174,20 @@ class EventManager:
|
|||||||
UNHANDLED_TOPICS.add(topic)
|
UNHANDLED_TOPICS.add(topic)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
event = await parser(unique_id, msg)
|
event = await parser(unique_id, msg)
|
||||||
|
error = None
|
||||||
|
except (AttributeError, KeyError) as e:
|
||||||
|
event = None
|
||||||
|
error = e
|
||||||
|
|
||||||
if not event:
|
if not event:
|
||||||
LOGGER.warning(
|
LOGGER.warning(
|
||||||
"%s: Unable to parse event from %s: %s", self.name, unique_id, msg
|
"%s: Unable to parse event from %s: %s: %s",
|
||||||
|
self.name,
|
||||||
|
unique_id,
|
||||||
|
error,
|
||||||
|
msg,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ async def async_parse_motion_alarm(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:VideoSource/MotionAlarm
|
Topic: tns1:VideoSource/MotionAlarm
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -65,8 +64,6 @@ async def async_parse_motion_alarm(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:VideoSource/ImageTooBlurry/AnalyticsService")
|
@PARSERS.register("tns1:VideoSource/ImageTooBlurry/AnalyticsService")
|
||||||
@ -77,7 +74,6 @@ async def async_parse_image_too_blurry(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:VideoSource/ImageTooBlurry/*
|
Topic: tns1:VideoSource/ImageTooBlurry/*
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -89,8 +85,6 @@ async def async_parse_image_too_blurry(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:VideoSource/ImageTooDark/AnalyticsService")
|
@PARSERS.register("tns1:VideoSource/ImageTooDark/AnalyticsService")
|
||||||
@ -101,7 +95,6 @@ async def async_parse_image_too_dark(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:VideoSource/ImageTooDark/*
|
Topic: tns1:VideoSource/ImageTooDark/*
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -113,8 +106,6 @@ async def async_parse_image_too_dark(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:VideoSource/ImageTooBright/AnalyticsService")
|
@PARSERS.register("tns1:VideoSource/ImageTooBright/AnalyticsService")
|
||||||
@ -125,7 +116,6 @@ async def async_parse_image_too_bright(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:VideoSource/ImageTooBright/*
|
Topic: tns1:VideoSource/ImageTooBright/*
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -137,8 +127,6 @@ async def async_parse_image_too_bright(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:VideoSource/GlobalSceneChange/AnalyticsService")
|
@PARSERS.register("tns1:VideoSource/GlobalSceneChange/AnalyticsService")
|
||||||
@ -149,7 +137,6 @@ async def async_parse_scene_change(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:VideoSource/GlobalSceneChange/*
|
Topic: tns1:VideoSource/GlobalSceneChange/*
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -160,8 +147,6 @@ async def async_parse_scene_change(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:AudioAnalytics/Audio/DetectedSound")
|
@PARSERS.register("tns1:AudioAnalytics/Audio/DetectedSound")
|
||||||
@ -170,7 +155,6 @@ async def async_parse_detected_sound(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:AudioAnalytics/Audio/DetectedSound
|
Topic: tns1:AudioAnalytics/Audio/DetectedSound
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
audio_source = ""
|
audio_source = ""
|
||||||
audio_analytics = ""
|
audio_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -191,8 +175,6 @@ async def async_parse_detected_sound(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/FieldDetector/ObjectsInside")
|
@PARSERS.register("tns1:RuleEngine/FieldDetector/ObjectsInside")
|
||||||
@ -201,7 +183,6 @@ async def async_parse_field_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/FieldDetector/ObjectsInside
|
Topic: tns1:RuleEngine/FieldDetector/ObjectsInside
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -214,7 +195,7 @@ async def async_parse_field_detector(uid: str, msg) -> Event | None:
|
|||||||
if source.Name == "Rule":
|
if source.Name == "Rule":
|
||||||
rule = source.Value
|
rule = source.Value
|
||||||
|
|
||||||
evt = Event(
|
return Event(
|
||||||
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
f"{uid}_{topic}_{video_source}_{video_analytics}_{rule}",
|
||||||
"Field Detection",
|
"Field Detection",
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
@ -222,9 +203,6 @@ async def async_parse_field_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
return evt
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/CellMotionDetector/Motion")
|
@PARSERS.register("tns1:RuleEngine/CellMotionDetector/Motion")
|
||||||
@ -233,7 +211,6 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/CellMotionDetector/Motion
|
Topic: tns1:RuleEngine/CellMotionDetector/Motion
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -254,8 +231,6 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/MotionRegionDetector/Motion")
|
@PARSERS.register("tns1:RuleEngine/MotionRegionDetector/Motion")
|
||||||
@ -264,7 +239,6 @@ async def async_parse_motion_region_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/MotionRegionDetector/Motion
|
Topic: tns1:RuleEngine/MotionRegionDetector/Motion
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -285,8 +259,6 @@ async def async_parse_motion_region_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value in ["1", "true"],
|
payload.Data.SimpleItem[0].Value in ["1", "true"],
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/TamperDetector/Tamper")
|
@PARSERS.register("tns1:RuleEngine/TamperDetector/Tamper")
|
||||||
@ -295,7 +267,6 @@ async def async_parse_tamper_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/TamperDetector/Tamper
|
Topic: tns1:RuleEngine/TamperDetector/Tamper
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -317,8 +288,6 @@ async def async_parse_tamper_detector(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/DogCatDetect")
|
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/DogCatDetect")
|
||||||
@ -327,7 +296,6 @@ async def async_parse_dog_cat_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/MyRuleDetector/DogCatDetect
|
Topic: tns1:RuleEngine/MyRuleDetector/DogCatDetect
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
for source in payload.Source.SimpleItem:
|
for source in payload.Source.SimpleItem:
|
||||||
@ -342,8 +310,6 @@ async def async_parse_dog_cat_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/VehicleDetect")
|
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/VehicleDetect")
|
||||||
@ -352,7 +318,6 @@ async def async_parse_vehicle_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/MyRuleDetector/VehicleDetect
|
Topic: tns1:RuleEngine/MyRuleDetector/VehicleDetect
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
for source in payload.Source.SimpleItem:
|
for source in payload.Source.SimpleItem:
|
||||||
@ -367,8 +332,6 @@ async def async_parse_vehicle_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
_TAPO_EVENT_TEMPLATES: dict[str, Event] = {
|
_TAPO_EVENT_TEMPLATES: dict[str, Event] = {
|
||||||
@ -420,7 +383,6 @@ async def async_parse_tplink_detector(uid: str, msg) -> Event | None:
|
|||||||
Topic: tns1:RuleEngine/PeopleDetector/People
|
Topic: tns1:RuleEngine/PeopleDetector/People
|
||||||
Topic: tns1:RuleEngine/TPSmartEventDetector/TPSmartEvent
|
Topic: tns1:RuleEngine/TPSmartEventDetector/TPSmartEvent
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -444,9 +406,6 @@ async def async_parse_tplink_detector(uid: str, msg) -> Event | None:
|
|||||||
value=item.Value == "true",
|
value=item.Value == "true",
|
||||||
)
|
)
|
||||||
|
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -456,7 +415,6 @@ async def async_parse_person_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/MyRuleDetector/PeopleDetect
|
Topic: tns1:RuleEngine/MyRuleDetector/PeopleDetect
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
for source in payload.Source.SimpleItem:
|
for source in payload.Source.SimpleItem:
|
||||||
@ -471,8 +429,6 @@ async def async_parse_person_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/FaceDetect")
|
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/FaceDetect")
|
||||||
@ -481,7 +437,6 @@ async def async_parse_face_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/MyRuleDetector/FaceDetect
|
Topic: tns1:RuleEngine/MyRuleDetector/FaceDetect
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
for source in payload.Source.SimpleItem:
|
for source in payload.Source.SimpleItem:
|
||||||
@ -496,8 +451,6 @@ async def async_parse_face_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/Visitor")
|
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/Visitor")
|
||||||
@ -506,7 +459,6 @@ async def async_parse_visitor_detector(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/MyRuleDetector/Visitor
|
Topic: tns1:RuleEngine/MyRuleDetector/Visitor
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
for source in payload.Source.SimpleItem:
|
for source in payload.Source.SimpleItem:
|
||||||
@ -521,8 +473,6 @@ async def async_parse_visitor_detector(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Device/Trigger/DigitalInput")
|
@PARSERS.register("tns1:Device/Trigger/DigitalInput")
|
||||||
@ -531,7 +481,6 @@ async def async_parse_digital_input(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Device/Trigger/DigitalInput
|
Topic: tns1:Device/Trigger/DigitalInput
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -542,8 +491,6 @@ async def async_parse_digital_input(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Device/Trigger/Relay")
|
@PARSERS.register("tns1:Device/Trigger/Relay")
|
||||||
@ -552,7 +499,6 @@ async def async_parse_relay(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Device/Trigger/Relay
|
Topic: tns1:Device/Trigger/Relay
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -563,8 +509,6 @@ async def async_parse_relay(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "active",
|
payload.Data.SimpleItem[0].Value == "active",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Device/HardwareFailure/StorageFailure")
|
@PARSERS.register("tns1:Device/HardwareFailure/StorageFailure")
|
||||||
@ -573,7 +517,6 @@ async def async_parse_storage_failure(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Device/HardwareFailure/StorageFailure
|
Topic: tns1:Device/HardwareFailure/StorageFailure
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -585,8 +528,6 @@ async def async_parse_storage_failure(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Monitoring/ProcessorUsage")
|
@PARSERS.register("tns1:Monitoring/ProcessorUsage")
|
||||||
@ -595,7 +536,6 @@ async def async_parse_processor_usage(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Monitoring/ProcessorUsage
|
Topic: tns1:Monitoring/ProcessorUsage
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
usage = float(payload.Data.SimpleItem[0].Value)
|
usage = float(payload.Data.SimpleItem[0].Value)
|
||||||
if usage <= 1:
|
if usage <= 1:
|
||||||
@ -610,8 +550,6 @@ async def async_parse_processor_usage(uid: str, msg) -> Event | None:
|
|||||||
int(usage),
|
int(usage),
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReboot")
|
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReboot")
|
||||||
@ -620,7 +558,6 @@ async def async_parse_last_reboot(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastReboot
|
Topic: tns1:Monitoring/OperatingTime/LastReboot
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
return Event(
|
return Event(
|
||||||
@ -632,8 +569,6 @@ async def async_parse_last_reboot(uid: str, msg) -> Event | None:
|
|||||||
date_time,
|
date_time,
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReset")
|
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReset")
|
||||||
@ -642,7 +577,6 @@ async def async_parse_last_reset(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastReset
|
Topic: tns1:Monitoring/OperatingTime/LastReset
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
return Event(
|
return Event(
|
||||||
@ -655,8 +589,6 @@ async def async_parse_last_reset(uid: str, msg) -> Event | None:
|
|||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
entity_enabled=False,
|
entity_enabled=False,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Monitoring/Backup/Last")
|
@PARSERS.register("tns1:Monitoring/Backup/Last")
|
||||||
@ -665,8 +597,6 @@ async def async_parse_backup_last(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Monitoring/Backup/Last
|
Topic: tns1:Monitoring/Backup/Last
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
return Event(
|
return Event(
|
||||||
@ -679,8 +609,6 @@ async def async_parse_backup_last(uid: str, msg) -> Event | None:
|
|||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
entity_enabled=False,
|
entity_enabled=False,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:Monitoring/OperatingTime/LastClockSynchronization")
|
@PARSERS.register("tns1:Monitoring/OperatingTime/LastClockSynchronization")
|
||||||
@ -689,7 +617,6 @@ async def async_parse_last_clock_sync(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastClockSynchronization
|
Topic: tns1:Monitoring/OperatingTime/LastClockSynchronization
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
date_time = local_datetime_or_none(payload.Data.SimpleItem[0].Value)
|
||||||
return Event(
|
return Event(
|
||||||
@ -702,8 +629,6 @@ async def async_parse_last_clock_sync(uid: str, msg) -> Event | None:
|
|||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
entity_enabled=False,
|
entity_enabled=False,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RecordingConfig/JobState")
|
@PARSERS.register("tns1:RecordingConfig/JobState")
|
||||||
@ -713,7 +638,6 @@ async def async_parse_jobstate(uid: str, msg) -> Event | None:
|
|||||||
Topic: tns1:RecordingConfig/JobState
|
Topic: tns1:RecordingConfig/JobState
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
source = payload.Source.SimpleItem[0].Value
|
source = payload.Source.SimpleItem[0].Value
|
||||||
return Event(
|
return Event(
|
||||||
@ -725,8 +649,6 @@ async def async_parse_jobstate(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value == "Active",
|
payload.Data.SimpleItem[0].Value == "Active",
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/LineDetector/Crossed")
|
@PARSERS.register("tns1:RuleEngine/LineDetector/Crossed")
|
||||||
@ -735,7 +657,6 @@ async def async_parse_linedetector_crossed(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/LineDetector/Crossed
|
Topic: tns1:RuleEngine/LineDetector/Crossed
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -757,8 +678,6 @@ async def async_parse_linedetector_crossed(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value,
|
payload.Data.SimpleItem[0].Value,
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:RuleEngine/CountAggregation/Counter")
|
@PARSERS.register("tns1:RuleEngine/CountAggregation/Counter")
|
||||||
@ -767,7 +686,6 @@ async def async_parse_count_aggregation_counter(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:RuleEngine/CountAggregation/Counter
|
Topic: tns1:RuleEngine/CountAggregation/Counter
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
video_source = ""
|
video_source = ""
|
||||||
video_analytics = ""
|
video_analytics = ""
|
||||||
rule = ""
|
rule = ""
|
||||||
@ -789,8 +707,6 @@ async def async_parse_count_aggregation_counter(uid: str, msg) -> Event | None:
|
|||||||
payload.Data.SimpleItem[0].Value,
|
payload.Data.SimpleItem[0].Value,
|
||||||
EntityCategory.DIAGNOSTIC,
|
EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@PARSERS.register("tns1:UserAlarm/IVA/HumanShapeDetect")
|
@PARSERS.register("tns1:UserAlarm/IVA/HumanShapeDetect")
|
||||||
@ -799,7 +715,6 @@ async def async_parse_human_shape_detect(uid: str, msg) -> Event | None:
|
|||||||
|
|
||||||
Topic: tns1:UserAlarm/IVA/HumanShapeDetect
|
Topic: tns1:UserAlarm/IVA/HumanShapeDetect
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
topic, payload = extract_message(msg)
|
topic, payload = extract_message(msg)
|
||||||
video_source = ""
|
video_source = ""
|
||||||
for source in payload.Source.SimpleItem:
|
for source in payload.Source.SimpleItem:
|
||||||
@ -815,5 +730,3 @@ async def async_parse_human_shape_detect(uid: str, msg) -> Event | None:
|
|||||||
None,
|
None,
|
||||||
payload.Data.SimpleItem[0].Value == "true",
|
payload.Data.SimpleItem[0].Value == "true",
|
||||||
)
|
)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
return None
|
|
||||||
|
@ -5,6 +5,7 @@ import os
|
|||||||
|
|
||||||
import onvif
|
import onvif
|
||||||
import onvif.settings
|
import onvif.settings
|
||||||
|
import pytest
|
||||||
from zeep import Client
|
from zeep import Client
|
||||||
from zeep.transports import Transport
|
from zeep.transports import Transport
|
||||||
|
|
||||||
@ -732,7 +733,8 @@ async def test_tapo_intrusion(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def test_tapo_missing_attributes(hass: HomeAssistant) -> None:
|
async def test_tapo_missing_attributes(hass: HomeAssistant) -> None:
|
||||||
"""Tests async_parse_tplink_detector with missing fields."""
|
"""Tests async_parse_tplink_detector with missing fields."""
|
||||||
event = await get_event(
|
with pytest.raises(AttributeError, match="SimpleItem"):
|
||||||
|
await get_event(
|
||||||
{
|
{
|
||||||
"Message": {
|
"Message": {
|
||||||
"_value_1": {
|
"_value_1": {
|
||||||
@ -750,8 +752,6 @@ async def test_tapo_missing_attributes(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert event is None
|
|
||||||
|
|
||||||
|
|
||||||
async def test_tapo_unknown_type(hass: HomeAssistant) -> None:
|
async def test_tapo_unknown_type(hass: HomeAssistant) -> None:
|
||||||
"""Tests async_parse_tplink_detector with unknown event type."""
|
"""Tests async_parse_tplink_detector with unknown event type."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user