Skip to content

Commit

Permalink
Adjust tests to ignore new update entity attributes (#4166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Oct 28, 2024
1 parent 2d5c1a5 commit 91cf950
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _entity_state(entity: er.RegistryEntry) -> dict[str, Any]:
state = hacs.hass.states.get(entity.entity_id)
return {
"state": state.state if state else None,
"attributes": state.attributes if state else None,
"attributes": recursive_remove_key(state.attributes, ("display_precision", "update_percentage")) if state else None,
}

snapshot.assert_match(
Expand Down
12 changes: 8 additions & 4 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ async def test_switch_entity_state(
MockedResponse(content=data),
)

er.async_update_entity(er.async_get_entity_id("switch", DOMAIN, repo.data.id), disabled_by=None)
er.async_update_entity(er.async_get_entity_id(
"switch", DOMAIN, repo.data.id), disabled_by=None)
await hass.config_entries.async_reload(hacs.configuration.config_entry.entry_id)
await hass.async_block_till_done()

Expand All @@ -77,13 +78,15 @@ async def test_switch_entity_state(

states[platform]["initial"] = recursive_remove_key(
hass.states.get(entity_id).as_dict(),
("id", "last_changed", "last_reported", "last_updated"),
("id", "last_changed", "last_reported", "last_updated",
"display_precision", "update_percentage"),
)

await hass.services.async_call(
domain="switch",
service="turn_on",
service_data={"entity_id": er.async_get_entity_id("switch", DOMAIN, repo.data.id)},
service_data={"entity_id": er.async_get_entity_id(
"switch", DOMAIN, repo.data.id)},
blocking=True,
)

Expand All @@ -92,7 +95,8 @@ async def test_switch_entity_state(
assert entity_id is not None
states[platform]["updated"] = recursive_remove_key(
hass.states.get(entity_id).as_dict(),
("id", "last_changed", "last_reported", "last_updated"),
("id", "last_changed", "last_reported", "last_updated",
"display_precision", "update_percentage"),
)

snapshots.assert_match(
Expand Down
12 changes: 8 additions & 4 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ async def test_update_entity_state(
# Get initial state
state = hass.states.get(entity_id)
initial_state = recursive_remove_key(
state.as_dict(), ("id", "last_changed", "last_reported", "last_updated"),
state.as_dict(), ("id", "last_changed", "last_reported", "last_updated",
"display_precision", "update_percentage"),
)

# Bump version
fixture_file = f"fixtures/proxy/data-v2.hacs.xyz/{category_test_data['category']}/data.json"
fixture_file = f"fixtures/proxy/data-v2.hacs.xyz/{
category_test_data['category']}/data.json"
fp = os.path.join(
os.path.dirname(__file__),
fixture_file,
Expand All @@ -83,10 +85,12 @@ async def test_update_entity_state(
# Get updated state
state = hass.states.get(entity_id)
updated_state = recursive_remove_key(
state.as_dict(), ("id", "last_changed", "last_reported", "last_updated"),
state.as_dict(), ("id", "last_changed", "last_reported", "last_updated",
"display_precision", "update_percentage"),
)

snapshots.assert_match(
safe_json_dumps({"initial_state": initial_state, "updated_state": updated_state}),
safe_json_dumps({"initial_state": initial_state,
"updated_state": updated_state}),
f"{category_test_data['repository']}/test_update_entity_state.json",
)

0 comments on commit 91cf950

Please sign in to comment.