224 files
This commit is contained in:
@@ -12,11 +12,38 @@ from homeassistant.helpers.entity_registry import RegistryEntry
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from custom_components.powercalc.common import SourceEntity
|
||||
from custom_components.powercalc.const import CONF_AREA
|
||||
from custom_components.powercalc.const import CONF_AREA, DUMMY_ENTITY_ID
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def is_composite_device_id(hass: HomeAssistant, device_id: str) -> bool:
|
||||
"""
|
||||
Return whether a device ID identifies a legacy composite device.
|
||||
Check for availability of async_is_composite_device_id, because this function is only available in HA >=2026.8
|
||||
"""
|
||||
device_reg = device_registry.async_get(hass)
|
||||
is_composite = getattr(device_reg, "async_is_composite_device_id", None)
|
||||
if not callable(is_composite):
|
||||
return False
|
||||
return bool(is_composite(device_id))
|
||||
|
||||
|
||||
def attach_configured_device_entry(
|
||||
hass: HomeAssistant,
|
||||
sensor_config: ConfigType,
|
||||
source_entity: SourceEntity,
|
||||
) -> SourceEntity:
|
||||
"""Attach the configured device entry to a device-based source entity."""
|
||||
if source_entity.entity_id != DUMMY_ENTITY_ID:
|
||||
return source_entity
|
||||
|
||||
device_entry = get_device_entry(hass, sensor_config=sensor_config)
|
||||
if device_entry:
|
||||
return source_entity._replace(device_entry=device_entry)
|
||||
return source_entity
|
||||
|
||||
|
||||
async def attach_entities_to_resolved_device(
|
||||
config_entry: ConfigEntry | None,
|
||||
entities_to_add: list[Entity],
|
||||
@@ -53,6 +80,8 @@ def get_device_entry(
|
||||
if device_id is None and config_entry is not None:
|
||||
device_id = config_entry.data.get(CONF_DEVICE)
|
||||
if device_id is not None:
|
||||
if is_composite_device_id(hass, device_id):
|
||||
return None
|
||||
return device_registry.async_get(hass).async_get(device_id)
|
||||
|
||||
if source_entity:
|
||||
|
||||
Reference in New Issue
Block a user