mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Reload Immich integration when the server version changes (#184978)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3a0121eabe
commit
ae86a06f8e
@@ -126,6 +126,18 @@ class ImmichDataUpdateCoordinator(DataUpdateCoordinator[ImmichData]):
|
||||
translation_placeholders={"error": str(err)},
|
||||
) from err
|
||||
|
||||
if (
|
||||
self.data is not None
|
||||
and self.data.server_about.version != server_about.version
|
||||
):
|
||||
# The API client adapts to the server version during setup
|
||||
_LOGGER.info(
|
||||
"Immich server version changed from %s to %s, reloading integration",
|
||||
self.data.server_about.version,
|
||||
server_about.version,
|
||||
)
|
||||
self.hass.config_entries.async_schedule_reload(self.config_entry.entry_id)
|
||||
|
||||
return ImmichData(
|
||||
server_about, server_storage, server_usage, server_version_check
|
||||
)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Test the Immich integration setup."""
|
||||
|
||||
from dataclasses import replace
|
||||
from datetime import timedelta
|
||||
from unittest.mock import Mock
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("new_version", "setup_calls"),
|
||||
[
|
||||
pytest.param("v1.134.0", 1, id="unchanged"),
|
||||
pytest.param("v3.1.0", 2, id="changed"),
|
||||
],
|
||||
)
|
||||
async def test_reload_on_server_version_change(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_immich: Mock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
new_version: str,
|
||||
setup_calls: int,
|
||||
) -> None:
|
||||
"""Test the integration reloads only when the server version changes."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
assert mock_immich.async_setup.call_count == 1
|
||||
|
||||
server_about = mock_immich.server.async_get_about_info.return_value
|
||||
mock_immich.server.async_get_about_info.return_value = replace(
|
||||
server_about, version=new_version
|
||||
)
|
||||
|
||||
freezer.tick(timedelta(seconds=60))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
assert mock_immich.async_setup.call_count == setup_calls
|
||||
Reference in New Issue
Block a user