Remove YAML import for Suez Water (#119923)

Remove YAML import for suez water
This commit is contained in:
G Johansson 2024-06-18 22:26:10 +02:00 committed by GitHub
parent adcd0cc2a4
commit 08864959ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 4 additions and 172 deletions

View File

@ -75,21 +75,6 @@ class SuezWaterConfigFlow(ConfigFlow, domain=DOMAIN):
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
"""Import the yaml config."""
await self.async_set_unique_id(user_input[CONF_USERNAME])
self._abort_if_unique_id_configured()
try:
await self.hass.async_add_executor_job(validate_input, user_input)
except CannotConnect:
return self.async_abort(reason="cannot_connect")
except InvalidAuth:
return self.async_abort(reason="invalid_auth")
except Exception:
_LOGGER.exception("Unexpected exception")
return self.async_abort(reason="unknown")
return self.async_create_entry(title=user_input[CONF_USERNAME], data=user_input)
class CannotConnect(HomeAssistantError):
"""Error to indicate we cannot connect."""

View File

@ -7,82 +7,20 @@ import logging
from pysuez import SuezClient
from pysuez.client import PySuezError
import voluptuous as vol
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, UnitOfVolume
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.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfVolume
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
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 .const import CONF_COUNTER_ID, DOMAIN
_LOGGER = logging.getLogger(__name__)
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=suez_water"}
SCAN_INTERVAL = timedelta(hours=12)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_COUNTER_ID): cv.string,
}
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the sensor platform."""
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.7.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Suez Water",
},
)
else:
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=ISSUE_PLACEHOLDER,
)
async def async_setup_entry(
hass: HomeAssistant,

View File

@ -24,19 +24,5 @@
"name": "Water usage yesterday"
}
}
},
"issues": {
"deprecated_yaml_import_issue_invalid_auth": {
"title": "The Suez water YAML configuration import failed",
"description": "Configuring Suez water using YAML is being removed but there was an authentication error importing your YAML configuration.\n\nCorrect the YAML configuration and restart Home Assistant to try again or remove the Suez water YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
},
"deprecated_yaml_import_issue_cannot_connect": {
"title": "The Suez water YAML configuration import failed",
"description": "Configuring Suez water using YAML is being removed but there was a connection error importing your YAML configuration.\n\nEnsure connection to Suez water works and restart Home Assistant to try again or remove the Suez water YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
},
"deprecated_yaml_import_issue_unknown": {
"title": "The Suez water YAML configuration import failed",
"description": "Configuring Suez water using YAML is being removed but there was an unknown error when trying to import the YAML configuration.\n\nEnsure the imported configuration is correct and remove the Suez water YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
}
}
}

View File

@ -139,80 +139,3 @@ async def test_form_error(
assert result["title"] == "test-username"
assert result["data"] == MOCK_DATA
assert len(mock_setup_entry.mock_calls) == 1
async def test_import(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""Test import flow."""
with patch("homeassistant.components.suez_water.config_flow.SuezClient"):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=MOCK_DATA
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "test-username"
assert result["result"].unique_id == "test-username"
assert result["data"] == MOCK_DATA
assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.parametrize(
("exception", "reason"), [(PySuezError, "cannot_connect"), (Exception, "unknown")]
)
async def test_import_error(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
exception: Exception,
reason: str,
) -> None:
"""Test we handle errors while importing."""
with patch(
"homeassistant.components.suez_water.config_flow.SuezClient",
side_effect=exception,
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=MOCK_DATA
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == reason
async def test_importing_invalid_auth(hass: HomeAssistant) -> None:
"""Test we handle invalid auth when importing."""
with (
patch(
"homeassistant.components.suez_water.config_flow.SuezClient.__init__",
return_value=None,
),
patch(
"homeassistant.components.suez_water.config_flow.SuezClient.check_credentials",
return_value=False,
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=MOCK_DATA
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "invalid_auth"
async def test_import_already_configured(hass: HomeAssistant) -> None:
"""Test we abort import when entry is already configured."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="test-username",
data=MOCK_DATA,
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=MOCK_DATA
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"