From 3f25f6cea3868cae37eba05fdccaf70b80f9205d Mon Sep 17 00:00:00 2001 From: Tuen Lee Date: Wed, 27 Sep 2023 22:36:07 +0200 Subject: [PATCH] #69 meter reading value for socket 2 --- custom_components/alfen_wallbox/alfen.py | 3 ++- custom_components/alfen_wallbox/const.py | 3 +++ custom_components/alfen_wallbox/sensor.py | 30 +++++++++++++++++++---- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/custom_components/alfen_wallbox/alfen.py b/custom_components/alfen_wallbox/alfen.py index eda3a9c..bbad4f7 100644 --- a/custom_components/alfen_wallbox/alfen.py +++ b/custom_components/alfen_wallbox/alfen.py @@ -16,6 +16,7 @@ CAT_GENERIC, CAT_GENERIC2, CAT_METER1, + CAT_METER2, CAT_METER4, CAT_OCPP, CAT_STATES, @@ -239,7 +240,7 @@ async def _get_value(self, api_param): async def _get_all_properties_value(self): _LOGGER.debug(f"Get properties") properties = [] - for cat in (CAT_GENERIC, CAT_GENERIC2, CAT_METER1, CAT_STATES, CAT_TEMP, CAT_OCPP, CAT_METER4, CAT_MBUS_TCP, CAT_COMM, CAT_DISPLAY): + for cat in (CAT_GENERIC, CAT_GENERIC2, CAT_METER1, CAT_STATES, CAT_TEMP, CAT_OCPP, CAT_METER4, CAT_MBUS_TCP, CAT_COMM, CAT_DISPLAY, CAT_METER2): nextRequest = True offset = 0 while (nextRequest): diff --git a/custom_components/alfen_wallbox/const.py b/custom_components/alfen_wallbox/const.py index 0e11303..89d37c3 100644 --- a/custom_components/alfen_wallbox/const.py +++ b/custom_components/alfen_wallbox/const.py @@ -34,6 +34,9 @@ CAT_MBUS_TCP = "MbusTCP" CAT_COMM = "comm" CAT_DISPLAY = "display" +#CAT_LEDS = "leds" +#CAT_ACCELERO = "accelero" +CAT_METER2 = "meter2" COMMAND_REBOOT = "reboot" diff --git a/custom_components/alfen_wallbox/sensor.py b/custom_components/alfen_wallbox/sensor.py index baa0c50..8421c9f 100644 --- a/custom_components/alfen_wallbox/sensor.py +++ b/custom_components/alfen_wallbox/sensor.py @@ -430,8 +430,8 @@ class AlfenSensorDescription( device_class=SensorDeviceClass.CURRENT, ), AlfenSensorDescription( - key="active_power_total", - name="Active Power Total", + key="active_power_total_socket_1", + name="Active Power Total Socket 1", icon="mdi:circle-slice-3", api_param="2221_16", unit=UnitOfPower.WATT, @@ -440,8 +440,8 @@ class AlfenSensorDescription( device_class=SensorDeviceClass.POWER, ), AlfenSensorDescription( - key="meter_reading", - name="Meter Reading", + key="meter_reading_socket_1", + name="Meter Reading Socket 1", icon="mdi:counter", api_param="2221_22", unit=UnitOfEnergy.KILO_WATT_HOUR, @@ -1149,6 +1149,26 @@ class AlfenSensorDescription( api_param="3191_2", round_digits=None, ), + AlfenSensorDescription( + key="meter_reading_socket_2", + name="Meter Reading Socket 2", + icon="mdi:counter", + api_param="3221_22", + unit=UnitOfEnergy.KILO_WATT_HOUR, + round_digits=None, + state_class=SensorStateClass.TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY + ), + AlfenSensorDescription( + key="active_power_total_socket_2", + name="Active Power Total Socket 2", + icon="mdi:circle-slice-3", + api_param="3221_16", + unit=UnitOfPower.WATT, + round_digits=2, + state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.POWER, + ), ) @@ -1351,7 +1371,7 @@ def state(self) -> StateType: return STATUS_DICT.get(prop[VALUE], 'Unknown') # meter_reading from w to kWh - if self.entity_description.api_param == "2221_22": + if self.entity_description.api_param == "2221_22" or self.entity_description.api_param == "3221_22": return round((prop[VALUE] / 1000), 2) # Car PWM Duty cycle %