From a2ee5eb82e485f93f4d328de07dfbf07b36dc047 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Mon, 24 Jun 2024 20:20:56 +1200 Subject: [PATCH 1/2] improve measurand logic --- custom_components/ocpp/api.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/custom_components/ocpp/api.py b/custom_components/ocpp/api.py index b7fbe8bb..b711c3b4 100644 --- a/custom_components/ocpp/api.py +++ b/custom_components/ocpp/api.py @@ -464,33 +464,34 @@ async def handle_set_charge_rate(call): all_measurands = self.entry.data.get( CONF_MONITORED_VARIABLES, DEFAULT_MEASURAND ) + key = ckey.meter_values_sampled_data.value + chgr_measurands = await self.get_configuration(key) accepted_measurands = [] - key = ckey.meter_values_sampled_data.value + cfg_ok = [ + ConfigurationStatus.accepted, + ConfigurationStatus.reboot_required, + ] for measurand in all_measurands.split(","): - _LOGGER.debug(f"'{self.id}' trying measurand '{measurand}'") + _LOGGER.debug(f"'{self.id}' trying measurand: '{measurand}'") req = call.ChangeConfiguration(key=key, value=measurand) resp = await self.call(req) - if resp.status == ConfigurationStatus.accepted: - _LOGGER.debug(f"'{self.id}' adding measurand '{measurand}'") + if resp.status in cfg_ok: + _LOGGER.debug(f"'{self.id}' adding measurand: '{measurand}'") accepted_measurands.append(measurand) accepted_measurands = ",".join(accepted_measurands) if len(accepted_measurands) > 0: - _LOGGER.debug(f"'{self.id}' allowed measurands '{accepted_measurands}'") + _LOGGER.debug(f"'{self.id}' allowed measurands: '{accepted_measurands}'") await self.configure( ckey.meter_values_sampled_data.value, accepted_measurands, ) else: - _LOGGER.debug(f"'{self.id}' measurands not configurable by OCPP") - resp = await self.get_configuration( - ckey.meter_values_sampled_data.value - ) - accepted_measurands = resp - _LOGGER.debug(f"'{self.id}' allowed measurands '{accepted_measurands}'") + _LOGGER.debug(f"'{self.id}' measurands not configurable by integration") + _LOGGER.debug(f"'{self.id}' allowed measurands: '{chgr_measurands}'") updated_entry = {**self.entry.data} updated_entry[CONF_MONITORED_VARIABLES] = accepted_measurands From 87bb53b6e21adc894a24cf9caf895b5365db3363 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Mon, 24 Jun 2024 20:31:32 +1200 Subject: [PATCH 2/2] fix linting --- custom_components/ocpp/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/ocpp/api.py b/custom_components/ocpp/api.py index b711c3b4..b6177d63 100644 --- a/custom_components/ocpp/api.py +++ b/custom_components/ocpp/api.py @@ -484,7 +484,9 @@ async def handle_set_charge_rate(call): accepted_measurands = ",".join(accepted_measurands) if len(accepted_measurands) > 0: - _LOGGER.debug(f"'{self.id}' allowed measurands: '{accepted_measurands}'") + _LOGGER.debug( + f"'{self.id}' allowed measurands: '{accepted_measurands}'" + ) await self.configure( ckey.meter_values_sampled_data.value, accepted_measurands,