From 79d50a0685cb1ee2a74036c982844f986de4108d Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Fri, 3 May 2024 13:36:15 +0200 Subject: [PATCH] Add test for HA stop to devolo Home Control (#116682) Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- tests/components/devolo_home_control/mocks.py | 4 +--- .../devolo_home_control/test_init.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/components/devolo_home_control/mocks.py b/tests/components/devolo_home_control/mocks.py index 61a9f1c7d8c..422a24c3be0 100644 --- a/tests/components/devolo_home_control/mocks.py +++ b/tests/components/devolo_home_control/mocks.py @@ -257,9 +257,7 @@ class HomeControlMock(HomeControl): self.gateway = MagicMock() self.gateway.local_connection = True self.gateway.firmware_version = "8.94.0" - - def websocket_disconnect(self, event: str = "") -> None: - """Mock disconnect of the websocket.""" + self.websocket_disconnect = MagicMock() class HomeControlMockBinarySensor(HomeControlMock): diff --git a/tests/components/devolo_home_control/test_init.py b/tests/components/devolo_home_control/test_init.py index fa32d67d86c..a6fa89231c2 100644 --- a/tests/components/devolo_home_control/test_init.py +++ b/tests/components/devolo_home_control/test_init.py @@ -8,6 +8,7 @@ import pytest from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN from homeassistant.components.devolo_home_control import DOMAIN from homeassistant.config_entries import ConfigEntryState +from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component @@ -63,6 +64,23 @@ async def test_unload_entry(hass: HomeAssistant) -> None: assert entry.state is ConfigEntryState.NOT_LOADED +async def test_home_assistant_stop(hass: HomeAssistant) -> None: + """Test home assistant stop.""" + entry = configure_integration(hass) + test_gateway = HomeControlMock() + test_gateway2 = HomeControlMock() + with patch( + "homeassistant.components.devolo_home_control.HomeControl", + side_effect=[test_gateway, test_gateway2], + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) + await hass.async_block_till_done() + assert test_gateway.websocket_disconnect.called + assert test_gateway2.websocket_disconnect.called + + async def test_remove_device( hass: HomeAssistant, hass_ws_client: WebSocketGenerator,