Support reloading the group notify platform (#39511)
This commit is contained in:
parent
2d2efeb9bb
commit
a778690b64
8 changed files with 470 additions and 129 deletions
|
@ -13,8 +13,9 @@ from homeassistant.helpers.reload import (
|
|||
async_reload_integration_platforms,
|
||||
async_setup_reload_service,
|
||||
)
|
||||
from homeassistant.loader import async_get_integration
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
from tests.async_mock import AsyncMock, Mock, patch
|
||||
from tests.common import (
|
||||
MockModule,
|
||||
MockPlatform,
|
||||
|
@ -109,6 +110,104 @@ async def test_setup_reload_service(hass):
|
|||
assert len(setup_called) == 2
|
||||
|
||||
|
||||
async def test_setup_reload_service_when_async_process_component_config_fails(hass):
|
||||
"""Test setting up a reload service with the config processing failing."""
|
||||
component_setup = Mock(return_value=True)
|
||||
|
||||
setup_called = []
|
||||
|
||||
async def setup_platform(*args):
|
||||
setup_called.append(args)
|
||||
|
||||
mock_integration(hass, MockModule(DOMAIN, setup=component_setup))
|
||||
mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN]))
|
||||
|
||||
mock_platform = MockPlatform(async_setup_platform=setup_platform)
|
||||
mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform)
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
||||
await component.async_setup({DOMAIN: {"platform": PLATFORM, "sensors": None}})
|
||||
await hass.async_block_till_done()
|
||||
assert component_setup.called
|
||||
|
||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
||||
assert len(setup_called) == 1
|
||||
|
||||
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
||||
|
||||
yaml_path = path.join(
|
||||
_get_fixtures_base_path(),
|
||||
"fixtures",
|
||||
"helpers/reload_configuration.yaml",
|
||||
)
|
||||
with patch.object(config, "YAML_CONFIG_FILE", yaml_path), patch.object(
|
||||
config, "async_process_component_config", return_value=None
|
||||
):
|
||||
await hass.services.async_call(
|
||||
PLATFORM,
|
||||
SERVICE_RELOAD,
|
||||
{},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(setup_called) == 1
|
||||
|
||||
|
||||
async def test_setup_reload_service_with_platform_that_provides_async_reset_platform(
|
||||
hass,
|
||||
):
|
||||
"""Test setting up a reload service using a platform that has its own async_reset_platform."""
|
||||
component_setup = AsyncMock(return_value=True)
|
||||
|
||||
setup_called = []
|
||||
async_reset_platform_called = []
|
||||
|
||||
async def setup_platform(*args):
|
||||
setup_called.append(args)
|
||||
|
||||
async def async_reset_platform(*args):
|
||||
async_reset_platform_called.append(args)
|
||||
|
||||
mock_integration(hass, MockModule(DOMAIN, async_setup=component_setup))
|
||||
integration = await async_get_integration(hass, DOMAIN)
|
||||
integration.get_component().async_reset_platform = async_reset_platform
|
||||
|
||||
mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN]))
|
||||
|
||||
mock_platform = MockPlatform(async_setup_platform=setup_platform)
|
||||
mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform)
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
||||
await component.async_setup({DOMAIN: {"platform": PLATFORM, "name": "xyz"}})
|
||||
await hass.async_block_till_done()
|
||||
assert component_setup.called
|
||||
|
||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
||||
assert len(setup_called) == 1
|
||||
|
||||
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
||||
|
||||
yaml_path = path.join(
|
||||
_get_fixtures_base_path(),
|
||||
"fixtures",
|
||||
"helpers/reload_configuration.yaml",
|
||||
)
|
||||
with patch.object(config, "YAML_CONFIG_FILE", yaml_path):
|
||||
await hass.services.async_call(
|
||||
PLATFORM,
|
||||
SERVICE_RELOAD,
|
||||
{},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(setup_called) == 1
|
||||
assert len(async_reset_platform_called) == 1
|
||||
|
||||
|
||||
async def test_async_integration_yaml_config(hass):
|
||||
"""Test loading yaml config for an integration."""
|
||||
mock_integration(hass, MockModule(DOMAIN))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue