mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +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:
|
||||
"""Fetch a nested attribute."""
|
||||
attrs = attr.split(".")
|
||||
|
||||
if "." not in attr:
|
||||
value = getattr(obj, attr, None)
|
||||
else:
|
||||
value = obj
|
||||
for key in attrs:
|
||||
for key in attr.split("."):
|
||||
if not hasattr(value, key):
|
||||
return None
|
||||
value = getattr(value, key)
|
||||
|
||||
if isinstance(value, Enum):
|
||||
value = value.value
|
||||
|
||||
return value
|
||||
return value.value if isinstance(value, Enum) else value
|
||||
|
||||
|
||||
@callback
|
||||
|
Loading…
x
Reference in New Issue
Block a user