Remove Color extractor import flow (#115015)

* Remove Color extractor import flow

* Remove Color extractor import flow
This commit is contained in:
Joost Lekkerkerker 2024-04-07 19:38:56 +02:00 committed by GitHub
parent 3239351f18
commit 9ec4e9a1a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 5 additions and 99 deletions

View file

@ -14,7 +14,7 @@ from homeassistant.components.light import (
DOMAIN as LIGHT_DOMAIN, DOMAIN as LIGHT_DOMAIN,
LIGHT_TURN_ON_SCHEMA, LIGHT_TURN_ON_SCHEMA,
) )
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import SERVICE_TURN_ON as LIGHT_SERVICE_TURN_ON from homeassistant.const import SERVICE_TURN_ON as LIGHT_SERVICE_TURN_ON
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import aiohttp_client from homeassistant.helpers import aiohttp_client
@ -25,10 +25,7 @@ from .const import ATTR_PATH, ATTR_URL, DOMAIN, SERVICE_TURN_ON
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
{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(
@ -156,13 +153,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
_file = _get_file(file_path) _file = _get_file(file_path)
return _get_color(_file) return _get_color(_file)
if DOMAIN in config:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data={}
)
)
return True return True

View file

@ -5,9 +5,6 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from .const import DEFAULT_NAME, DOMAIN from .const import DEFAULT_NAME, DOMAIN
@ -28,38 +25,3 @@ class ColorExtractorConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_create_entry(title=DEFAULT_NAME, data={}) return self.async_create_entry(title=DEFAULT_NAME, data={})
return self.async_show_form(step_id="user") return self.async_show_form(step_id="user")
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
"""Handle import from configuration.yaml."""
result = await self.async_step_user(user_input)
if result["type"] == FlowResultType.CREATE_ENTRY:
async_create_issue(
self.hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
breaks_in_ha_version="2024.4.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Color extractor",
},
)
else:
async_create_issue(
self.hass,
DOMAIN,
"deprecated_yaml",
breaks_in_ha_version="2024.4.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Color extractor",
},
)
return result

View file

@ -9,12 +9,6 @@
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
} }
}, },
"issues": {
"deprecated_yaml": {
"title": "The {integration_title} YAML configuration is being removed",
"description": "Configuring {integration_title} using YAML is being removed.\n\nYour configuration is already imported.\n\nRemove the `{domain}` configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
},
"services": { "services": {
"turn_on": { "turn_on": {
"name": "[%key:common::action::turn_on%]", "name": "[%key:common::action::turn_on%]",

View file

@ -2,10 +2,8 @@
from unittest.mock import patch from unittest.mock import patch
import pytest
from homeassistant.components.color_extractor.const import DOMAIN from homeassistant.components.color_extractor.const import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
@ -37,35 +35,15 @@ async def test_full_user_flow(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.parametrize("source", [SOURCE_USER, SOURCE_IMPORT]) async def test_single_instance_allowed(hass: HomeAssistant) -> None:
async def test_single_instance_allowed(
hass: HomeAssistant,
source: str,
) -> None:
"""Test we abort if already setup.""" """Test we abort if already setup."""
mock_config_entry = MockConfigEntry(domain=DOMAIN) mock_config_entry = MockConfigEntry(domain=DOMAIN)
mock_config_entry.add_to_hass(hass) mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": source}, data={} DOMAIN, context={"source": SOURCE_USER}, data={}
) )
assert result.get("type") is FlowResultType.ABORT assert result.get("type") is FlowResultType.ABORT
assert result.get("reason") == "single_instance_allowed" assert result.get("reason") == "single_instance_allowed"
async def test_import_flow(
hass: HomeAssistant,
) -> None:
"""Test the import configuration flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={},
)
assert result.get("type") is FlowResultType.CREATE_ENTRY
assert result.get("title") == "Color extractor"
assert result.get("data") == {}
assert result.get("options") == {}

View file

@ -1,18 +0,0 @@
"""Test Color extractor component setup process."""
from homeassistant.components.color_extractor import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
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, {DOMAIN: {}})
await hass.async_block_till_done()
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
assert entries[0].state is ConfigEntryState.LOADED
issue_registry = ir.async_get(hass)
assert len(issue_registry.issues) == 1