diff --git a/custom_components/lg_ess/__init__.py b/custom_components/lg_ess/__init__.py index e015291..256b388 100644 --- a/custom_components/lg_ess/__init__.py +++ b/custom_components/lg_ess/__init__.py @@ -5,9 +5,10 @@ from pyess.aio_ess import ESS, ESSException from homeassistant.config_entries import ConfigEntry -from homeassistant.const import Platform -from homeassistant.core import HomeAssistant +from homeassistant.const import CONF_HOST, CONF_PASSWORD, Platform +from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers.entity_registry import async_migrate_entries from .const import DOMAIN @@ -39,3 +40,25 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await api.destruct() return unload_ok + + +async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: + """Migrate old entry.""" + _LOGGER.debug("Migrating from version %s", entry.version) + + # Add serialno to unique id in order to allow multiple devices + if entry.version == 1: + ess = await ESS.create(None, entry.data[CONF_PASSWORD], entry.data[CONF_HOST]) + serialno = (await ess.get_systeminfo())["pms"]["serialno"] + + @callback + def update_unique_id(entity_entry): + """Update unique ID of entity entry.""" + return {"new_unique_id": serialno + "_" + entity_entry.unique_id} + + await async_migrate_entries(hass, entry.entry_id, update_unique_id) + hass.config_entries.async_update_entry(entry, version=2) + + _LOGGER.info("Migration to version %s successful", entry.version) + + return True diff --git a/custom_components/lg_ess/config_flow.py b/custom_components/lg_ess/config_flow.py index 69d024a..0161394 100644 --- a/custom_components/lg_ess/config_flow.py +++ b/custom_components/lg_ess/config_flow.py @@ -6,9 +6,9 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.config_entries import ConfigFlowResult from homeassistant.const import CONF_HOST, CONF_PASSWORD from homeassistant.core import HomeAssistant -from homeassistant.data_entry_flow import FlowResult from .const import DOMAIN @@ -20,6 +20,11 @@ vol.Required(CONF_PASSWORD): str, } ) +STEP_DISCOVERED_DATA_SCHEMA = vol.Schema( + { + vol.Required(CONF_PASSWORD): str, + } +) async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]: @@ -34,19 +39,24 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, return {"title": "LG ESS"} -class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): +class EssConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow for LG ESS.""" - VERSION = 1 + def __init__(self) -> None: + """Initialize the ESS config flow.""" + self.discovery_schema: vol.Schema | None = None + + VERSION = 2 async def async_step_user( self, user_input: dict[str, Any] | None = None - ) -> FlowResult: + ) -> ConfigFlowResult: """Handle the initial step.""" errors: dict[str, str] = {} if user_input is not None: try: info = await validate_input(self.hass, user_input) + # user_input['serialno'] = info['serialno'] return self.async_create_entry(title=info["title"], data=user_input) except ESSAuthException: _LOGGER.exception("Wrong password") @@ -61,3 +71,27 @@ async def async_step_user( return self.async_show_form( step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors ) + + +# async def async_step_zeroconf( +# self, discovery_info: zeroconf.ZeroconfServiceInfo +# ) -> ConfigFlowResult: +# """Handle the zeroconf discovery.""" +# host = discovery_info.host +# properties = discovery_info.properties +# _LOGGER.info("Discovered device %s with %s", host, discovery_info) +# host = discovery_info.host +# id = {CONF_HOST: host} +# await self.async_set_unique_id(host) +# self._abort_if_unique_id_configured(updates={CONF_HOST: host}) +# +# self._async_abort_entries_match({CONF_HOST: host}) +# +# self.discovery_schema = vol.Schema( +# { +# vol.Required(CONF_HOST, default=host): str, +# } +# ) +# +# return await self.async_step_user() +# diff --git a/custom_components/lg_ess/manifest.json b/custom_components/lg_ess/manifest.json index 4a2a19e..059ce02 100644 --- a/custom_components/lg_ess/manifest.json +++ b/custom_components/lg_ess/manifest.json @@ -5,11 +5,14 @@ "config_flow": true, "dependencies": [], "documentation": "https://github.com/dkarv/hacs-lg-ess/blob/main/README.md", - "version": "0.1.0", + "version": "0.2.0", "homekit": {}, "iot_class": "local_polling", "issue_tracker": "https://github.com/dkarv/hacs-lg-ess/issues", + "documentation": "https://www.home-assistant.io/integrations/lg_ess", + "homekit": {}, + "iot_class": "local_polling", "requirements": ["pyess==0.1.15"], "ssdp": [], - "zeroconf": [] + "zeroconf": ["_pmsctrl._tcp.local."] } diff --git a/custom_components/lg_ess/sensor.py b/custom_components/lg_ess/sensor.py index 392263d..693de0a 100644 --- a/custom_components/lg_ess/sensor.py +++ b/custom_components/lg_ess/sensor.py @@ -22,6 +22,7 @@ ) from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryAuthFailed +from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -84,71 +85,133 @@ async def async_setup_entry( # and start a config flow with SOURCE_REAUTH (async_step_reauth) raise ConfigEntryAuthFailed from e + device_info = DeviceInfo( + configuration_url=None, + connections=set(), + entry_type=None, + hw_version=None, + identifiers={(DOMAIN, config_entry.entry_id)}, + manufacturer="LG", + model=system_coordinator.data["pms"]["model"], + name=config_entry.title, + serial_number=system_coordinator.data["pms"]["serialno"], + suggested_area=None, + sw_version=system_coordinator.data["version"]["pcs_version"], + via_device=(DOMAIN, ""), + ) + async_add_entities( [ MeasurementSensor( common_coordinator, + device_info, "BATT", "dc_power", UnitOfPower.WATT, icon=_BATTERYLOAD, ), MeasurementSensor( - common_coordinator, "LOAD", "load_power", UnitOfPower.WATT, icon=_LOAD + common_coordinator, + device_info, + "LOAD", + "load_power", + UnitOfPower.WATT, + icon=_LOAD, ), MeasurementSensor( - common_coordinator, "PCS", "today_self_consumption", PERCENTAGE + common_coordinator, + device_info, + "PCS", + "today_self_consumption", + PERCENTAGE, + ), + EssSensor(system_coordinator, device_info, "pms", "model"), + EssSensor(system_coordinator, device_info, "pms", "serialno"), + EssSensor( + system_coordinator, device_info, "pms", "ac_input_power" + ), # number + EssSensor( + system_coordinator, device_info, "pms", "ac_output_power" + ), # number + EssSensor( + system_coordinator, device_info, "pms", "install_date", _parse_date ), - EssSensor(system_coordinator, "pms", "model"), - EssSensor(system_coordinator, "pms", "serialno"), - EssSensor(system_coordinator, "pms", "ac_input_power"), # number - EssSensor(system_coordinator, "pms", "ac_output_power"), # number - EssSensor(system_coordinator, "pms", "install_date", _parse_date), MeasurementSensor( system_coordinator, + device_info, "batt", "capacity", UnitOfEnergy.WATT_HOUR, lambda x: int(x) * 100, ), - EssSensor(system_coordinator, "batt", "type"), # + EssSensor(system_coordinator, device_info, "batt", "type"), # MeasurementSensor( - system_coordinator, "batt", "hbc_cycle_count_1" + system_coordinator, device_info, "batt", "hbc_cycle_count_1" ), # number MeasurementSensor( - system_coordinator, "batt", "hbc_cycle_count_2" + system_coordinator, device_info, "batt", "hbc_cycle_count_2" ), # number - EssSensor(system_coordinator, "batt", "install_date", _parse_date), - EssSensor(system_coordinator, "version", "pms_version"), - EssSensor(system_coordinator, "version", "pms_build_date"), - EssSensor(system_coordinator, "version", "pcs_version"), - EssSensor(system_coordinator, "version", "bms_version"), - EssSensor(system_coordinator, "version", "bms_unit1_version"), - EssSensor(system_coordinator, "version", "bms_unit2_version"), + EssSensor( + system_coordinator, device_info, "batt", "install_date", _parse_date + ), + EssSensor(system_coordinator, device_info, "version", "pms_version"), + EssSensor(system_coordinator, device_info, "version", "pms_build_date"), + EssSensor(system_coordinator, device_info, "version", "pcs_version"), + EssSensor(system_coordinator, device_info, "version", "bms_version"), + EssSensor(system_coordinator, device_info, "version", "bms_unit1_version"), + EssSensor(system_coordinator, device_info, "version", "bms_unit2_version"), MeasurementSensor( - home_coordinator, "statistics", "pcs_pv_total_power", icon=_PV + home_coordinator, + device_info, + "statistics", + "pcs_pv_total_power", + icon=_PV, ), MeasurementSensor( - home_coordinator, "statistics", "batconv_power", icon=_BATTERYLOAD + home_coordinator, + device_info, + "statistics", + "batconv_power", + icon=_BATTERYLOAD, + ), + BinarySensor( + home_coordinator, + device_info, + "statistics", + "bat_use", + icon=_BATTERYHOME, ), - BinarySensor(home_coordinator, "statistics", "bat_use", icon=_BATTERYHOME), MeasurementSensor( - home_coordinator, "statistics", "bat_status", icon=_BATTERYSTATUS + home_coordinator, + device_info, + "statistics", + "bat_status", + icon=_BATTERYSTATUS, ), # unknown enum MeasurementSensor( home_coordinator, + device_info, "statistics", "bat_user_soc", PERCENTAGE, icon=_BATTERYHALF, ), MeasurementSensor( - home_coordinator, "statistics", "load_power", UnitOfPower.WATT + home_coordinator, + device_info, + "statistics", + "load_power", + UnitOfPower.WATT, + ), + MeasurementSensor( + home_coordinator, device_info, "statistics", "ac_output_power" + ), + MeasurementSensor( + home_coordinator, device_info, "statistics", "load_today", icon=_LOAD ), - MeasurementSensor(home_coordinator, "statistics", "ac_output_power"), - MeasurementSensor(home_coordinator, "statistics", "load_today", icon=_LOAD), MeasurementSensor( home_coordinator, + device_info, "statistics", "grid_power", UnitOfPower.WATT, @@ -156,137 +219,229 @@ async def async_setup_entry( ), MeasurementSensor( home_coordinator, + device_info, "statistics", "current_day_self_consumption", PERCENTAGE, icon=_PV, ), BinarySensor( - home_coordinator, "direction", "is_direct_consuming_", icon=_PV + home_coordinator, + device_info, + "direction", + "is_direct_consuming_", + icon=_PV, ), BinarySensor( - home_coordinator, "direction", "is_battery_charging_", icon=_CHARGING + home_coordinator, + device_info, + "direction", + "is_battery_charging_", + icon=_CHARGING, ), BinarySensor( home_coordinator, + device_info, "direction", "is_battery_discharging_", icon=_DISCHARGING, ), BinarySensor( - home_coordinator, "direction", "is_grid_selling_", icon=_TOGRID + home_coordinator, + device_info, + "direction", + "is_grid_selling_", + icon=_TOGRID, ), BinarySensor( - home_coordinator, "direction", "is_grid_buying_", icon=_FROMGRID + home_coordinator, + device_info, + "direction", + "is_grid_buying_", + icon=_FROMGRID, ), BinarySensor( home_coordinator, + device_info, "direction", "is_charging_from_grid_", icon=_CHARGING, ), BinarySensor( home_coordinator, + device_info, "direction", "is_discharging_to_grid_", icon=_DISCHARGING, ), - EssSensor(home_coordinator, "operation", "status"), - MeasurementSensor(home_coordinator, "operation", "mode"), - BinarySensor(home_coordinator, "operation", "pcs_standbymode"), - MeasurementSensor(home_coordinator, "operation", "drm_mode0"), - MeasurementSensor(home_coordinator, "operation", "remote_mode"), - MeasurementSensor(home_coordinator, "operation", "drm_control"), - BinarySensor(home_coordinator, "wintermode", "winter_status", icon=_WINTER), - BinarySensor(home_coordinator, "wintermode", "backup_status", icon=_BACKUP), - EssSensor(home_coordinator, "pcs_fault", "pcs_status"), - EssSensor(home_coordinator, "pcs_fault", "pcs_op_status"), + EssSensor(home_coordinator, device_info, "operation", "status"), + MeasurementSensor(home_coordinator, device_info, "operation", "mode"), + BinarySensor(home_coordinator, device_info, "operation", "pcs_standbymode"), + MeasurementSensor(home_coordinator, device_info, "operation", "drm_mode0"), + MeasurementSensor( + home_coordinator, device_info, "operation", "remote_mode" + ), + MeasurementSensor( + home_coordinator, device_info, "operation", "drm_control" + ), + BinarySensor( + home_coordinator, + device_info, + "wintermode", + "winter_status", + icon=_WINTER, + ), + BinarySensor( + home_coordinator, + device_info, + "wintermode", + "backup_status", + icon=_BACKUP, + ), + EssSensor(home_coordinator, device_info, "pcs_fault", "pcs_status"), + EssSensor(home_coordinator, device_info, "pcs_fault", "pcs_op_status"), MeasurementSensor( - home_coordinator, "heatpump", "heatpump_protocol", icon=_HEATPUMP + home_coordinator, + device_info, + "heatpump", + "heatpump_protocol", + icon=_HEATPUMP, ), BinarySensor( - home_coordinator, "heatpump", "heatpump_activate", icon=_HEATPUMP + home_coordinator, + device_info, + "heatpump", + "heatpump_activate", + icon=_HEATPUMP, ), MeasurementSensor( - home_coordinator, "heatpump", "current_temp", icon=_HEATPUMP + home_coordinator, + device_info, + "heatpump", + "current_temp", + icon=_HEATPUMP, ), BinarySensor( - home_coordinator, "heatpump", "heatpump_working", icon=_HEATPUMP + home_coordinator, + device_info, + "heatpump", + "heatpump_working", + icon=_HEATPUMP, + ), + BinarySensor( + home_coordinator, device_info, "evcharger", "ev_activate", icon=_EV ), - BinarySensor(home_coordinator, "evcharger", "ev_activate", icon=_EV), MeasurementSensor( - home_coordinator, "evcharger", "ev_power", UnitOfPower.WATT, icon=_EV + home_coordinator, + device_info, + "evcharger", + "ev_power", + UnitOfPower.WATT, + icon=_EV, ), - MeasurementSensor(home_coordinator, None, "gridWaitingTime"), - EssSensor(home_coordinator, None, "backupmode", icon=_BACKUP), + MeasurementSensor(home_coordinator, device_info, None, "gridWaitingTime"), + EssSensor(home_coordinator, device_info, None, "backupmode", icon=_BACKUP), IncreasingEnergySensor( common_coordinator, + device_info, "BATT", "today_batt_discharge_enery", icon=_DISCHARGING, ), IncreasingEnergySensor( common_coordinator, + device_info, "BATT", "today_batt_charge_energy", icon=_CHARGING, ), IncreasingEnergySensor( common_coordinator, + device_info, "BATT", "month_batt_discharge_energy", icon=_DISCHARGING, ), IncreasingEnergySensor( common_coordinator, + device_info, "BATT", "month_batt_charge_energy", icon=_CHARGING, ), IncreasingEnergySensor( - common_coordinator, "LOAD", "today_load_consumption_sum", icon=_LOAD + common_coordinator, + device_info, + "LOAD", + "today_load_consumption_sum", + icon=_LOAD, ), IncreasingEnergySensor( common_coordinator, + device_info, "LOAD", "today_pv_direct_consumption_enegy", icon=_PV, ), IncreasingEnergySensor( common_coordinator, + device_info, "LOAD", "today_grid_power_purchase_energy", icon=_FROMGRID, ), IncreasingEnergySensor( - common_coordinator, "LOAD", "month_load_consumption_sum", icon=_LOAD + common_coordinator, + device_info, + "LOAD", + "month_load_consumption_sum", + icon=_LOAD, ), IncreasingEnergySensor( common_coordinator, + device_info, "LOAD", "month_pv_direct_consumption_energy", icon=_PV, ), IncreasingEnergySensor( common_coordinator, + device_info, "LOAD", "month_grid_power_purchase_energy", icon=_FROMGRID, ), IncreasingEnergySensor( - common_coordinator, "PCS", "today_pv_generation_sum", icon=_PV + common_coordinator, + device_info, + "PCS", + "today_pv_generation_sum", + icon=_PV, ), IncreasingEnergySensor( - common_coordinator, "PCS", "today_grid_feed_in_energy", icon=_TOGRID + common_coordinator, + device_info, + "PCS", + "today_grid_feed_in_energy", + icon=_TOGRID, ), IncreasingEnergySensor( - common_coordinator, "PCS", "month_pv_generation_sum", icon=_PV + common_coordinator, + device_info, + "PCS", + "month_pv_generation_sum", + icon=_PV, ), IncreasingEnergySensor( - common_coordinator, "PCS", "month_grid_feed_in_energy", icon=_TOGRID + common_coordinator, + device_info, + "PCS", + "month_grid_feed_in_energy", + icon=_TOGRID, ), MeasurementSensor( common_coordinator, + device_info, "PV", "pv1_voltage", UnitOfElectricPotential.VOLT, @@ -294,6 +449,7 @@ async def async_setup_entry( ), MeasurementSensor( common_coordinator, + device_info, "PV", "pv2_voltage", UnitOfElectricPotential.VOLT, @@ -301,22 +457,39 @@ async def async_setup_entry( ), MeasurementSensor( common_coordinator, + device_info, "PV", "pv3_voltage", UnitOfElectricPotential.VOLT, icon=_THREE, ), MeasurementSensor( - common_coordinator, "PV", "pv1_power", UnitOfPower.WATT, icon=_ONE + common_coordinator, + device_info, + "PV", + "pv1_power", + UnitOfPower.WATT, + icon=_ONE, ), MeasurementSensor( - common_coordinator, "PV", "pv2_power", UnitOfPower.WATT, icon=_TWO + common_coordinator, + device_info, + "PV", + "pv2_power", + UnitOfPower.WATT, + icon=_TWO, ), MeasurementSensor( - common_coordinator, "PV", "pv3_power", UnitOfPower.WATT, icon=_THREE + common_coordinator, + device_info, + "PV", + "pv3_power", + UnitOfPower.WATT, + icon=_THREE, ), MeasurementSensor( common_coordinator, + device_info, "PV", "pv1_current", UnitOfElectricCurrent.AMPERE, @@ -324,6 +497,7 @@ async def async_setup_entry( ), MeasurementSensor( common_coordinator, + device_info, "PV", "pv2_current", UnitOfElectricCurrent.AMPERE, @@ -331,28 +505,56 @@ async def async_setup_entry( ), MeasurementSensor( common_coordinator, + device_info, "PV", "pv3_current", UnitOfElectricCurrent.AMPERE, icon=_THREE, ), IncreasingSensor( - common_coordinator, "PCS", "month_co2_reduction_accum", icon=_CO2 + common_coordinator, + device_info, + "PCS", + "month_co2_reduction_accum", + icon=_CO2, + ), + EssSensor( + common_coordinator, device_info, "PV", "capacity", icon=_PV + ), # Wp + EssSensor( + common_coordinator, device_info, "BATT", "status", icon=_BATTERYSTATUS + ), + BinarySensor( + common_coordinator, device_info, "BATT", "winter_setting", icon=_WINTER + ), + BinarySensor( + common_coordinator, device_info, "BATT", "winter_status", icon=_WINTER ), - EssSensor(common_coordinator, "PV", "capacity", icon=_PV), # Wp - EssSensor(common_coordinator, "BATT", "status", icon=_BATTERYSTATUS), - BinarySensor(common_coordinator, "BATT", "winter_setting", icon=_WINTER), - BinarySensor(common_coordinator, "BATT", "winter_status", icon=_WINTER), MeasurementSensor( - common_coordinator, "BATT", "safety_soc", PERCENTAGE, icon=_WINTER + common_coordinator, + device_info, + "BATT", + "safety_soc", + PERCENTAGE, + icon=_WINTER, + ), + BinarySensor( + common_coordinator, device_info, "BATT", "backup_setting", icon=_BACKUP + ), + BinarySensor( + common_coordinator, device_info, "BATT", "backup_status", icon=_BACKUP ), - BinarySensor(common_coordinator, "BATT", "backup_setting", icon=_BACKUP), - BinarySensor(common_coordinator, "BATT", "backup_status", icon=_BACKUP), MeasurementSensor( - common_coordinator, "BATT", "backup_soc", PERCENTAGE, icon=_BACKUP + common_coordinator, + device_info, + "BATT", + "backup_soc", + PERCENTAGE, + icon=_BACKUP, ), MeasurementSensor( common_coordinator, + device_info, "GRID", "active_power", UnitOfPower.WATT, @@ -360,23 +562,30 @@ async def async_setup_entry( ), MeasurementSensor( common_coordinator, + device_info, "GRID", "a_phase", UnitOfElectricPotential.VOLT, icon=_GRID, ), MeasurementSensor( - common_coordinator, "GRID", "freq", UnitOfFrequency.HERTZ, icon=_GRID + common_coordinator, + device_info, + "GRID", + "freq", + UnitOfFrequency.HERTZ, + icon=_GRID, ), - EssSensor(common_coordinator, "PCS", "pcs_stauts"), + EssSensor(common_coordinator, device_info, "PCS", "pcs_stauts"), MeasurementSensor( common_coordinator, + device_info, "PCS", "feed_in_limitation", PERCENTAGE, icon=_TOGRID, ), - EssSensor(common_coordinator, "PCS", "operation_mode"), + EssSensor(common_coordinator, device_info, "PCS", "operation_mode"), ] ) @@ -390,6 +599,7 @@ class EssSensor(CoordinatorEntity[ESSCoordinator], SensorEntity): def __init__( self, coordinator, + device_info: DeviceInfo, group: str | None, key: str, modify=None, @@ -397,6 +607,7 @@ def __init__( ) -> None: """Initialize the sensor with the common coordinator.""" super().__init__(coordinator) + self._attr_device_info = device_info self._group = group self._key = key self._modify = modify @@ -411,8 +622,10 @@ def __init__( .replace("_stauts", "_status") ) self._attr_translation_key = entity - self._attr_unique_id = entity + self._attr_unique_id = f"${device_info["serial_number"]}_${entity}" + # self._attr_unique_id = entity self._attr_icon = icon + self.entity_id = f"sensor.${DOMAIN}_${key}" @callback def _handle_coordinator_update(self) -> None: @@ -441,10 +654,16 @@ class BinarySensor(CoordinatorEntity[ESSCoordinator], BinarySensorEntity): _key: str def __init__( - self, coordinator, group: str | None, key: str, icon: str | None = None + self, + coordinator, + device_info: DeviceInfo, + group: str | None, + key: str, + icon: str | None = None, ) -> None: """Initialize the sensor with the coordinator.""" super().__init__(coordinator) + self._attr_device_info = device_info self._group = group self._key = key if group is None: @@ -452,8 +671,10 @@ def __init__( else: entity = group + "_" + key self._attr_translation_key = entity - self._attr_unique_id = entity + self._attr_unique_id = f"${device_info["serial_number"]}_${entity}" + # self._attr_unique_id = entity self._attr_icon = icon + self.entity_id = f"binary_sensor.${DOMAIN}_${key}" @callback def _handle_coordinator_update(self) -> None: @@ -474,6 +695,7 @@ class MeasurementSensor(EssSensor): def __init__( self, coordinator, + device_info: DeviceInfo, group: str | None, key: str, unit: str | None = None, @@ -481,7 +703,7 @@ def __init__( icon: str | None = None, ) -> None: """Initialize the sensor with the common coordinator.""" - super().__init__(coordinator, group, key, modify, icon=icon) + super().__init__(coordinator, device_info, group, key, modify, icon=icon) self._attr_native_unit_of_measurement = unit @@ -494,13 +716,14 @@ class IncreasingSensor(EssSensor): def __init__( self, coordinator, + device_info: DeviceInfo, group: str | None, key: str, unit=UnitOfEnergy.WATT_HOUR, icon: str | None = None, ) -> None: """Initialize the sensor with the coordinator.""" - super().__init__(coordinator, group, key, icon=icon) + super().__init__(coordinator, device_info, group, key, icon=icon) self._attr_native_unit_of_measurement = unit @@ -508,10 +731,17 @@ class IncreasingEnergySensor(IncreasingSensor): """Increasing energy Wh sensor.""" def __init__( - self, coordinator, group: str | None, key: str, icon: str | None = None + self, + coordinator, + device_info: DeviceInfo, + group: str | None, + key: str, + icon: str | None = None, ) -> None: """Initialize the energy sensor with the coordinator.""" - super().__init__(coordinator, group, key, UnitOfEnergy.WATT_HOUR, icon=icon) + super().__init__( + coordinator, device_info, group, key, UnitOfEnergy.WATT_HOUR, icon=icon + ) self._attr_suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR