mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Small speedup to unifiprotect attribute lookups (#93507)
This commit is contained in:
parent
c63e3c3bf1
commit
f8d918ca4a
@ -41,18 +41,16 @@ from .const import (
|
|||||||
|
|
||||||
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."""
|
||||||
attrs = attr.split(".")
|
if "." not in attr:
|
||||||
|
value = getattr(obj, attr, None)
|
||||||
|
else:
|
||||||
value = obj
|
value = obj
|
||||||
for key in attrs:
|
for key in attr.split("."):
|
||||||
if not hasattr(value, key):
|
if not hasattr(value, key):
|
||||||
return None
|
return None
|
||||||
value = getattr(value, key)
|
value = getattr(value, key)
|
||||||
|
|
||||||
if isinstance(value, Enum):
|
return value.value if isinstance(value, Enum) else value
|
||||||
value = value.value
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user