diff --git a/homeassistant/components/hydrawise/__init__.py b/homeassistant/components/hydrawise/__init__.py index 541d4211e49..62a4cacc5c4 100644 --- a/homeassistant/components/hydrawise/__init__.py +++ b/homeassistant/components/hydrawise/__init__.py @@ -1,52 +1,17 @@ """Support for Hydrawise cloud.""" from pydrawise import legacy -import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import ( - CONF_ACCESS_TOKEN, - CONF_API_KEY, - CONF_SCAN_INTERVAL, - Platform, -) +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_API_KEY, Platform from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.typing import ConfigType from .const import DOMAIN, SCAN_INTERVAL from .coordinator import HydrawiseDataUpdateCoordinator -CONFIG_SCHEMA = vol.Schema( - { - DOMAIN: vol.Schema( - { - vol.Required(CONF_ACCESS_TOKEN): cv.string, - vol.Optional(CONF_SCAN_INTERVAL, default=SCAN_INTERVAL): cv.time_period, - } - ) - }, - extra=vol.ALLOW_EXTRA, -) - PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.SWITCH] -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the Hunter Hydrawise component.""" - if DOMAIN not in config: - return True - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={CONF_API_KEY: config[DOMAIN][CONF_ACCESS_TOKEN]}, - ) - ) - return True - - async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up Hydrawise from a config entry.""" access_token = config_entry.data[CONF_API_KEY] diff --git a/homeassistant/components/hydrawise/config_flow.py b/homeassistant/components/hydrawise/config_flow.py index cfaaefcd03a..8233074c3cd 100644 --- a/homeassistant/components/hydrawise/config_flow.py +++ b/homeassistant/components/hydrawise/config_flow.py @@ -11,9 +11,6 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_API_KEY -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN -from homeassistant.data_entry_flow import AbortFlow, FlowResultType -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from .const import DOMAIN, LOGGER @@ -42,40 +39,6 @@ class HydrawiseConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_create_entry(title="Hydrawise", data={CONF_API_KEY: api_key}) - def _import_issue(self, error_type: str) -> ConfigFlowResult: - """Create an issue about a YAML import failure.""" - async_create_issue( - self.hass, - DOMAIN, - f"deprecated_yaml_import_issue_{error_type}", - breaks_in_ha_version="2024.4.0", - is_fixable=False, - severity=IssueSeverity.ERROR, - translation_key="deprecated_yaml_import_issue", - translation_placeholders={ - "error_type": error_type, - "url": "/config/integrations/dashboard/add?domain=hydrawise", - }, - ) - return self.async_abort(reason=error_type) - - def _deprecated_yaml_issue(self) -> None: - """Create an issue about YAML deprecation.""" - 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": "Hydrawise", - }, - ) - async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: @@ -94,18 +57,3 @@ class HydrawiseConfigFlow(ConfigFlow, domain=DOMAIN): data_schema=vol.Schema({vol.Required(CONF_API_KEY): str}), errors=errors, ) - - async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult: - """Import data from YAML.""" - try: - result = await self._create_entry( - import_data.get(CONF_API_KEY, ""), - on_failure=self._import_issue, - ) - except AbortFlow: - self._deprecated_yaml_issue() - raise - - if result["type"] == FlowResultType.CREATE_ENTRY: - self._deprecated_yaml_issue() - return result diff --git a/homeassistant/components/hydrawise/strings.json b/homeassistant/components/hydrawise/strings.json index 8f079abcc7d..1c96098db35 100644 --- a/homeassistant/components/hydrawise/strings.json +++ b/homeassistant/components/hydrawise/strings.json @@ -16,12 +16,6 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_service%]" } }, - "issues": { - "deprecated_yaml_import_issue": { - "title": "The Hydrawise YAML configuration import failed", - "description": "Configuring Hydrawise using YAML is being removed but there was an {error_type} error importing your YAML configuration.\n\nEnsure connection to Hydrawise works and restart Home Assistant to try again or remove the Hydrawise YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually." - } - }, "entity": { "binary_sensor": { "watering": { diff --git a/tests/components/hydrawise/test_config_flow.py b/tests/components/hydrawise/test_config_flow.py index b0d5b098309..be0ef90becd 100644 --- a/tests/components/hydrawise/test_config_flow.py +++ b/tests/components/hydrawise/test_config_flow.py @@ -8,12 +8,8 @@ import pytest from homeassistant import config_entries from homeassistant.components.hydrawise.const import DOMAIN -from homeassistant.const import CONF_API_KEY, CONF_SCAN_INTERVAL -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant +from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType -import homeassistant.helpers.issue_registry as ir - -from tests.common import MockConfigEntry pytestmark = pytest.mark.usefixtures("mock_setup_entry") @@ -87,115 +83,3 @@ async def test_form_connect_timeout( mock_pydrawise.get_user.return_value = user result2 = await hass.config_entries.flow.async_configure(result["flow_id"], data) assert result2["type"] is FlowResultType.CREATE_ENTRY - - -async def test_flow_import_success( - hass: HomeAssistant, mock_pydrawise: AsyncMock, user: User -) -> None: - """Test that we can import a YAML config.""" - mock_pydrawise.get_user.return_value = User - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - CONF_API_KEY: "__api_key__", - CONF_SCAN_INTERVAL: 120, - }, - ) - await hass.async_block_till_done() - - assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "Hydrawise" - assert result["data"] == { - CONF_API_KEY: "__api_key__", - } - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue( - HOMEASSISTANT_DOMAIN, "deprecated_yaml_hydrawise" - ) - assert issue.translation_key == "deprecated_yaml" - - -async def test_flow_import_api_error( - hass: HomeAssistant, mock_pydrawise: AsyncMock -) -> None: - """Test that we handle API errors on YAML import.""" - mock_pydrawise.get_user.side_effect = ClientError - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - CONF_API_KEY: "__api_key__", - CONF_SCAN_INTERVAL: 120, - }, - ) - await hass.async_block_till_done() - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "cannot_connect" - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue( - DOMAIN, "deprecated_yaml_import_issue_cannot_connect" - ) - assert issue.translation_key == "deprecated_yaml_import_issue" - - -async def test_flow_import_connect_timeout( - hass: HomeAssistant, mock_pydrawise: AsyncMock -) -> None: - """Test that we handle connection timeouts on YAML import.""" - mock_pydrawise.get_user.side_effect = TimeoutError - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - CONF_API_KEY: "__api_key__", - CONF_SCAN_INTERVAL: 120, - }, - ) - await hass.async_block_till_done() - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "timeout_connect" - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue( - DOMAIN, "deprecated_yaml_import_issue_timeout_connect" - ) - assert issue.translation_key == "deprecated_yaml_import_issue" - - -async def test_flow_import_already_imported( - hass: HomeAssistant, mock_pydrawise: AsyncMock, user: User -) -> None: - """Test that we can handle a YAML config already imported.""" - mock_config_entry = MockConfigEntry( - title="Hydrawise", - domain=DOMAIN, - data={ - CONF_API_KEY: "__api_key__", - }, - unique_id="hydrawise-12345", - ) - mock_config_entry.add_to_hass(hass) - - mock_pydrawise.get_user.return_value = user - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - CONF_API_KEY: "__api_key__", - CONF_SCAN_INTERVAL: 120, - }, - ) - await hass.async_block_till_done() - - assert result["type"] is FlowResultType.ABORT - assert result.get("reason") == "already_configured" - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue( - HOMEASSISTANT_DOMAIN, "deprecated_yaml_hydrawise" - ) - assert issue.translation_key == "deprecated_yaml" diff --git a/tests/components/hydrawise/test_init.py b/tests/components/hydrawise/test_init.py index 6b41867b044..91c99833531 100644 --- a/tests/components/hydrawise/test_init.py +++ b/tests/components/hydrawise/test_init.py @@ -5,29 +5,11 @@ from unittest.mock import AsyncMock from aiohttp import ClientError from homeassistant.config_entries import ConfigEntryState -from homeassistant.const import CONF_ACCESS_TOKEN -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant -import homeassistant.helpers.issue_registry as ir -from homeassistant.setup import async_setup_component +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry -async def test_setup_import_success( - hass: HomeAssistant, mock_pydrawise: AsyncMock -) -> None: - """Test that setup with a YAML config triggers an import and warning.""" - config = {"hydrawise": {CONF_ACCESS_TOKEN: "_access-token_"}} - assert await async_setup_component(hass, "hydrawise", config) - await hass.async_block_till_done() - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue( - HOMEASSISTANT_DOMAIN, "deprecated_yaml_hydrawise" - ) - assert issue.translation_key == "deprecated_yaml" - - async def test_connect_retry( hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_pydrawise: AsyncMock ) -> None: