Remove YAML import for lutron (#120159)

* Remove YAML import for lutron

* Restore constants
pull/120168/head
G Johansson 2024-06-22 18:23:35 +02:00 committed by GitHub
parent 6045c2bb08
commit cac55d0f47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 2 additions and 187 deletions

View File

@ -4,17 +4,11 @@ from dataclasses import dataclass
import logging
from pylutron import Button, Keypad, Led, Lutron, OccupancyGroup, Output
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN
@ -35,69 +29,6 @@ ATTR_ACTION = "action"
ATTR_FULL_ID = "full_id"
ATTR_UUID = "uuid"
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_USERNAME): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)
async def _async_import(hass: HomeAssistant, base_config: ConfigType) -> None:
"""Import a config entry from configuration.yaml."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=base_config[DOMAIN],
)
if (
result["type"] == FlowResultType.CREATE_ENTRY
or result["reason"] == "single_instance_allowed"
):
async_create_issue(
hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
breaks_in_ha_version="2024.7.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Lutron",
},
)
return
async_create_issue(
hass,
DOMAIN,
f"deprecated_yaml_import_issue_{result['reason']}",
breaks_in_ha_version="2024.7.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Lutron",
},
)
async def async_setup(hass: HomeAssistant, base_config: ConfigType) -> bool:
"""Set up the Lutron component."""
if DOMAIN in base_config:
hass.async_create_task(_async_import(hass, base_config))
return True
@dataclass(slots=True, kw_only=True)
class LutronData:

View File

@ -73,37 +73,3 @@ class LutronConfigFlow(ConfigFlow, domain=DOMAIN):
),
errors=errors,
)
async def async_step_import(
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Attempt to import the existing configuration."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
main_repeater = Lutron(
import_config[CONF_HOST],
import_config[CONF_USERNAME],
import_config[CONF_PASSWORD],
)
def _load_db() -> None:
main_repeater.load_xml_db()
try:
await self.hass.async_add_executor_job(_load_db)
except HTTPError:
_LOGGER.exception("Http error")
return self.async_abort(reason="cannot_connect")
except Exception:
_LOGGER.exception("Unknown error")
return self.async_abort(reason="unknown")
guid = main_repeater.guid
if len(guid) <= 10:
return self.async_abort(reason="cannot_connect")
_LOGGER.debug("Main Repeater GUID: %s", main_repeater.guid)
await self.async_set_unique_id(guid)
self._abort_if_unique_id_configured()
return self.async_create_entry(title="Lutron", data=import_config)

View File

@ -38,14 +38,6 @@
}
},
"issues": {
"deprecated_yaml_import_issue_cannot_connect": {
"title": "The Lutron YAML configuration import cannot connect to server",
"description": "Configuring Lutron using YAML is being removed but there was an connection error importing your YAML configuration.\n\nThings you can try:\nMake sure your home assistant can reach the main repeater.\nRestart the main repeater by unplugging it for 60 seconds.\nTry logging into the main repeater at the IP address you specified in a web browser and the same login information.\n\nThen restart Home Assistant to try importing this integration again.\n\nAlternatively, you may remove the Lutron configuration from your YAML configuration entirely, restart Home Assistant, and add the Lutron integration manually."
},
"deprecated_yaml_import_issue_unknown": {
"title": "The Lutron YAML configuration import request failed due to an unknown error",
"description": "Configuring Lutron using YAML is being removed but there was an unknown error while importing your existing configuration.\nSetup will not proceed.\n\nThe specific error can be found in the logs. The most likely cause is a networking error or the Main Repeater is down or has an invalid configuration.\n\nVerify that your Lutron system is operating correctly and restart Home Assistant to attempt the import again.\n\nAlternatively, you may remove the Lutron configuration from your YAML configuration entirely, restart Home Assistant, and add the Lutron integration manually."
},
"deprecated_light_fan_entity": {
"title": "Detected Lutron fan entity created as a light",
"description": "Fan entities have been added to the Lutron integration.\nWe detected that entity `{entity}` is being used in `{info}`\n\nWe have created a new fan entity and you should migrate `{info}` to use this new entity.\n\nWhen you are done migrating `{info}` and are ready to have the deprecated light entity removed, disable the entity and restart Home Assistant."

View File

@ -7,7 +7,7 @@ from urllib.error import HTTPError
import pytest
from homeassistant.components.lutron.const import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -146,77 +146,3 @@ MOCK_DATA_IMPORT = {
CONF_USERNAME: "lutron",
CONF_PASSWORD: "integration",
}
async def test_import(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
) -> None:
"""Test import flow."""
with (
patch("homeassistant.components.lutron.config_flow.Lutron.load_xml_db"),
patch("homeassistant.components.lutron.config_flow.Lutron.guid", "12345678901"),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=MOCK_DATA_IMPORT
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == MOCK_DATA_IMPORT
assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.parametrize(
("raise_error", "reason"),
[
(HTTPError("", 404, "", Message(), None), "cannot_connect"),
(Exception, "unknown"),
],
)
async def test_import_flow_failure(
hass: HomeAssistant, raise_error: Exception, reason: str
) -> None:
"""Test handling errors while importing."""
with patch(
"homeassistant.components.lutron.config_flow.Lutron.load_xml_db",
side_effect=raise_error,
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=MOCK_DATA_IMPORT
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == reason
async def test_import_flow_guid_failure(hass: HomeAssistant) -> None:
"""Test handling errors while importing."""
with (
patch("homeassistant.components.lutron.config_flow.Lutron.load_xml_db"),
patch("homeassistant.components.lutron.config_flow.Lutron.guid", "123"),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=MOCK_DATA_IMPORT
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
async def test_import_already_configured(hass: HomeAssistant) -> None:
"""Test we abort import when entry is already configured."""
entry = MockConfigEntry(
domain=DOMAIN, data=MOCK_DATA_IMPORT, unique_id="12345678901"
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=MOCK_DATA_IMPORT
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"