From 215b3174ab9c3cdd38b8d6f81d07fcef35446fb3 Mon Sep 17 00:00:00 2001 From: michalbiesek Date: Fri, 22 Nov 2024 03:11:47 +0100 Subject: [PATCH] Add missing device type ESS Ref: https://support.huawei.com/enterprise/en/doc/EDOC1100316813/c2b572a8/device-list-interface Ref: https://support.huawei.com/enterprise/en/doc/EDOC1100261860/3557ba96/real-time-device-data-interface Signed-off-by: michalbiesek --- .../fusion_solar/device_real_kpi_coordinator.py | 6 ++++-- .../fusion_solar/fusion_solar/const.py | 1 + .../fusion_solar/fusion_solar/openapi/device.py | 2 ++ custom_components/fusion_solar/sensor.py | 17 ++++++++++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/custom_components/fusion_solar/device_real_kpi_coordinator.py b/custom_components/fusion_solar/device_real_kpi_coordinator.py index 81152a3..76dfb7f 100644 --- a/custom_components/fusion_solar/device_real_kpi_coordinator.py +++ b/custom_components/fusion_solar/device_real_kpi_coordinator.py @@ -10,7 +10,8 @@ from .const import DOMAIN from .fusion_solar.const import ATTR_DEVICE_REAL_KPI_DEV_ID, ATTR_DEVICE_REAL_KPI_DATA_ITEM_MAP, \ PARAM_DEVICE_TYPE_ID_STRING_INVERTER, PARAM_DEVICE_TYPE_ID_EMI, PARAM_DEVICE_TYPE_ID_GRID_METER, \ - PARAM_DEVICE_TYPE_ID_RESIDENTIAL_INVERTER, PARAM_DEVICE_TYPE_ID_BATTERY, PARAM_DEVICE_TYPE_ID_POWER_SENSOR + PARAM_DEVICE_TYPE_ID_RESIDENTIAL_INVERTER, PARAM_DEVICE_TYPE_ID_BATTERY, PARAM_DEVICE_TYPE_ID_POWER_SENSOR, \ + PARAM_DEVICE_TYPE_ID_C_I_UTILITY_ESS from .fusion_solar.openapi.openapi_api import FusionSolarOpenApiError, FusionSolarOpenApiAccessFrequencyTooHighError _LOGGER = logging.getLogger(__name__) @@ -85,7 +86,8 @@ def device_ids_grouped_per_type_id(self): # skip devices wherefore no real kpi data is available if device.type_id not in [PARAM_DEVICE_TYPE_ID_STRING_INVERTER, PARAM_DEVICE_TYPE_ID_EMI, PARAM_DEVICE_TYPE_ID_GRID_METER, PARAM_DEVICE_TYPE_ID_RESIDENTIAL_INVERTER, - PARAM_DEVICE_TYPE_ID_BATTERY, PARAM_DEVICE_TYPE_ID_POWER_SENSOR]: + PARAM_DEVICE_TYPE_ID_BATTERY, PARAM_DEVICE_TYPE_ID_POWER_SENSOR, + PARAM_DEVICE_TYPE_ID_C_I_UTILITY_ESS]: continue device_from_registry = device_registry.async_get_device(identifiers={(DOMAIN, device.device_id)}) diff --git a/custom_components/fusion_solar/fusion_solar/const.py b/custom_components/fusion_solar/fusion_solar/const.py index af20fbb..09f5958 100644 --- a/custom_components/fusion_solar/fusion_solar/const.py +++ b/custom_components/fusion_solar/fusion_solar/const.py @@ -54,4 +54,5 @@ PARAM_DEVICE_TYPE_ID_GRID_METER = 17 PARAM_DEVICE_TYPE_ID_POWER_SENSOR = 47 PARAM_DEVICE_TYPE_ID_RESIDENTIAL_INVERTER = 38 +PARAM_DEVICE_TYPE_ID_C_I_UTILITY_ESS = 41 PARAM_DEVICE_TYPE_ID_STRING_INVERTER = 1 diff --git a/custom_components/fusion_solar/fusion_solar/openapi/device.py b/custom_components/fusion_solar/fusion_solar/openapi/device.py index 988fc46..6950a9a 100644 --- a/custom_components/fusion_solar/fusion_solar/openapi/device.py +++ b/custom_components/fusion_solar/fusion_solar/openapi/device.py @@ -57,6 +57,8 @@ def device_type(self) -> str: return 'Battery' if self.type_id == 40: return 'Backup box' + if self.type_id == 41: + return 'ESS' if self.type_id == 45: return 'PLC' if self.type_id == 46: diff --git a/custom_components/fusion_solar/sensor.py b/custom_components/fusion_solar/sensor.py index 7c7c9b8..b754df4 100644 --- a/custom_components/fusion_solar/sensor.py +++ b/custom_components/fusion_solar/sensor.py @@ -17,7 +17,7 @@ ATTR_STATION_REAL_KPI_TOTAL_CURRENT_MONTH_ENERGY, ATTR_STATION_REAL_KPI_TOTAL_LIFETIME_ENERGY, \ ATTR_DATA_COLLECT_TIME, ATTR_KPI_YEAR_INVERTER_POWER, ATTR_DEVICE_REAL_KPI_ACTIVE_POWER, \ PARAM_DEVICE_TYPE_ID_STRING_INVERTER, PARAM_DEVICE_TYPE_ID_GRID_METER, PARAM_DEVICE_TYPE_ID_RESIDENTIAL_INVERTER, \ - PARAM_DEVICE_TYPE_ID_POWER_SENSOR, PARAM_DEVICE_TYPE_ID_EMI, PARAM_DEVICE_TYPE_ID_BATTERY + PARAM_DEVICE_TYPE_ID_POWER_SENSOR, PARAM_DEVICE_TYPE_ID_EMI, PARAM_DEVICE_TYPE_ID_BATTERY, PARAM_DEVICE_TYPE_ID_C_I_UTILITY_ESS from .fusion_solar.kiosk.kiosk import FusionSolarKiosk from .fusion_solar.kiosk.kiosk_api import FusionSolarKioskApi, FusionSolarKioskApiError from .fusion_solar.openapi.openapi_api import FusionSolarOpenApi, FusionSolarOpenApiError @@ -556,6 +556,21 @@ async def add_entities_for_stations(hass, async_add_entities, stations, api: Fus {'class': 'FusionSolarRealtimeDeviceDataStateBinarySensor', 'attribute': 'run_state', 'name': 'Status'}, ] + if device.type_id == PARAM_DEVICE_TYPE_ID_C_I_UTILITY_ESS: + entities_to_create = [ + {'class': 'FusionSolarRealtimeDeviceDataPowerInWattSensor', 'attribute': 'ch_discharge_power', + 'name': 'Charge/Discharge power'}, + {'class': 'FusionSolarRealtimeDeviceDataBatterySensor', 'attribute': 'battery_soc', + 'name': 'Battery state of charge (SOC)'}, + {'class': 'FusionSolarRealtimeDeviceDataSensor', 'attribute': 'battery_soh', + 'name': 'Battery state of health (SOH)'}, + {'class': 'FusionSolarRealtimeDeviceDataEnergyTotalIncreasingSensor', 'attribute': 'charge_cap', + 'name': 'Charging capacity'}, + {'class': 'FusionSolarRealtimeDeviceDataEnergyTotalIncreasingSensor', 'attribute': 'discharge_cap', + 'name': 'Discharging capacity'}, + {'class': 'FusionSolarRealtimeDeviceDataStateBinarySensor', 'attribute': 'run_state', 'name': 'Status'}, + ] + if device.type_id == PARAM_DEVICE_TYPE_ID_POWER_SENSOR: entities_to_create = [ {'class': 'FusionSolarRealtimeDeviceDataTranslatedSensor', 'attribute': 'meter_status',