197 files
This commit is contained in:
@@ -59,13 +59,13 @@ from .const import (
|
||||
DATA_ENTITY_TYPES,
|
||||
DATA_GROUP_ENTITIES,
|
||||
DATA_HAS_GROUP_INCLUDE,
|
||||
DATA_MEASURE_APP_COORDINATOR,
|
||||
DATA_SENSOR_TYPES,
|
||||
DATA_SOURCE_DOMAINS,
|
||||
DATA_USED_UNIQUE_IDS,
|
||||
DISCOVERY_TYPE,
|
||||
DOMAIN,
|
||||
DOMAIN_CONFIG,
|
||||
DUMMY_ENTITY_ID,
|
||||
ENTRY_DATA_ENERGY_ENTITY,
|
||||
ENTRY_DATA_POWER_ENTITY,
|
||||
ENTRY_GLOBAL_CONFIG_UNIQUE_ID,
|
||||
@@ -87,8 +87,8 @@ from .const import (
|
||||
SensorType,
|
||||
)
|
||||
from .device_binding import (
|
||||
attach_configured_device_entry,
|
||||
attach_entities_to_resolved_device,
|
||||
assign_device_to_entities,
|
||||
resolve_source_device,
|
||||
)
|
||||
from .errors import (
|
||||
PowercalcSetupError,
|
||||
@@ -97,6 +97,7 @@ from .errors import (
|
||||
)
|
||||
from .group_include.filter import FilterOperator, create_composite_filter
|
||||
from .group_include.include import find_entities
|
||||
from .measure import MeasureAppCoordinator
|
||||
from .sensors.cost import CostSensor, create_cost_sensor_for_energy_entity
|
||||
from .sensors.daily_energy import (
|
||||
create_daily_fixed_energy_power_sensor,
|
||||
@@ -108,6 +109,7 @@ from .sensors.group.config_entry_utils import add_to_associated_groups
|
||||
from .sensors.group.custom import GroupedSensor
|
||||
from .sensors.group.factory import create_group_sensors
|
||||
from .sensors.group.standby import StandbyPowerSensor
|
||||
from .sensors.measure import MeasureSessionStatusSensor
|
||||
from .sensors.power import PowerSensor, VirtualPowerSensor, create_power_sensor
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -127,6 +129,11 @@ async def async_setup_platform(
|
||||
) -> None:
|
||||
"""Setup sensors from YAML config sensor entries."""
|
||||
|
||||
if discovery_info and discovery_info.get(DISCOVERY_TYPE) == PowercalcDiscoveryType.MEASURE_APP:
|
||||
coordinator: MeasureAppCoordinator = hass.data[DOMAIN][DATA_MEASURE_APP_COORDINATOR]
|
||||
async_add_entities([MeasureSessionStatusSensor(coordinator)])
|
||||
return
|
||||
|
||||
# Legacy sensor platform config is used. Raise an issue.
|
||||
if not discovery_info and config:
|
||||
async_create_issue(
|
||||
@@ -218,7 +225,7 @@ async def _async_setup_entities(
|
||||
_LOGGER.error(err)
|
||||
return
|
||||
|
||||
attach_entities_to_resolved_device(config_entry, entities.new, hass, None, config)
|
||||
assign_device_to_entities(hass, config_entry, entities.new, None, config)
|
||||
|
||||
entities_to_add = [entity for entity in entities.new if isinstance(entity, SensorEntity)]
|
||||
for entity in entities_to_add:
|
||||
@@ -662,7 +669,7 @@ async def create_individual_sensors(
|
||||
source_entity = create_source_entity(sensor_config[CONF_ENTITY_ID], hass)
|
||||
|
||||
# For device-based profiles, attach the device entry to the source entity
|
||||
source_entity = attach_configured_device_entry(hass, sensor_config, source_entity)
|
||||
source_entity = resolve_source_device(hass, sensor_config, source_entity)
|
||||
|
||||
used_unique_ids = hass.data[DOMAIN].get(DATA_USED_UNIQUE_IDS, [])
|
||||
|
||||
@@ -699,7 +706,7 @@ async def create_individual_sensors(
|
||||
create_energy_related_sensors(hass, sensor_config, energy_sensor, source_entity, config_entry),
|
||||
)
|
||||
|
||||
attach_entities_to_resolved_device(config_entry, entities_to_add, hass, source_entity, sensor_config)
|
||||
assign_device_to_entities(hass, config_entry, entities_to_add, source_entity, sensor_config)
|
||||
hass.data[DOMAIN][DATA_CONFIGURED_ENTITIES].update(
|
||||
{source_entity.entity_id: [(entity, context.is_yaml) for entity in entities_to_add]},
|
||||
)
|
||||
@@ -738,7 +745,7 @@ def check_entity_not_already_configured(
|
||||
used_unique_ids: list[str],
|
||||
context: CreationContext,
|
||||
) -> None:
|
||||
if source_entity.entity_id == DUMMY_ENTITY_ID:
|
||||
if source_entity.is_dummy:
|
||||
return
|
||||
|
||||
entity_id = source_entity.entity_id
|
||||
|
||||
Reference in New Issue
Block a user