224 files

This commit is contained in:
Home Assistant Version Control
2026-07-27 13:30:34 +00:00
parent b5723aa856
commit e36b8a1a22
224 changed files with 9967 additions and 2663 deletions
+30 -1
View File
@@ -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: