Only import color extractor when domain is in config (#101522)
This commit is contained in:
parent
ca7355b2f3
commit
97d17637ea
3 changed files with 12 additions and 14 deletions
|
@ -24,7 +24,10 @@ from .const import ATTR_PATH, ATTR_URL, DOMAIN, SERVICE_TURN_ON
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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
|
# Extend the existing light.turn_on service schema
|
||||||
SERVICE_SCHEMA = vol.All(
|
SERVICE_SCHEMA = vol.All(
|
||||||
|
@ -62,6 +65,7 @@ def _get_color(file_handler) -> tuple:
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Color extractor component."""
|
"""Set up the Color extractor component."""
|
||||||
|
|
||||||
|
if DOMAIN in config:
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data={}
|
DOMAIN, context={"source": SOURCE_IMPORT}, data={}
|
||||||
|
|
|
@ -8,7 +8,7 @@ from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
async def test_legacy_migration(hass: HomeAssistant) -> None:
|
async def test_legacy_migration(hass: HomeAssistant) -> None:
|
||||||
"""Test migration from yaml to config flow."""
|
"""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()
|
await hass.async_block_till_done()
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert len(entries) == 1
|
assert len(entries) == 1
|
||||||
|
|
|
@ -254,7 +254,7 @@ def _get_file_mock(file_path):
|
||||||
|
|
||||||
@patch("os.path.isfile", Mock(return_value=True))
|
@patch("os.path.isfile", Mock(return_value=True))
|
||||||
@patch("os.access", 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."""
|
"""Test that the file only service reads a file and translates to light RGB."""
|
||||||
service_data = {
|
service_data = {
|
||||||
ATTR_PATH: "/opt/image.png",
|
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
|
# Add our /opt/ path to the allowed list of paths
|
||||||
hass.config.allowlist_external_dirs.add("/opt/")
|
hass.config.allowlist_external_dirs.add("/opt/")
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, {})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Verify pre service check
|
# Verify pre service check
|
||||||
state = hass.states.get(LIGHT_ENTITY)
|
state = hass.states.get(LIGHT_ENTITY)
|
||||||
assert state
|
assert state
|
||||||
|
@ -295,7 +292,7 @@ async def test_file(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
@patch("os.path.isfile", Mock(return_value=True))
|
@patch("os.path.isfile", Mock(return_value=True))
|
||||||
@patch("os.access", 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."""
|
"""Test that the file only service fails to read an image in a dir not explicitly allowed."""
|
||||||
service_data = {
|
service_data = {
|
||||||
ATTR_PATH: "/path/to/a/dir/not/allowed/image.png",
|
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,
|
ATTR_BRIGHTNESS_PCT: 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
await async_setup_component(hass, DOMAIN, {})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Verify pre service check
|
# Verify pre service check
|
||||||
state = hass.states.get(LIGHT_ENTITY)
|
state = hass.states.get(LIGHT_ENTITY)
|
||||||
assert state
|
assert state
|
||||||
|
|
Loading…
Add table
Reference in a new issue