Skip to content

Commit ea5cba0

Browse files
authored
add security event handling (#634)
1 parent 62e4d6a commit ea5cba0

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

custom_components/ocpp/api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,20 @@ def on_diagnostics_status(self, status, **kwargs):
12191219
)
12201220
return call_result.DiagnosticsStatusNotificationPayload()
12211221

1222+
@on(Action.SecurityEventNotification)
1223+
def on_security_event(self, type, timestamp, **kwargs):
1224+
"""Handle security event notification."""
1225+
_LOGGER.info(
1226+
"Security event notification received: %s at %s [techinfo: %s]",
1227+
type,
1228+
timestamp,
1229+
kwargs.get(om.tech_info.name, "none"),
1230+
)
1231+
self.hass.async_create_task(
1232+
self.notify_ha(f"Security event notification received: {type}")
1233+
)
1234+
return call_result.SecurityEventNotificationPayload()
1235+
12221236
def get_authorization_status(self, id_tag):
12231237
"""Get the authorization status for an id_tag."""
12241238
# get the domain wide configuration

custom_components/ocpp/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class OcppMisc(str, Enum):
106106
feature_profile_reservation = "Reservation"
107107
feature_profile_remote = "RemoteTrigger"
108108
feature_profile_auth = "LocalAuthListManagement"
109+
tech_info = "techInfo"
109110

110111
# for use with Smart Charging
111112
current = "Current"

tests/test_charge_point.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ async def test_services(hass, socket_enabled):
242242
cp.send_authorize(),
243243
cp.send_heartbeat(),
244244
cp.send_status_notification(),
245+
cp.send_security_event(),
245246
cp.send_firmware_status(),
246247
cp.send_data_transfer(),
247248
cp.send_start_transaction(),
@@ -877,3 +878,12 @@ async def send_stop_transaction(self, delay: int = 0):
877878
)
878879
resp = await self.call(request)
879880
assert resp.id_tag_info["status"] == AuthorizationStatus.accepted.value
881+
882+
async def send_security_event(self):
883+
"""Send a security event notification."""
884+
request = call.SecurityEventNotificationPayload(
885+
type="SettingSystemTime",
886+
timestamp="2022-09-29T20:58:29Z",
887+
tech_info="BootNotification",
888+
)
889+
await self.call(request)

0 commit comments

Comments
 (0)