Always include old_state in EventStateChangedData [tests] (#115098)

This commit is contained in:
Marc Mueller 2024-04-08 20:25:22 +02:00 committed by GitHub
parent 017b2fe685
commit a52a80f806
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -589,12 +589,12 @@ def json_round_trip(obj: Any) -> Any:
def mock_state_change_event( def mock_state_change_event(
hass: HomeAssistant, new_state: State, old_state: State | None = None hass: HomeAssistant, new_state: State, old_state: State | None = None
) -> None: ) -> None:
"""Mock state change envent.""" """Mock state change event."""
event_data = {"entity_id": new_state.entity_id, "new_state": new_state} event_data = {
"entity_id": new_state.entity_id,
if old_state: "new_state": new_state,
event_data["old_state"] = old_state "old_state": old_state,
}
hass.bus.fire(EVENT_STATE_CHANGED, event_data, context=new_state.context) hass.bus.fire(EVENT_STATE_CHANGED, event_data, context=new_state.context)

View file

@ -111,7 +111,7 @@ async def test_state_changed_event_sends_message(
"last_updated": now.isoformat(), "last_updated": now.isoformat(),
"state": "on", "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 # Verify that the message received was that expected
result = json.loads(msg) result = json.loads(msg)