mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 03:03:17 +01:00
Implement shorter default update_interval for Plugwise P1 (#159626)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user