Repository: home-assistant/core
File: homeassistant/components/enphase_envoy/sensor.py (Python)

Code before:
    EnvoyAggregateBatterySensorEntityDescription(
        key="aggregated_soc",
        translation_key="aggregated_soc",
        native_unit_of_measurement=PERCENTAGE,
        device_class=SensorDeviceClass.BATTERY,
        value_fn=attrgetter("state_of_charge"),
    ),
    EnvoyAggregateBatterySensorEntityDescription(
        key="aggregated_available_energy",
        translation_key="aggregated_available_energy",
        native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
        device_class=SensorDeviceClass.ENERGY_STORAGE,
        value_fn=attrgetter("available_energy"),
    ),
    EnvoyAggregateBatterySensorEntityDescription(
        key="aggregated_max_battery_capacity",
        translation_key="aggregated_max_capacity",
        native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
        device_class=SensorDeviceClass.ENERGY_STORAGE,
        value_fn=attrgetter("max_available_capacity"),
    ),
)


async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: EnphaseConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up envoy sensor platform."""
    coordinator = config_entry.runtime_data
    envoy_data = coordinator.envoy.data
    assert envoy_data is not None
    _LOGGER.debug("Envoy data: %s", envoy_data)

    entities: list[Entity] = [
        EnvoyProductionEntity(coordinator, description)
        for description in PRODUCTION_SENSORS
    ]
    if envoy_data.system_consumption:
        entities.extend(
            EnvoyConsumptionEntity(coordinator, description)
            for description in CONSUMPTION_SENSORS
        )
    if envoy_data.system_net_consumption:
        entities.extend(
            EnvoyNetConsumptionEntity(coordinator, description)
            for description in NET_CONSUMPTION_SENSORS
        )
    # For each production phase reported add production entities
    if envoy_data.system_production_phases:

Review comment (suggestion):
Shouldn't this be `SensorStateClass.TOTAL_INCREASING`? I am not sure about this sensor, because I don't know it, but as it uses "aggregate" in name and Watt_hour as unit, it looks like its totally increasing.

Code after:
        value_fn=attrgetter("charge_wh"),
    ),
)


@dataclass(frozen=True, kw_only=True)
class EnvoyAggregateBatterySensorEntityDescription(SensorEntityDescription):
    """Describes an Envoy aggregate Ensemble and ACB Battery sensor entity."""

    value_fn: Callable[[EnvoyBatteryAggregate], int]


AGGREGATE_BATTERY_SENSORS = (
    EnvoyAggregateBatterySensorEntityDescription(
        key="aggregated_soc",
        translation_key="aggregated_soc",
        state_class=SensorStateClass.MEASUREMENT,
        native_unit_of_measurement=PERCENTAGE,
        device_class=SensorDeviceClass.BATTERY,
        value_fn=attrgetter("state_of_charge"),
    ),
    EnvoyAggregateBatterySensorEntityDescription(
        key="aggregated_available_energy",
        translation_key="aggregated_available_energy",
        native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
        state_class=SensorStateClass.MEASUREMENT,
        device_class=SensorDeviceClass.ENERGY_STORAGE,
        value_fn=attrgetter("available_energy"),
    ),
    EnvoyAggregateBatterySensorEntityDescription(
        key="aggregated_max_battery_capacity",
        translation_key="aggregated_max_capacity",
        native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
        device_class=SensorDeviceClass.ENERGY_STORAGE,
        value_fn=attrgetter("max_available_capacity"),
    ),
)


async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: EnphaseConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up envoy sensor platform."""
    coordinator = config_entry.runtime_data
    envoy_data = coordinator.envoy.data
    assert envoy_data is not None
    _LOGGER.debug("Envoy data: %s", envoy_data)

    entities: list[Entity] = [