Fix device cleanup in plugwise (#126212)

This commit is contained in:
Erik Montnemery
2024-09-18 13:50:36 +02:00
committed by GitHub
parent ec2db38516
commit a10d68e63e
2 changed files with 21 additions and 13 deletions

View File

@@ -3,6 +3,7 @@
from datetime import timedelta
from unittest.mock import MagicMock, patch
from freezegun.api import FrozenDateTimeFactory
from plugwise.exceptions import (
ConnectionFailedError,
InvalidAuthentication,
@@ -19,7 +20,6 @@ from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
from tests.common import MockConfigEntry, async_fire_time_changed
@@ -231,9 +231,9 @@ async def test_update_device(
mock_smile_adam_2: MagicMock,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test a clean-up of the device_registry."""
utcnow = dt_util.utcnow()
data = mock_smile_adam_2.async_update.return_value
mock_config_entry.add_to_hass(hass)
@@ -260,7 +260,8 @@ async def test_update_device(
# Add a 2nd Tom/Floor
data.devices.update(TOM)
with patch(HA_PLUGWISE_SMILE_ASYNC_UPDATE, return_value=data):
async_fire_time_changed(hass, utcnow + timedelta(minutes=1))
freezer.tick(timedelta(minutes=1))
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert (
@@ -287,7 +288,8 @@ async def test_update_device(
# Remove the existing Tom/Floor
data.devices.pop("1772a4ea304041adb83f357b751341ff")
with patch(HA_PLUGWISE_SMILE_ASYNC_UPDATE, return_value=data):
async_fire_time_changed(hass, utcnow + timedelta(minutes=1))
freezer.tick(timedelta(minutes=1))
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert (