1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-01 05:04:21 +01:00
Files
core/homeassistant/components/deconz/util.py
T
2026-04-30 21:14:48 +02:00

30 lines
811 B
Python

"""Utilities for deCONZ integration."""
from typing import TYPE_CHECKING
from homeassistant.core import HomeAssistant, callback
from .const import DOMAIN
from .hub import DeconzHub
if TYPE_CHECKING:
from . import DeconzConfigEntry
def serial_from_unique_id(unique_id: str | None) -> str | None:
"""Get a device serial number from a unique ID, if possible."""
if not unique_id or unique_id.count(":") != 7:
return None
return unique_id.partition("-")[0]
@callback
def get_master_hub(hass: HomeAssistant) -> DeconzHub:
"""Return the gateway which is marked as master."""
entry: DeconzConfigEntry
hub: DeconzHub
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
if (hub := entry.runtime_data).master:
return hub
raise ValueError