Skip to content

Commit

Permalink
add try except for getting measurands (#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
drc38 authored Aug 31, 2024
1 parent 14dec53 commit 73ac441
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
13 changes: 8 additions & 5 deletions custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,13 @@ async def handle_set_charge_rate(call):
CONF_MONITORED_VARIABLES, DEFAULT_MEASURAND
)
key = ckey.meter_values_sampled_data.value
chgr_measurands = await self.get_configuration(key)
try:
chgr_measurands = await self.get_configuration(key)
except Exception:
_LOGGER.debug(
f"'{self.id}' had error while returning measurands, ignoring"
)
chgr_measurands = all_measurands

accepted_measurands = []
cfg_ok = [
Expand All @@ -487,10 +493,7 @@ async def handle_set_charge_rate(call):
_LOGGER.debug(
f"'{self.id}' allowed measurands: '{accepted_measurands}'"
)
await self.configure(
ckey.meter_values_sampled_data.value,
accepted_measurands,
)
await self.configure(key, accepted_measurands)
else:
_LOGGER.debug(f"'{self.id}' measurands not configurable by integration")
_LOGGER.debug(f"'{self.id}' allowed measurands: '{chgr_measurands}'")
Expand Down
27 changes: 13 additions & 14 deletions tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,7 @@ def on_get_configuration(self, key, **kwargs):
)
else:
# use to test TypeError handling
return call_result.GetConfiguration(
unknown_key=["SupportedFeatureProfiles"]
)
return call_result.GetConfiguration(unknown_key=[key[0]])
if key[0] == ConfigurationKey.heartbeat_interval.value:
return call_result.GetConfiguration(
configuration_key=[{"key": key[0], "readonly": False, "value": "300"}]
Expand All @@ -559,19 +557,20 @@ def on_get_configuration(self, key, **kwargs):
]
)
else:
return call_result.GetConfiguration(unknown_key=[key[0]])
if key[0] == ConfigurationKey.meter_values_sampled_data.value:
if self.accept is True:
return call_result.GetConfiguration(
unknown_key=["WebSocketPingInterval"]
configuration_key=[
{
"key": key[0],
"readonly": False,
"value": "Energy.Active.Import.Register",
}
]
)
if key[0] == ConfigurationKey.meter_values_sampled_data.value:
return call_result.GetConfiguration(
configuration_key=[
{
"key": key[0],
"readonly": False,
"value": "Energy.Active.Import.Register",
}
]
)
else:
raise Exception
if key[0] == ConfigurationKey.meter_value_sample_interval.value:
if self.accept is True:
return call_result.GetConfiguration(
Expand Down

0 comments on commit 73ac441

Please sign in to comment.