Fix ZHA events for logbook (#74245)

This commit is contained in:
David F. Mulcahey 2022-06-30 13:03:39 -04:00 committed by GitHub
parent 5fa3b90b2c
commit 8bcccb17f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -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']}"

View File

@ -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."""