Skip to content

Commit 2ba4b55

Browse files
authored
Improve measurand logic (#1217)
* improve measurand logic * fix linting
1 parent e339ebb commit 2ba4b55

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

custom_components/ocpp/api.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,33 +464,36 @@ async def handle_set_charge_rate(call):
464464
all_measurands = self.entry.data.get(
465465
CONF_MONITORED_VARIABLES, DEFAULT_MEASURAND
466466
)
467+
key = ckey.meter_values_sampled_data.value
468+
chgr_measurands = await self.get_configuration(key)
467469

468470
accepted_measurands = []
469-
key = ckey.meter_values_sampled_data.value
471+
cfg_ok = [
472+
ConfigurationStatus.accepted,
473+
ConfigurationStatus.reboot_required,
474+
]
470475

471476
for measurand in all_measurands.split(","):
472-
_LOGGER.debug(f"'{self.id}' trying measurand '{measurand}'")
477+
_LOGGER.debug(f"'{self.id}' trying measurand: '{measurand}'")
473478
req = call.ChangeConfiguration(key=key, value=measurand)
474479
resp = await self.call(req)
475-
if resp.status == ConfigurationStatus.accepted:
476-
_LOGGER.debug(f"'{self.id}' adding measurand '{measurand}'")
480+
if resp.status in cfg_ok:
481+
_LOGGER.debug(f"'{self.id}' adding measurand: '{measurand}'")
477482
accepted_measurands.append(measurand)
478483

479484
accepted_measurands = ",".join(accepted_measurands)
480485

481486
if len(accepted_measurands) > 0:
482-
_LOGGER.debug(f"'{self.id}' allowed measurands '{accepted_measurands}'")
487+
_LOGGER.debug(
488+
f"'{self.id}' allowed measurands: '{accepted_measurands}'"
489+
)
483490
await self.configure(
484491
ckey.meter_values_sampled_data.value,
485492
accepted_measurands,
486493
)
487494
else:
488-
_LOGGER.debug(f"'{self.id}' measurands not configurable by OCPP")
489-
resp = await self.get_configuration(
490-
ckey.meter_values_sampled_data.value
491-
)
492-
accepted_measurands = resp
493-
_LOGGER.debug(f"'{self.id}' allowed measurands '{accepted_measurands}'")
495+
_LOGGER.debug(f"'{self.id}' measurands not configurable by integration")
496+
_LOGGER.debug(f"'{self.id}' allowed measurands: '{chgr_measurands}'")
494497

495498
updated_entry = {**self.entry.data}
496499
updated_entry[CONF_MONITORED_VARIABLES] = accepted_measurands

0 commit comments

Comments
 (0)