mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 05:20:17 +00:00
ESPHome quality improvements round 2 (#143613)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
34
tests/components/esphome/common.py
Normal file
34
tests/components/esphome/common.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""ESPHome test common code."""
|
||||
|
||||
from homeassistant.components import assist_satellite
|
||||
from homeassistant.components.assist_satellite import AssistSatelliteEntity
|
||||
|
||||
# pylint: disable-next=hass-component-root-import
|
||||
from homeassistant.components.esphome import DOMAIN
|
||||
from homeassistant.components.esphome.assist_satellite import EsphomeAssistSatellite
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
||||
|
||||
def get_satellite_entity(
|
||||
hass: HomeAssistant, mac_address: str
|
||||
) -> EsphomeAssistSatellite | None:
|
||||
"""Get the satellite entity for a device."""
|
||||
ent_reg = er.async_get(hass)
|
||||
satellite_entity_id = ent_reg.async_get_entity_id(
|
||||
Platform.ASSIST_SATELLITE, DOMAIN, f"{mac_address}-assist_satellite"
|
||||
)
|
||||
if satellite_entity_id is None:
|
||||
return None
|
||||
assert satellite_entity_id.endswith("_assist_satellite")
|
||||
|
||||
component: EntityComponent[AssistSatelliteEntity] = hass.data[
|
||||
assist_satellite.DOMAIN
|
||||
]
|
||||
if (entity := component.get_entity(satellite_entity_id)) is not None:
|
||||
assert isinstance(entity, EsphomeAssistSatellite)
|
||||
return entity
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user