mirror of
https://github.com/home-assistant/core.git
synced 2026-04-29 13:13:46 +01:00
22 lines
577 B
Python
22 lines
577 B
Python
"""Helpers for automation."""
|
|
|
|
|
|
def get_absolute_description_key(domain: str, key: str) -> str:
|
|
"""Return the absolute description key."""
|
|
if not key.startswith("_"):
|
|
return f"{domain}.{key}"
|
|
key = key[1:] # Remove leading underscore
|
|
if not key:
|
|
return domain
|
|
return key
|
|
|
|
|
|
def get_relative_description_key(domain: str, key: str) -> str:
|
|
"""Return the relative description key."""
|
|
platform, *subtype = key.split(".", 1)
|
|
if platform != domain:
|
|
return f"_{key}"
|
|
if not subtype:
|
|
return "_"
|
|
return subtype[0]
|