Skip to content

Commit e8a203c

Browse files
committed
fix: register campass_access events with HA logbook
Events were being fired via hass.bus.async_fire() but weren't showing up in the Logbook because they weren't registered with the logbook component. Added logbook.py descriptor and logbook dependency to manifest.json.
1 parent 72d7574 commit e8a203c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Logbook support for CamPass."""
2+
from __future__ import annotations
3+
4+
from homeassistant.components.logbook import LOGBOOK_ENTRY_MESSAGE, LOGBOOK_ENTRY_NAME
5+
from homeassistant.core import Event, HomeAssistant, callback
6+
7+
EVENT_CAMPASS_ACCESS = "campass_access"
8+
9+
MESSAGES = {
10+
"auth_success": "authenticated to '{share}' share from {ip}",
11+
"auth_failure": "failed authentication to '{share}' share from {ip}",
12+
"camera_view": "viewed camera {camera_id} on '{share}' share from {ip}",
13+
}
14+
15+
16+
@callback
17+
def async_describe_events(hass: HomeAssistant, async_describe_event):
18+
"""Describe CamPass logbook events."""
19+
20+
@callback
21+
def async_describe_campass_event(event: Event):
22+
"""Describe a CamPass access event."""
23+
data = event.data
24+
event_type = data.get("type", "unknown")
25+
share = data.get("share", "unknown")
26+
ip = data.get("ip", "unknown")
27+
camera_id = data.get("camera_id", "")
28+
29+
template = MESSAGES.get(event_type, "performed '{type}' on share '{share}'")
30+
message = template.format(
31+
share=share,
32+
ip=ip,
33+
camera_id=camera_id,
34+
type=event_type,
35+
)
36+
37+
return {
38+
LOGBOOK_ENTRY_NAME: "CamPass",
39+
LOGBOOK_ENTRY_MESSAGE: message,
40+
}
41+
42+
async_describe_event(EVENT_CAMPASS_ACCESS, async_describe_campass_event)

custom_components/campass/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"name": "CamPass",
44
"codeowners": ["@evandcoleman"],
55
"config_flow": true,
6-
"dependencies": ["camera", "stream"],
6+
"dependencies": ["camera", "logbook", "stream"],
77
"documentation": "https://github.com/evandcoleman/campass",
88
"integration_type": "service",
99
"iot_class": "local_push",
1010
"requirements": ["PyJWT>=2.0.0"],
11-
"version": "0.4.0"
11+
"version": "0.4.1"
1212
}

0 commit comments

Comments
 (0)