diff --git a/homeassistant/components/litejet/__init__.py b/homeassistant/components/litejet/__init__.py index 8c6d5ef4487..da24aee9ab8 100644 --- a/homeassistant/components/litejet/__init__.py +++ b/homeassistant/components/litejet/__init__.py @@ -2,49 +2,16 @@ import logging import pylitejet -import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PORT, EVENT_HOMEASSISTANT_STOP from homeassistant.core import Event, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.typing import ConfigType -from .const import CONF_EXCLUDE_NAMES, CONF_INCLUDE_SWITCHES, DOMAIN, PLATFORMS +from .const import DOMAIN, PLATFORMS _LOGGER = logging.getLogger(__name__) -CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN), - { - DOMAIN: vol.Schema( - { - vol.Required(CONF_PORT): cv.string, - vol.Optional(CONF_EXCLUDE_NAMES): vol.All( - cv.ensure_list, [cv.string] - ), - vol.Optional(CONF_INCLUDE_SWITCHES, default=False): cv.boolean, - } - ) - }, - ), - extra=vol.ALLOW_EXTRA, -) - - -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the LiteJet component.""" - if DOMAIN in config: - # Configuration.yaml config exists, trigger the import flow. - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=config[DOMAIN] - ) - ) - return True - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up LiteJet via a config entry.""" diff --git a/homeassistant/components/litejet/config_flow.py b/homeassistant/components/litejet/config_flow.py index 1062e948090..a7b5a6f000e 100644 --- a/homeassistant/components/litejet/config_flow.py +++ b/homeassistant/components/litejet/config_flow.py @@ -9,10 +9,9 @@ import voluptuous as vol from homeassistant import config_entries from homeassistant.const import CONF_PORT -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, callback -from homeassistant.data_entry_flow import FlowResult, FlowResultType +from homeassistant.core import callback +from homeassistant.data_entry_flow import FlowResult import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from .const import CONF_DEFAULT_TRANSITION, DOMAIN @@ -54,21 +53,6 @@ class LiteJetConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) -> FlowResult: """Create a LiteJet config entry based upon user input.""" if self._async_current_entries(): - if self.context["source"] == config_entries.SOURCE_IMPORT: - async_create_issue( - self.hass, - HOMEASSISTANT_DOMAIN, - f"deprecated_yaml_{DOMAIN}", - breaks_in_ha_version="2024.2.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - translation_placeholders={ - "domain": DOMAIN, - "integration_title": "LiteJet", - }, - ) return self.async_abort(reason="single_instance_allowed") errors = {} @@ -78,20 +62,6 @@ class LiteJetConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): try: system = await pylitejet.open(port) except SerialException: - if self.context["source"] == config_entries.SOURCE_IMPORT: - async_create_issue( - self.hass, - DOMAIN, - "deprecated_yaml_serial_exception", - breaks_in_ha_version="2024.2.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.ERROR, - translation_key="deprecated_yaml_serial_exception", - translation_placeholders={ - "url": "/config/integrations/dashboard/add?domain=litejet" - }, - ) errors[CONF_PORT] = "open_failed" else: await system.close() @@ -106,27 +76,6 @@ class LiteJetConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): errors=errors, ) - async def async_step_import(self, import_data: dict[str, Any]) -> FlowResult: - """Import litejet config from configuration.yaml.""" - new_data = {CONF_PORT: import_data[CONF_PORT]} - result = await self.async_step_user(new_data) - if result["type"] == FlowResultType.CREATE_ENTRY: - async_create_issue( - self.hass, - HOMEASSISTANT_DOMAIN, - f"deprecated_yaml_{DOMAIN}", - breaks_in_ha_version="2024.2.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - translation_placeholders={ - "domain": DOMAIN, - "integration_title": "LiteJet", - }, - ) - return result - @staticmethod @callback def async_get_options_flow( diff --git a/homeassistant/components/litejet/strings.json b/homeassistant/components/litejet/strings.json index 288e5f959a8..398f1a1e5aa 100644 --- a/homeassistant/components/litejet/strings.json +++ b/homeassistant/components/litejet/strings.json @@ -25,11 +25,5 @@ } } } - }, - "issues": { - "deprecated_yaml_serial_exception": { - "title": "The LiteJet YAML configuration import failed", - "description": "Configuring LiteJet using YAML is being removed but there was an error opening the serial port when importing your YAML configuration.\n\nCorrect the YAML configuration and restart Home Assistant to try again or manually continue to [set up the integration]({url})." - } } } diff --git a/tests/components/litejet/test_config_flow.py b/tests/components/litejet/test_config_flow.py index e2b2829de9e..b490643f622 100644 --- a/tests/components/litejet/test_config_flow.py +++ b/tests/components/litejet/test_config_flow.py @@ -6,8 +6,7 @@ from serial import SerialException from homeassistant import config_entries, data_entry_flow from homeassistant.components.litejet.const import CONF_DEFAULT_TRANSITION, DOMAIN from homeassistant.const import CONF_PORT -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant -import homeassistant.helpers.issue_registry as ir +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -68,63 +67,6 @@ async def test_flow_open_failed(hass: HomeAssistant) -> None: assert result["errors"][CONF_PORT] == "open_failed" -async def test_import_step(hass: HomeAssistant, mock_litejet) -> None: - """Test initializing via import step.""" - test_data = {CONF_PORT: "/dev/imported"} - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=test_data - ) - - assert result["type"] == "create_entry" - assert result["title"] == test_data[CONF_PORT] - assert result["data"] == test_data - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue( - HOMEASSISTANT_DOMAIN, "deprecated_yaml_litejet" - ) - assert issue.translation_key == "deprecated_yaml" - - -async def test_import_step_fails(hass: HomeAssistant) -> None: - """Test initializing via import step fails due to can't open port.""" - test_data = {CONF_PORT: "/dev/test"} - with patch("pylitejet.LiteJet") as mock_pylitejet: - mock_pylitejet.side_effect = SerialException - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=test_data - ) - - assert result["type"] == data_entry_flow.FlowResultType.FORM - assert result["errors"] == {"port": "open_failed"} - - issue_registry = ir.async_get(hass) - assert issue_registry.async_get_issue(DOMAIN, "deprecated_yaml_serial_exception") - - -async def test_import_step_already_exist(hass: HomeAssistant) -> None: - """Test initializing via import step when entry already exist.""" - first_entry = MockConfigEntry( - domain=DOMAIN, - data={CONF_PORT: "/dev/imported"}, - ) - first_entry.add_to_hass(hass) - - test_data = {CONF_PORT: "/dev/imported"} - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=test_data - ) - - assert result["type"] == data_entry_flow.FlowResultType.ABORT - assert result["reason"] == "single_instance_allowed" - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue( - HOMEASSISTANT_DOMAIN, "deprecated_yaml_litejet" - ) - assert issue.translation_key == "deprecated_yaml" - - async def test_options(hass: HomeAssistant) -> None: """Test updating options.""" entry = MockConfigEntry(domain=DOMAIN, data={CONF_PORT: "/dev/test"}) diff --git a/tests/components/litejet/test_init.py b/tests/components/litejet/test_init.py index fdaeeefc867..c6f0d5c5b02 100644 --- a/tests/components/litejet/test_init.py +++ b/tests/components/litejet/test_init.py @@ -1,7 +1,6 @@ """The tests for the litejet component.""" from homeassistant.components import litejet from homeassistant.components.litejet.const import DOMAIN -from homeassistant.const import CONF_PORT from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -14,15 +13,6 @@ async def test_setup_with_no_config(hass: HomeAssistant) -> None: assert DOMAIN not in hass.data -async def test_setup_with_config_to_import(hass: HomeAssistant, mock_litejet) -> None: - """Test that import happens.""" - assert ( - await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PORT: "/dev/hello"}}) - is True - ) - assert DOMAIN in hass.data - - async def test_unload_entry(hass: HomeAssistant, mock_litejet) -> None: """Test being able to unload an entry.""" entry = await async_init_integration(hass, use_switch=True, use_scene=True)