Home Assistant Unofficial Reference 2024.12.1
util.py
Go to the documentation of this file.
1 """Support for Lutron Caseta."""
2 
3 from __future__ import annotations
4 
5 from .const import UNASSIGNED_AREA
6 
7 
8 def serial_to_unique_id(serial: int) -> str:
9  """Convert a lutron serial number to a unique id."""
10  return hex(serial)[2:].zfill(8)
11 
12 
13 def area_name_from_id(areas: dict[str, dict], area_id: str | None) -> str:
14  """Return the full area name including parent(s)."""
15  if area_id is None:
16  return UNASSIGNED_AREA
17  return _construct_area_name_from_id(areas, area_id, [])
18 
19 
21  areas: dict[str, dict], area_id: str, labels: list[str]
22 ) -> str:
23  """Recursively construct the full area name including parent(s)."""
24  area = areas[area_id]
25  parent_area_id = area["parent_id"]
26  if parent_area_id is None:
27  # This is the root area, return last area
28  return " ".join(labels)
29 
30  labels.insert(0, area["name"])
31  return _construct_area_name_from_id(areas, parent_area_id, labels)
str _construct_area_name_from_id(dict[str, dict] areas, str area_id, list[str] labels)
Definition: util.py:22
str area_name_from_id(dict[str, dict] areas, str|None area_id)
Definition: util.py:13