Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
GCONF_SERVICE_DATA_SCHEMA = vol.Schema(
{
vol.Optional("devid"): cv.string,
vol.Required("ocpp_key"): cv.string,
vol.Optional("ocpp_key"): cv.string,
}
)
GDIAG_SERVICE_DATA_SCHEMA = vol.Schema(
Expand Down Expand Up @@ -677,6 +677,6 @@ async def handle_configure(self, call, cp) -> ServiceResponse:
@check_charger_available
async def handle_get_configuration(self, call, cp) -> ServiceResponse:
"""Handle the get configuration service call."""
key = call.data.get("ocpp_key")
key = call.data.get("ocpp_key", "")
value = await cp.get_configuration(key)
return {"value": value}
2 changes: 1 addition & 1 deletion custom_components/ocpp/chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async def data_transfer(self, vendor_id: str, message_id: str = "", data: str =
"""Request vendor specific data transfer from charger."""
pass

async def get_configuration(self, key: str = "") -> str | None:
async def get_configuration(self, key: str = "") -> str | dict | None:
"""Get Configuration of charger for supported keys else return None."""
return None

Expand Down
16 changes: 14 additions & 2 deletions custom_components/ocpp/ocppv16.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,14 +809,26 @@ async def data_transfer(self, vendor_id: str, message_id: str = "", data: str =
)
return False

async def get_configuration(self, key: str = "") -> str:
"""Get Configuration of charger for supported keys else return None."""
async def get_configuration(self, key: str = "") -> str | dict | None:
"""Get Configuration of charger for supported keys.

When key is empty, returns a dict of all configuration key-value pairs.
When key is specified, returns the value as a string.
"""
if key == "":
req = call.GetConfiguration()
else:
req = call.GetConfiguration(key=[key])
resp = await self.call(req)
if resp.configuration_key:
if key == "":
result = {}
for entry in resp.configuration_key:
entry_key = entry.get("key", "")
entry_value = entry.get(om.value.value, "")
result[entry_key] = entry_value
_LOGGER.debug("Get Configuration returned %d keys", len(result))
return result
value = resp.configuration_key[0][om.value.value]
_LOGGER.debug("Get Configuration for %s: %s", key, value)
self._metrics[0][cdet.config_response.value].value = datetime.now(tz=UTC)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ocpp/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ get_configuration:
example: charger
ocpp_key:
name: Configuration key name
description: v1.6- Key name v2.0.1- Component name/Key name
required: true
description: v1.6- Key name v2.0.1- Component name/Key name. Leave empty to retrieve all configuration keys (v1.6 only).
required: false
advanced: true
example: "WebSocketPingInterval"

Expand Down
4 changes: 2 additions & 2 deletions tests/test_additional_charge_point_v16.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,12 @@ async def fake_call(req):
req, "key", None
)
return SimpleNamespace(
configuration_key=[{"value": "42"}], unknown_key=None
configuration_key=[{"key": "HeartbeatInterval", "value": "300"}, {"key": "MeterValueSampleInterval", "value": "60"}], unknown_key=None
)

monkeypatch.setattr(srv, "call", fake_call, raising=True)
val = await srv.get_configuration("")
assert val == "42"
assert val == {"HeartbeatInterval": "300", "MeterValueSampleInterval": "60"}
finally:
task.cancel()
with contextlib.suppress(asyncio.CancelledError):
Expand Down