Skip to content

Commit a234f0c

Browse files
authored
New metrics (#159)
* Add metrics to support automations, templating of data transfer and configuration responses * change to using extra_attr because of size
1 parent 8ceb34f commit a234f0c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

custom_components/ocpp/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ async def data_transfer(self, vendor_id: str, message_id: str = "", data: str =
632632
data,
633633
resp.data,
634634
)
635+
self._metrics[cdet.data_response.value].value = datetime.now(
636+
tz=timezone.utc
637+
).isoformat()
638+
self._metrics[cdet.data_response.value].extra_attr = {message_id: resp.data}
635639
return True
636640
else:
637641
_LOGGER.warning("Failed with response: %s", resp.status)
@@ -647,6 +651,10 @@ async def get_configuration(self, key: str = ""):
647651
if resp.configuration_key is not None:
648652
value = resp.configuration_key[0][om.value.value]
649653
_LOGGER.debug("Get Configuration for %s: %s", key, value)
654+
self._metrics[cdet.config_response.value].value = datetime.now(
655+
tz=timezone.utc
656+
).isoformat()
657+
self._metrics[cdet.config_response.value].extra_attr = {key: value}
650658
return value
651659
if resp.unknown_key is not None:
652660
_LOGGER.warning("Get Configuration returned unknown key for: %s", key)

custom_components/ocpp/enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class HAChargerDetails(str, Enum):
4242
firmware_version = "FW.Version"
4343
features = "Features"
4444
connectors = "Connectors"
45+
data_response = "Data.Response"
46+
config_response = "Config.Response"
4547

4648

4749
class HAChargerSession(str, Enum):

0 commit comments

Comments
 (0)