diff --git a/homeassistant/components/zha/logbook.py b/homeassistant/components/zha/logbook.py index e2d238ddbe8..8140a5244f1 100644 --- a/homeassistant/components/zha/logbook.py +++ b/homeassistant/components/zha/logbook.py @@ -62,14 +62,18 @@ def async_describe_events( break if event_type is None: - event_type = event_data[ATTR_COMMAND] + event_type = event_data.get(ATTR_COMMAND, ZHA_EVENT) if event_subtype is not None and event_subtype != event_type: event_type = f"{event_type} - {event_subtype}" - event_type = event_type.replace("_", " ").title() + if event_type is not None: + event_type = event_type.replace("_", " ").title() + if "event" in event_type.lower(): + message = f"{event_type} was fired" + else: + message = f"{event_type} event was fired" - message = f"{event_type} event was fired" if event_data["params"]: message = f"{message} with parameters: {event_data['params']}" diff --git a/tests/components/zha/test_logbook.py b/tests/components/zha/test_logbook.py index 33b758fd0a7..6c28284b1e6 100644 --- a/tests/components/zha/test_logbook.py +++ b/tests/components/zha/test_logbook.py @@ -172,6 +172,19 @@ async def test_zha_logbook_event_device_no_triggers(hass, mock_devices): }, }, ), + MockRow( + ZHA_EVENT, + { + CONF_DEVICE_ID: reg_device.id, + "device_ieee": str(ieee_address), + CONF_UNIQUE_ID: f"{str(ieee_address)}:1:0x0006", + "endpoint_id": 1, + "cluster_id": 6, + "params": { + "test": "test", + }, + }, + ), ], ) @@ -182,6 +195,12 @@ async def test_zha_logbook_event_device_no_triggers(hass, mock_devices): == "Shake event was fired with parameters: {'test': 'test'}" ) + assert events[1]["name"] == "FakeManufacturer FakeModel" + assert events[1]["domain"] == "zha" + assert ( + events[1]["message"] == "Zha Event was fired with parameters: {'test': 'test'}" + ) + async def test_zha_logbook_event_device_no_device(hass, mock_devices): """Test zha logbook events without device and without triggers."""