From d66305ddd3ca175d5d48e7454c285c9d6509de1d Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 7 May 2023 00:01:58 +0200 Subject: [PATCH] Remove dlink yaml import (#92590) --- homeassistant/components/dlink/config_flow.py | 11 +--- homeassistant/components/dlink/switch.py | 65 ++----------------- homeassistant/components/lyric/strings.json | 6 -- tests/components/dlink/test_config_flow.py | 16 +---- tests/components/dlink/test_switch.py | 51 ++++++--------- 5 files changed, 27 insertions(+), 122 deletions(-) diff --git a/homeassistant/components/dlink/config_flow.py b/homeassistant/components/dlink/config_flow.py index 4499e2efffc..09df5571a78 100644 --- a/homeassistant/components/dlink/config_flow.py +++ b/homeassistant/components/dlink/config_flow.py @@ -9,7 +9,7 @@ import voluptuous as vol from homeassistant import config_entries from homeassistant.components import dhcp -from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME +from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.data_entry_flow import FlowResult from .const import CONF_USE_LEGACY_PROTOCOL, DEFAULT_NAME, DEFAULT_USERNAME, DOMAIN @@ -72,15 +72,6 @@ class DLinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): errors=errors, ) - async def async_step_import(self, config: dict[str, Any]) -> FlowResult: - """Import a config entry.""" - self._async_abort_entries_match({CONF_HOST: config[CONF_HOST]}) - title = config.pop(CONF_NAME, DEFAULT_NAME) - return self.async_create_entry( - title=title, - data=config, - ) - async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> FlowResult: diff --git a/homeassistant/components/dlink/switch.py b/homeassistant/components/dlink/switch.py index e6b9a4c7883..d06372bb28b 100644 --- a/homeassistant/components/dlink/switch.py +++ b/homeassistant/components/dlink/switch.py @@ -4,80 +4,23 @@ from __future__ import annotations from datetime import timedelta from typing import Any -import voluptuous as vol - -from homeassistant.components.switch import ( - PLATFORM_SCHEMA, - SwitchEntity, - SwitchEntityDescription, -) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import ( - ATTR_TEMPERATURE, - CONF_HOST, - CONF_NAME, - CONF_PASSWORD, - CONF_USERNAME, - UnitOfTemperature, -) +from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv 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 ( - ATTR_TOTAL_CONSUMPTION, - CONF_USE_LEGACY_PROTOCOL, - DEFAULT_NAME, - DEFAULT_USERNAME, - DOMAIN, -) +from .const import ATTR_TOTAL_CONSUMPTION, DOMAIN from .entity import DLinkEntity SCAN_INTERVAL = timedelta(minutes=2) -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_HOST): cv.string, - vol.Required(CONF_PASSWORD, default=""): cv.string, - vol.Required(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_USE_LEGACY_PROTOCOL, default=False): cv.boolean, - } -) - SWITCH_TYPE = SwitchEntityDescription( key="switch", name="Switch", ) -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up a D-Link Smart Plug.""" - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml", - breaks_in_ha_version="2023.4.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - ) - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=config, - ) - ) - - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: diff --git a/homeassistant/components/lyric/strings.json b/homeassistant/components/lyric/strings.json index dd9a89f294d..3c9cd6043df 100644 --- a/homeassistant/components/lyric/strings.json +++ b/homeassistant/components/lyric/strings.json @@ -17,11 +17,5 @@ "create_entry": { "default": "[%key:common::config_flow::create_entry::authenticated%]" } - }, - "issues": { - "removed_yaml": { - "title": "The Honeywell Lyric YAML configuration has been removed", - "description": "Configuring Honeywell Lyric using YAML has been removed.\n\nYour existing YAML configuration is not used by Home Assistant.\n\nRemove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue." - } } } diff --git a/tests/components/dlink/test_config_flow.py b/tests/components/dlink/test_config_flow.py index e9ee29134aa..5cd34987646 100644 --- a/tests/components/dlink/test_config_flow.py +++ b/tests/components/dlink/test_config_flow.py @@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch from homeassistant import data_entry_flow from homeassistant.components import dhcp from homeassistant.components.dlink.const import DEFAULT_NAME, DOMAIN -from homeassistant.config_entries import SOURCE_DHCP, SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER from homeassistant.const import CONF_HOST from homeassistant.core import HomeAssistant @@ -13,7 +13,6 @@ from .conftest import ( CONF_DHCP_DATA, CONF_DHCP_FLOW, CONF_DHCP_FLOW_NEW_IP, - CONF_IMPORT_DATA, patch_config_flow, ) @@ -99,19 +98,6 @@ async def test_flow_user_unknown_error( assert result["data"] == CONF_DATA -async def test_import(hass: HomeAssistant, mocked_plug: MagicMock) -> None: - """Test import initialized flow.""" - with patch_config_flow(mocked_plug), _patch_setup_entry(): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=CONF_IMPORT_DATA, - ) - assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY - assert result["title"] == "Smart Plug" - assert result["data"] == CONF_DATA - - async def test_dhcp(hass: HomeAssistant, mocked_plug: MagicMock) -> None: """Test we can process the discovery from dhcp.""" result = await hass.config_entries.flow.async_init( diff --git a/tests/components/dlink/test_switch.py b/tests/components/dlink/test_switch.py index 683d30be7f6..24316006b5e 100644 --- a/tests/components/dlink/test_switch.py +++ b/tests/components/dlink/test_switch.py @@ -1,4 +1,5 @@ """Switch tests for the D-Link Smart Plug integration.""" +from unittest.mock import patch from homeassistant.components.dlink import DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN @@ -10,39 +11,22 @@ from homeassistant.const import ( STATE_ON, ) from homeassistant.core import HomeAssistant -from homeassistant.setup import async_setup_component -from .conftest import ComponentSetup +from .conftest import CONF_DATA -from tests.components.repairs import get_repairs -from tests.typing import WebSocketGenerator +from tests.common import AsyncMock, MockConfigEntry -async def test_switch_state( - hass: HomeAssistant, - hass_ws_client: WebSocketGenerator, - setup_integration: ComponentSetup, -) -> None: +async def test_switch_state(hass: HomeAssistant, mocked_plug: AsyncMock) -> None: """Test we get the switch status.""" - assert await async_setup_component( - hass, - SWITCH_DOMAIN, - { - SWITCH_DOMAIN: { - "platform": DOMAIN, - "host": "1.2.3.4", - "username": "admin", - "password": "123456", - "use_legacy_protocol": True, - } - }, - ) - await hass.async_block_till_done() - issues = await get_repairs(hass, hass_ws_client) - assert len(issues) == 1 - assert issues[0]["issue_id"] == "deprecated_yaml" - - await setup_integration() + with patch( + "homeassistant.components.dlink.SmartPlug", + return_value=mocked_plug, + ): + entry = MockConfigEntry(domain=DOMAIN, data=CONF_DATA) + entry.add_to_hass(hass) + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() entity_id = "switch.mock_title_switch" state = hass.states.get(entity_id) @@ -66,10 +50,17 @@ async def test_switch_state( async def test_switch_no_value( - hass: HomeAssistant, setup_integration_legacy: ComponentSetup + hass: HomeAssistant, mocked_plug_legacy: AsyncMock ) -> None: """Test we handle 'N/A' being passed by the pypi package.""" - await setup_integration_legacy() + with patch( + "homeassistant.components.dlink.SmartPlug", + return_value=mocked_plug_legacy, + ): + entry = MockConfigEntry(domain=DOMAIN, data=CONF_DATA) + entry.add_to_hass(hass) + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() state = hass.states.get("switch.mock_title_switch") assert state.state == STATE_OFF