diff --git a/homeassistant/core.py b/homeassistant/core.py index 573ddde05ba..72e33a1d786 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1259,6 +1259,14 @@ class Context: """Compare contexts.""" return isinstance(other, Context) and self.id == other.id + def __copy__(self) -> Context: + """Create a shallow copy of this context.""" + return Context(user_id=self.user_id, parent_id=self.parent_id, id=self.id) + + def __deepcopy__(self, memo: dict[int, Any]) -> Context: + """Create a deep copy of this context.""" + return Context(user_id=self.user_id, parent_id=self.parent_id, id=self.id) + @cached_property def _as_dict(self) -> dict[str, str | None]: """Return a dictionary representation of the context. diff --git a/tests/helpers/test_llm.py b/tests/helpers/test_llm.py index e3308b89061..43eef04734c 100644 --- a/tests/helpers/test_llm.py +++ b/tests/helpers/test_llm.py @@ -90,6 +90,7 @@ async def test_assist_api(hass: HomeAssistant) -> None: assert str(tool) == "" test_context = Context() + assert test_context.json_fragment # To reproduce an error case in tracing intent_response = intent.IntentResponse("*") intent_response.matched_states = [State("light.matched", "on")] intent_response.unmatched_states = [State("light.unmatched", "on")]