mirror of
https://github.com/home-assistant/core.git
synced 2026-07-13 01:27:57 +01:00
Don't use async_setup in vesync tests (#172257)
This commit is contained in:
committed by
GitHub
parent
f6d4d0289e
commit
e4b79d4f3d
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user