"""Helpers for Home Assistant tests.""" from __future__ import annotations from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from custom_components.ninlight.const import DOMAIN from tests_unit.samples import MAC_RGB def entity_id_for(hass: HomeAssistant, platform: str, key: str, mac: str = MAC_RGB) -> str: """Look entities up by unique_id instead of guessing slugs.""" entity_id = er.async_get(hass).async_get_entity_id(platform, DOMAIN, f"{mac}_{key}") assert entity_id is not None, f"no {platform} entity with key {key}" return entity_id