From d5f4e512e9448a0ad37da55871754d01d910b29d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 31 Mar 2022 11:16:55 -0700 Subject: [PATCH] Solax: remove deprecated YAML import (#69003) --- homeassistant/components/solax/config_flow.py | 11 ----- homeassistant/components/solax/sensor.py | 41 +------------------ tests/components/solax/test_config_flow.py | 39 ------------------ 3 files changed, 2 insertions(+), 89 deletions(-) diff --git a/homeassistant/components/solax/config_flow.py b/homeassistant/components/solax/config_flow.py index 5c4ef05da4b..56c6989cc7f 100644 --- a/homeassistant/components/solax/config_flow.py +++ b/homeassistant/components/solax/config_flow.py @@ -63,14 +63,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_show_form( step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors ) - - async def async_step_import(self, config: dict[str, Any]) -> FlowResult: - """Handle import of solax config from YAML.""" - - import_data = { - CONF_IP_ADDRESS: config[CONF_IP_ADDRESS], - CONF_PORT: config[CONF_PORT], - CONF_PASSWORD: DEFAULT_PASSWORD, - } - - return await self.async_step_user(user_input=import_data) diff --git a/homeassistant/components/solax/sensor.py b/homeassistant/components/solax/sensor.py index 6f1b5ef6cf3..7f9d81ac9b0 100644 --- a/homeassistant/components/solax/sensor.py +++ b/homeassistant/components/solax/sensor.py @@ -3,38 +3,25 @@ from __future__ import annotations import asyncio from datetime import timedelta -import logging from solax.inverter import InverterError -import voluptuous as vol from homeassistant.components.sensor import ( - PLATFORM_SCHEMA, SensorDeviceClass, SensorEntity, SensorStateClass, ) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, TEMP_CELSIUS +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import TEMP_CELSIUS from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from .const import DOMAIN, MANUFACTURER -_LOGGER = logging.getLogger(__name__) - DEFAULT_PORT = 80 -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_IP_ADDRESS): cv.string, - vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, - }, -) SCAN_INTERVAL = timedelta(seconds=30) @@ -81,30 +68,6 @@ async def async_setup_entry( async_add_entities(devices) -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Platform setup.""" - - _LOGGER.warning( - "Configuration of the SolaX Power platform in YAML is deprecated and " - "will be removed in Home Assistant 2022.4; Your existing configuration " - "has been imported into the UI automatically and can be safely removed " - "from your configuration.yaml file" - ) - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=config, - ) - ) - - class RealTimeDataEndpoint: """Representation of a Sensor.""" diff --git a/tests/components/solax/test_config_flow.py b/tests/components/solax/test_config_flow.py index 56db8d3f6cb..cb658405860 100644 --- a/tests/components/solax/test_config_flow.py +++ b/tests/components/solax/test_config_flow.py @@ -90,42 +90,3 @@ async def test_form_unknown_error(hass): assert entry_result["type"] == "form" assert entry_result["errors"] == {"base": "unknown"} - - -async def test_import_success(hass): - """Test import success.""" - conf = {CONF_IP_ADDRESS: "192.168.1.87", CONF_PORT: 80} - with patch( - "homeassistant.components.solax.config_flow.real_time_api", - return_value=__mock_real_time_api_success(), - ), patch("solax.RealTimeAPI.get_data", return_value=__mock_get_data()), patch( - "homeassistant.components.solax.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - entry_result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf - ) - - assert entry_result["type"] == "create_entry" - assert entry_result["title"] == "ABCDEFGHIJ" - assert entry_result["data"] == { - CONF_IP_ADDRESS: "192.168.1.87", - CONF_PORT: 80, - CONF_PASSWORD: "", - } - assert len(mock_setup_entry.mock_calls) == 1 - - -async def test_import_error(hass): - """Test import success.""" - conf = {CONF_IP_ADDRESS: "192.168.1.87", CONF_PORT: 80} - with patch( - "homeassistant.components.solax.config_flow.real_time_api", - side_effect=ConnectionError, - ): - entry_result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf - ) - - assert entry_result["type"] == "form" - assert entry_result["errors"] == {"base": "cannot_connect"}