1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add the ability to reload light/cover groups from yaml (#39250)

* Add the ability to reload light/cover groups from yaml

Update previous usage to reduce code duplication.

* Fix conflict from rebase
This commit is contained in:
J. Nick Koston
2020-08-25 18:13:43 -05:00
committed by GitHub
parent e109b04efe
commit 810df38f0d
16 changed files with 175 additions and 56 deletions

View File

@@ -3,10 +3,12 @@ import logging
from os import path
from homeassistant import config
from homeassistant.const import SERVICE_RELOAD
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.reload import (
async_get_platform,
async_reload_integration_platforms,
async_setup_reload_service,
)
from tests.async_mock import Mock, patch
@@ -59,5 +61,43 @@ async def test_reload_platform(hass):
assert len(setup_called) == 2
async def test_setup_reload_service(hass):
"""Test setting up a reload service."""
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):
await hass.services.async_call(
PLATFORM, SERVICE_RELOAD, {}, blocking=True,
)
await hass.async_block_till_done()
assert len(setup_called) == 2
def _get_fixtures_base_path():
return path.dirname(path.dirname(__file__))