From e4b79d4f3d41f5cf4cf5df2a8efb49a3fb99fad0 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 26 May 2026 16:17:37 +0200 Subject: [PATCH] Don't use async_setup in vesync tests (#172257) --- tests/components/vesync/test_services.py | 30 ++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/components/vesync/test_services.py b/tests/components/vesync/test_services.py index 9993bae366b0..0f7ffae02e38 100644 --- a/tests/components/vesync/test_services.py +++ b/tests/components/vesync/test_services.py @@ -5,7 +5,6 @@ from unittest.mock import AsyncMock import pytest from pyvesync import VeSync -from homeassistant.components.vesync import async_setup from homeassistant.components.vesync.const import DOMAIN, SERVICE_UPDATE_DEVS from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.core import HomeAssistant @@ -13,33 +12,40 @@ from homeassistant.exceptions import ServiceValidationError from homeassistant.helpers import entity_registry as er +@pytest.mark.usefixtures("manager") async def test_async_new_device_discovery_no_entry( hass: HomeAssistant, + config_entry: ConfigEntry, ) -> None: """Service should raise when no config entry exists.""" - # Ensure the integration is set up so the service is registered - # pylint: disable-next=home-assistant-tests-direct-async-setup - assert await async_setup(hass, {}) + # Set up the config entry so the service is registered, then remove the + # entry so the service has no entries to operate on. + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + await hass.config_entries.async_remove(config_entry.entry_id) + await hass.async_block_till_done() - # No entries for the domain, service should raise with pytest.raises(ServiceValidationError, match="Entry not found"): - await hass.services.async_call("vesync", SERVICE_UPDATE_DEVS, {}, blocking=True) + await hass.services.async_call(DOMAIN, SERVICE_UPDATE_DEVS, {}, blocking=True) +@pytest.mark.usefixtures("manager") async def test_async_new_device_discovery_entry_not_loaded( - hass: HomeAssistant, config_entry: ConfigEntry + hass: HomeAssistant, + config_entry: ConfigEntry, ) -> None: """Service should raise when entry exists but is not loaded.""" - # Add a config entry but do not set it up (state is not LOADED) + # Set up the config entry so the service is registered, then unload it. + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + assert await hass.config_entries.async_unload(config_entry.entry_id) + await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.NOT_LOADED - # Ensure the integration is set up so the service is registered - # pylint: disable-next=home-assistant-tests-direct-async-setup - assert await async_setup(hass, {}) with pytest.raises(ServiceValidationError, match="Entry not loaded"): - await hass.services.async_call("vesync", SERVICE_UPDATE_DEVS, {}, blocking=True) + await hass.services.async_call(DOMAIN, SERVICE_UPDATE_DEVS, {}, blocking=True) async def test_async_new_device_discovery(