mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 05:05:09 +02:00
Reduce overhead to fetch unifiprotect attributes (#94976)
This commit is contained in:
@@ -38,6 +38,8 @@ from .const import (
|
|||||||
ModelType,
|
ModelType,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_SENTINEL = object()
|
||||||
|
|
||||||
|
|
||||||
def get_nested_attr(obj: Any, attr: str) -> Any:
|
def get_nested_attr(obj: Any, attr: str) -> Any:
|
||||||
"""Fetch a nested attribute."""
|
"""Fetch a nested attribute."""
|
||||||
@@ -46,9 +48,8 @@ def get_nested_attr(obj: Any, attr: str) -> Any:
|
|||||||
else:
|
else:
|
||||||
value = obj
|
value = obj
|
||||||
for key in attr.split("."):
|
for key in attr.split("."):
|
||||||
if not hasattr(value, key):
|
if (value := getattr(value, key, _SENTINEL)) is _SENTINEL:
|
||||||
return None
|
return None
|
||||||
value = getattr(value, key)
|
|
||||||
|
|
||||||
return value.value if isinstance(value, Enum) else value
|
return value.value if isinstance(value, Enum) else value
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user