diff --git a/homeassistant/components/zha/logbook.py b/homeassistant/components/zha/logbook.py index 8140a5244f1..90d433be210 100644 --- a/homeassistant/components/zha/logbook.py +++ b/homeassistant/components/zha/logbook.py @@ -74,8 +74,8 @@ def async_describe_events( else: message = f"{event_type} event was fired" - if event_data["params"]: - message = f"{message} with parameters: {event_data['params']}" + if params := event_data.get("params"): + message = f"{message} with parameters: {params}" return { LOGBOOK_ENTRY_NAME: device_name, diff --git a/tests/components/zha/test_logbook.py b/tests/components/zha/test_logbook.py index 6c28284b1e6..373a48c2d47 100644 --- a/tests/components/zha/test_logbook.py +++ b/tests/components/zha/test_logbook.py @@ -185,6 +185,27 @@ 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": {}, + }, + ), + 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, + }, + ), ], ) @@ -201,6 +222,14 @@ async def test_zha_logbook_event_device_no_triggers(hass, mock_devices): events[1]["message"] == "Zha Event was fired with parameters: {'test': 'test'}" ) + assert events[2]["name"] == "FakeManufacturer FakeModel" + assert events[2]["domain"] == "zha" + assert events[2]["message"] == "Zha Event was fired" + + assert events[3]["name"] == "FakeManufacturer FakeModel" + assert events[3]["domain"] == "zha" + assert events[3]["message"] == "Zha Event was fired" + async def test_zha_logbook_event_device_no_device(hass, mock_devices): """Test zha logbook events without device and without triggers."""