Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/unit_tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ async def test_install_requests_coordinator_refresh(self):

coordinator.async_request_refresh.assert_awaited_once()

async def test_install_keeps_in_progress_true_while_refresh_runs(self):
"""in_progress should remain True until coordinator refresh completes."""
entity, coordinator = _make_update_entity()
coordinator.create = AsyncMock()

async def _refresh_side_effect():
self.assertTrue(entity._attr_in_progress)

coordinator.async_request_refresh = AsyncMock(side_effect=_refresh_side_effect)

await entity.async_install(None, False)

coordinator.async_request_refresh.assert_awaited_once()
self.assertFalse(entity._attr_in_progress)

async def test_install_raises_when_coordinator_create_fails(self):
"""async_install should propagate ServiceValidationError from coordinator.create()."""
entity, coordinator = _make_update_entity()
Expand Down
8 changes: 5 additions & 3 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ async def async_install(
try:
await self.coordinator.create()
finally:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Is an empty finally block in python valid and reasonable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes—try ... finally without an except is valid Python, and it’s commonly used for guaranteed cleanup. In this case the outer finally is not empty; it ensures we always run the post-install refresh/cleanup path even if create() raises.

self._attr_in_progress = False
self.async_write_ha_state()
# Refresh coordinator so the new container state is reflected quickly.
await self.coordinator.async_request_refresh()
try:
await self.coordinator.async_request_refresh()
finally:
self._attr_in_progress = False
self.async_write_ha_state()