diff --git a/homeassistant/components/plugwise/const.py b/homeassistant/components/plugwise/const.py index e2f4ac17099..9b9e426651b 100644 --- a/homeassistant/components/plugwise/const.py +++ b/homeassistant/components/plugwise/const.py @@ -71,12 +71,9 @@ type SelectOptionsType = Literal[ DEFAULT_MAX_TEMP: Final = 30 DEFAULT_MIN_TEMP: Final = 4 DEFAULT_PORT: Final = 80 -DEFAULT_SCAN_INTERVAL: Final[dict[str, timedelta]] = { - "power": timedelta(seconds=10), - "stretch": timedelta(seconds=60), - "thermostat": timedelta(seconds=60), -} +DEFAULT_UPDATE_INTERVAL = timedelta(seconds=60) DEFAULT_USERNAME: Final = "smile" +P1_UPDATE_INTERVAL = timedelta(seconds=10) MASTER_THERMOSTATS: Final[list[str]] = [ "thermostat", diff --git a/homeassistant/components/plugwise/coordinator.py b/homeassistant/components/plugwise/coordinator.py index 7cbf5a22a4f..566b6f75840 100644 --- a/homeassistant/components/plugwise/coordinator.py +++ b/homeassistant/components/plugwise/coordinator.py @@ -1,7 +1,5 @@ """DataUpdateCoordinator for Plugwise.""" -from datetime import timedelta - from packaging.version import Version from plugwise import GwEntityData, Smile from plugwise.exceptions import ( @@ -23,7 +21,14 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from .const import DEFAULT_PORT, DEFAULT_USERNAME, DOMAIN, LOGGER +from .const import ( + DEFAULT_PORT, + DEFAULT_UPDATE_INTERVAL, + DEFAULT_USERNAME, + DOMAIN, + LOGGER, + P1_UPDATE_INTERVAL, +) type PlugwiseConfigEntry = ConfigEntry[PlugwiseDataUpdateCoordinator] @@ -45,7 +50,7 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData LOGGER, config_entry=config_entry, name=DOMAIN, - update_interval=timedelta(seconds=60), + update_interval=DEFAULT_UPDATE_INTERVAL, # Don't refresh immediately, give the device time to process # the change in state before we query it. request_refresh_debouncer=Debouncer( @@ -74,6 +79,8 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData """ version = await self.api.connect() self._connected = isinstance(version, Version) + if self._connected and self.api.smile.type == "power": + self.update_interval = P1_UPDATE_INTERVAL async def _async_setup(self) -> None: """Initialize the update_data process.""" diff --git a/tests/components/plugwise/test_init.py b/tests/components/plugwise/test_init.py index 02f434b2366..b06b1a9e0c8 100644 --- a/tests/components/plugwise/test_init.py +++ b/tests/components/plugwise/test_init.py @@ -15,7 +15,11 @@ from plugwise.exceptions import ( ) import pytest -from homeassistant.components.plugwise.const import DOMAIN +from homeassistant.components.plugwise.const import ( + DEFAULT_UPDATE_INTERVAL, + DOMAIN, + P1_UPDATE_INTERVAL, +) from homeassistant.config_entries import ConfigEntryState from homeassistant.const import Platform from homeassistant.core import HomeAssistant @@ -364,3 +368,51 @@ async def test_delete_removed_device( for device_entry in device_registry.devices.values(): item_list.extend(x[1] for x in device_entry.identifiers) assert "14df5c4dc8cb4ba69f9d1ac0eaf7c5c6" not in item_list + + +@pytest.mark.parametrize("chosen_env", ["m_adam_heating"], indirect=True) +@pytest.mark.parametrize("cooling_present", [False], indirect=True) +async def test_update_interval_adam( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_smile_adam_heat_cool: MagicMock, + freezer: FrozenDateTimeFactory, +) -> None: + """Test Adam update interval.""" + mock_config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + assert mock_config_entry.state is ConfigEntryState.LOADED + assert mock_smile_adam_heat_cool.async_update.call_count == 1 + + freezer.tick(DEFAULT_UPDATE_INTERVAL) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + assert mock_smile_adam_heat_cool.async_update.call_count == 2 + + +@pytest.mark.parametrize("chosen_env", ["p1v4_442_single"], indirect=True) +@pytest.mark.parametrize( + "gateway_id", ["a455b61e52394b2db5081ce025a430f3"], indirect=True +) +async def test_update_interval_p1( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_smile_p1: MagicMock, + freezer: FrozenDateTimeFactory, +) -> None: + """Test Smile P1 update interval.""" + mock_config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + assert mock_config_entry.state is ConfigEntryState.LOADED + assert mock_smile_p1.async_update.call_count == 1 + + freezer.tick(P1_UPDATE_INTERVAL) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + assert mock_smile_p1.async_update.call_count == 2