From a52a80f8062272146f78083fc6d18a95f538e854 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:25:22 +0200 Subject: [PATCH] Always include old_state in EventStateChangedData [tests] (#115098) --- tests/common.py | 12 ++++++------ tests/components/mqtt_eventstream/test_init.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/common.py b/tests/common.py index 88450d34564..38af58642c9 100644 --- a/tests/common.py +++ b/tests/common.py @@ -589,12 +589,12 @@ def json_round_trip(obj: Any) -> Any: def mock_state_change_event( hass: HomeAssistant, new_state: State, old_state: State | None = None ) -> None: - """Mock state change envent.""" - event_data = {"entity_id": new_state.entity_id, "new_state": new_state} - - if old_state: - event_data["old_state"] = old_state - + """Mock state change event.""" + event_data = { + "entity_id": new_state.entity_id, + "new_state": new_state, + "old_state": old_state, + } hass.bus.fire(EVENT_STATE_CHANGED, event_data, context=new_state.context) diff --git a/tests/components/mqtt_eventstream/test_init.py b/tests/components/mqtt_eventstream/test_init.py index 24b4a83c425..90034382fc8 100644 --- a/tests/components/mqtt_eventstream/test_init.py +++ b/tests/components/mqtt_eventstream/test_init.py @@ -111,7 +111,7 @@ async def test_state_changed_event_sends_message( "last_updated": now.isoformat(), "state": "on", } - event["event_data"] = {"new_state": new_state, "entity_id": e_id} + event["event_data"] = {"new_state": new_state, "entity_id": e_id, "old_state": None} # Verify that the message received was that expected result = json.loads(msg)