mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove deprecated YAML import from rova (#125849)
This commit is contained in:
parent
2c210e4b58
commit
57e1709782
@ -59,31 +59,3 @@ class RovaConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
),
|
),
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
|
||||||
"""Import the yaml config."""
|
|
||||||
zip_code = import_data[CONF_ZIP_CODE]
|
|
||||||
number = import_data[CONF_HOUSE_NUMBER]
|
|
||||||
suffix = import_data[CONF_HOUSE_NUMBER_SUFFIX]
|
|
||||||
|
|
||||||
await self.async_set_unique_id(f"{zip_code}{number}{suffix}".strip())
|
|
||||||
self._abort_if_unique_id_configured()
|
|
||||||
|
|
||||||
api = Rova(zip_code, number, suffix)
|
|
||||||
|
|
||||||
try:
|
|
||||||
result = await self.hass.async_add_executor_job(api.is_rova_area)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
return self.async_create_entry(
|
|
||||||
title=f"{zip_code} {number} {suffix}".strip(),
|
|
||||||
data={
|
|
||||||
CONF_ZIP_CODE: zip_code,
|
|
||||||
CONF_HOUSE_NUMBER: number,
|
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: suffix,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="invalid_rova_area")
|
|
||||||
|
|
||||||
except (ConnectTimeout, HTTPError):
|
|
||||||
return self.async_abort(reason="cannot_connect")
|
|
||||||
|
@ -4,26 +4,18 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
|
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import CONF_HOUSE_NUMBER, CONF_HOUSE_NUMBER_SUFFIX, CONF_ZIP_CODE, DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import RovaCoordinator
|
from .coordinator import RovaCoordinator
|
||||||
|
|
||||||
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=rova"}
|
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=rova"}
|
||||||
@ -47,62 +39,6 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_ZIP_CODE): cv.string,
|
|
||||||
vol.Required(CONF_HOUSE_NUMBER): cv.string,
|
|
||||||
vol.Optional(CONF_HOUSE_NUMBER_SUFFIX, default=""): cv.string,
|
|
||||||
vol.Optional(CONF_NAME, default="Rova"): cv.string,
|
|
||||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=["bio"]): vol.All(
|
|
||||||
cv.ensure_list, [vol.In(["bio", "paper", "plastic", "residual"])]
|
|
||||||
),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the rova sensor platform through yaml configuration."""
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=config,
|
|
||||||
)
|
|
||||||
if (
|
|
||||||
result["type"] == FlowResultType.CREATE_ENTRY
|
|
||||||
or result["reason"] == "already_configured"
|
|
||||||
):
|
|
||||||
async_create_issue(
|
|
||||||
hass,
|
|
||||||
HOMEASSISTANT_DOMAIN,
|
|
||||||
f"deprecated_yaml_{DOMAIN}",
|
|
||||||
breaks_in_ha_version="2024.10.0",
|
|
||||||
is_fixable=False,
|
|
||||||
issue_domain=DOMAIN,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key="deprecated_yaml",
|
|
||||||
translation_placeholders={
|
|
||||||
"domain": DOMAIN,
|
|
||||||
"integration_title": "Rova",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
async_create_issue(
|
|
||||||
hass,
|
|
||||||
DOMAIN,
|
|
||||||
f"deprecated_yaml_import_issue_{result['reason']}",
|
|
||||||
breaks_in_ha_version="2024.10.0",
|
|
||||||
is_fixable=False,
|
|
||||||
issue_domain=DOMAIN,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
|
|
||||||
translation_placeholders=ISSUE_PLACEHOLDER,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -21,14 +21,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"issues": {
|
"issues": {
|
||||||
"deprecated_yaml_import_issue_cannot_connect": {
|
|
||||||
"title": "The Rova YAML configuration import failed",
|
|
||||||
"description": "Configuring Rova using YAML is being removed but there was a connection error importing your YAML configuration.\n\nEnsure connection to Rova works and restart Home Assistant to try again or remove the Rova YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
|
|
||||||
},
|
|
||||||
"deprecated_yaml_import_issue_invalid_rova_area": {
|
|
||||||
"title": "The Rova YAML configuration import failed",
|
|
||||||
"description": "There was an error when trying to import your Rova YAML configuration.\n\nRova does not collect at this address.\n\nEnsure the imported configuration is correct and remove the Rova YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
|
|
||||||
},
|
|
||||||
"no_rova_area": {
|
"no_rova_area": {
|
||||||
"title": "Rova does not collect at this address anymore",
|
"title": "Rova does not collect at this address anymore",
|
||||||
"description": "Rova does not collect at {zip_code} anymore.\n\nPlease remove the integration."
|
"description": "Rova does not collect at {zip_code} anymore.\n\nPlease remove the integration."
|
||||||
|
@ -11,7 +11,7 @@ from homeassistant.components.rova.const import (
|
|||||||
CONF_ZIP_CODE,
|
CONF_ZIP_CODE,
|
||||||
DOMAIN,
|
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
|
||||||
|
|
||||||
@ -167,104 +167,3 @@ async def test_abort_if_api_throws_exception(
|
|||||||
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass: HomeAssistant, mock_rova: MagicMock) -> None:
|
|
||||||
"""Test import flow."""
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_ZIP_CODE: ZIP_CODE,
|
|
||||||
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == f"{ZIP_CODE} {HOUSE_NUMBER} {HOUSE_NUMBER_SUFFIX}"
|
|
||||||
assert result["data"] == {
|
|
||||||
CONF_ZIP_CODE: ZIP_CODE,
|
|
||||||
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_already_configured(
|
|
||||||
hass: HomeAssistant, mock_rova: MagicMock
|
|
||||||
) -> None:
|
|
||||||
"""Test we abort import flow when entry is already configured."""
|
|
||||||
entry = MockConfigEntry(
|
|
||||||
domain=DOMAIN,
|
|
||||||
unique_id=f"{ZIP_CODE}{HOUSE_NUMBER}{HOUSE_NUMBER_SUFFIX}",
|
|
||||||
data={
|
|
||||||
CONF_ZIP_CODE: ZIP_CODE,
|
|
||||||
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_ZIP_CODE: ZIP_CODE,
|
|
||||||
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_if_not_rova_area(
|
|
||||||
hass: HomeAssistant, mock_rova: MagicMock
|
|
||||||
) -> None:
|
|
||||||
"""Test we abort if rova does not collect at the given address."""
|
|
||||||
|
|
||||||
# test with area where rova does not collect
|
|
||||||
mock_rova.return_value.is_rova_area.return_value = False
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_ZIP_CODE: ZIP_CODE,
|
|
||||||
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.ABORT
|
|
||||||
assert result.get("reason") == "invalid_rova_area"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("exception", "error"),
|
|
||||||
[
|
|
||||||
(ConnectTimeout(), "cannot_connect"),
|
|
||||||
(HTTPError(), "cannot_connect"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_import_connection_errors(
|
|
||||||
hass: HomeAssistant, exception: Exception, error: str, mock_rova: MagicMock
|
|
||||||
) -> None:
|
|
||||||
"""Test import connection errors flow."""
|
|
||||||
|
|
||||||
# test with HTTPError
|
|
||||||
mock_rova.return_value.is_rova_area.side_effect = exception
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_ZIP_CODE: ZIP_CODE,
|
|
||||||
CONF_HOUSE_NUMBER: HOUSE_NUMBER,
|
|
||||||
CONF_HOUSE_NUMBER_SUFFIX: HOUSE_NUMBER_SUFFIX,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result.get("type") is FlowResultType.ABORT
|
|
||||||
assert result.get("reason") == error
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user