1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Use python defaults for comparing State, LazyState, and Event objects (#86856)

* Speed up comparing State and Event objects

Use default python implementation for State and Event __hash__ and __eq__

The default implementation compared based on the id() of the object
which is effectively what we want here anyways. These overrides are
left over from the days when these used to be attrs objects

By avoiding implementing these ourselves all of the equality checks
can happen in native code

* tweak

* adjust tests

* write out some more

* fix test to not compare objects

* more test fixes

* more test fixes

* correct stats tests

* fix more tests

* fix more tests

* update sensor recorder tests
This commit is contained in:
J. Nick Koston
2023-01-29 08:31:43 -10:00
committed by GitHub
parent 80ffac48a3
commit c612a92cfb
17 changed files with 389 additions and 174 deletions

View File

@@ -331,7 +331,7 @@ def test_event_eq():
ha.Event("some_type", data, time_fired=now, context=context) for _ in range(2)
)
assert event1 == event2
assert event1.as_dict() == event2.as_dict()
def test_event_repr():
@@ -685,7 +685,7 @@ def test_state_name_if_friendly_name_attr():
def test_state_dict_conversion():
"""Test conversion of dict."""
state = ha.State("domain.hello", "world", {"some": "attr"})
assert state == ha.State.from_dict(state.as_dict())
assert state.as_dict() == ha.State.from_dict(state.as_dict()).as_dict()
def test_state_dict_conversion_with_wrong_data():