Add test for HA stop to devolo Home Control (#116682)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
pull/116697/head
Guido Schmitz 2024-05-03 13:36:15 +02:00 committed by GitHub
parent 28ab45d5d8
commit 79d50a0685
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -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):

View File

@ -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,