Only import color extractor when domain is in config (#101522)

pull/101529/head
Joost Lekkerkerker 2023-10-06 13:18:44 +02:00 committed by GitHub
parent ca7355b2f3
commit 97d17637ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 14 deletions

View File

@ -24,7 +24,10 @@ from .const import ATTR_PATH, ATTR_URL, DOMAIN, SERVICE_TURN_ON
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
CONFIG_SCHEMA = vol.Schema(
{vol.Optional(DOMAIN): {}},
extra=vol.ALLOW_EXTRA,
)
# Extend the existing light.turn_on service schema
SERVICE_SCHEMA = vol.All(
@ -62,6 +65,7 @@ def _get_color(file_handler) -> tuple:
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Color extractor component."""
if DOMAIN in config:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data={}

View File

@ -8,7 +8,7 @@ from homeassistant.setup import async_setup_component
async def test_legacy_migration(hass: HomeAssistant) -> None:
"""Test migration from yaml to config flow."""
assert await async_setup_component(hass, DOMAIN, {})
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1

View File

@ -254,7 +254,7 @@ def _get_file_mock(file_path):
@patch("os.path.isfile", Mock(return_value=True))
@patch("os.access", Mock(return_value=True))
async def test_file(hass: HomeAssistant) -> None:
async def test_file(hass: HomeAssistant, setup_integration) -> None:
"""Test that the file only service reads a file and translates to light RGB."""
service_data = {
ATTR_PATH: "/opt/image.png",
@ -266,9 +266,6 @@ async def test_file(hass: HomeAssistant) -> None:
# Add our /opt/ path to the allowed list of paths
hass.config.allowlist_external_dirs.add("/opt/")
await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
# Verify pre service check
state = hass.states.get(LIGHT_ENTITY)
assert state
@ -295,7 +292,7 @@ async def test_file(hass: HomeAssistant) -> None:
@patch("os.path.isfile", Mock(return_value=True))
@patch("os.access", Mock(return_value=True))
async def test_file_denied_dir(hass: HomeAssistant) -> None:
async def test_file_denied_dir(hass: HomeAssistant, setup_integration) -> None:
"""Test that the file only service fails to read an image in a dir not explicitly allowed."""
service_data = {
ATTR_PATH: "/path/to/a/dir/not/allowed/image.png",
@ -304,9 +301,6 @@ async def test_file_denied_dir(hass: HomeAssistant) -> None:
ATTR_BRIGHTNESS_PCT: 100,
}
await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
# Verify pre service check
state = hass.states.get(LIGHT_ENTITY)
assert state