From 26faac05678e77b455e19bedf2b41fc6b2713656 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 14 Oct 2021 08:46:39 +0200 Subject: [PATCH] Remove YAML configuration from Rainforest Eagle (#57636) --- .../rainforest_eagle/config_flow.py | 6 -- .../components/rainforest_eagle/sensor.py | 50 +-------------- .../components/rainforest_eagle/test_init.py | 64 ------------------- 3 files changed, 2 insertions(+), 118 deletions(-) delete mode 100644 tests/components/rainforest_eagle/test_init.py diff --git a/homeassistant/components/rainforest_eagle/config_flow.py b/homeassistant/components/rainforest_eagle/config_flow.py index be921c31bf7..f1e01a9d77a 100644 --- a/homeassistant/components/rainforest_eagle/config_flow.py +++ b/homeassistant/components/rainforest_eagle/config_flow.py @@ -72,9 +72,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_show_form( step_id="user", data_schema=create_schema(user_input), errors=errors ) - - async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult: - """Handle the import step.""" - await self.async_set_unique_id(user_input[CONF_CLOUD_ID]) - self._abort_if_unique_id_configured() - return await self.async_step_user(user_input) diff --git a/homeassistant/components/rainforest_eagle/sensor.py b/homeassistant/components/rainforest_eagle/sensor.py index 6f6b496cfca..35864e55fa4 100644 --- a/homeassistant/components/rainforest_eagle/sensor.py +++ b/homeassistant/components/rainforest_eagle/sensor.py @@ -1,40 +1,28 @@ """Support for the Rainforest Eagle energy monitor.""" from __future__ import annotations -import logging -from typing import Any - -import voluptuous as vol - from homeassistant.components.sensor import ( DEVICE_CLASS_ENERGY, - PLATFORM_SCHEMA, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, SensorEntity, SensorEntityDescription, StateType, ) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - CONF_HOST, - CONF_IP_ADDRESS, DEVICE_CLASS_POWER, ENERGY_KILO_WATT_HOUR, POWER_KILO_WATT, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.update_coordinator import CoordinatorEntity -from .const import CONF_CLOUD_ID, CONF_INSTALL_CODE, DOMAIN +from .const import DOMAIN from .data import EagleDataCoordinator -_LOGGER = logging.getLogger(__name__) - SENSORS = ( SensorEntityDescription( key="zigbee:InstantaneousDemand", @@ -60,40 +48,6 @@ SENSORS = ( ), ) -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_IP_ADDRESS): cv.string, - vol.Required(CONF_CLOUD_ID): cv.string, - vol.Required(CONF_INSTALL_CODE): cv.string, - } -) - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: dict[str, Any] | None = None, -): - """Import config as config entry.""" - _LOGGER.warning( - "Configuration of the rainforest_eagle platform in YAML is deprecated " - "and will be removed in Home Assistant 2021.11; 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={ - CONF_HOST: config[CONF_IP_ADDRESS], - CONF_CLOUD_ID: config[CONF_CLOUD_ID], - CONF_INSTALL_CODE: config[CONF_INSTALL_CODE], - }, - ) - ) - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback diff --git a/tests/components/rainforest_eagle/test_init.py b/tests/components/rainforest_eagle/test_init.py deleted file mode 100644 index f4ce029231a..00000000000 --- a/tests/components/rainforest_eagle/test_init.py +++ /dev/null @@ -1,64 +0,0 @@ -"""Tests for the Rainforest Eagle integration.""" -from unittest.mock import patch - -from homeassistant import config_entries -from homeassistant.components.rainforest_eagle.const import ( - CONF_CLOUD_ID, - CONF_HARDWARE_ADDRESS, - CONF_INSTALL_CODE, - DOMAIN, - TYPE_EAGLE_200, -) -from homeassistant.const import CONF_HOST, CONF_TYPE -from homeassistant.core import HomeAssistant -from homeassistant.data_entry_flow import RESULT_TYPE_ABORT -from homeassistant.setup import async_setup_component - - -async def test_import(hass: HomeAssistant) -> None: - """Test we get the form.""" - - with patch( - "homeassistant.components.rainforest_eagle.data.async_get_type", - return_value=(TYPE_EAGLE_200, "mock-hw"), - ), patch( - "homeassistant.components.rainforest_eagle.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - await async_setup_component( - hass, - "sensor", - { - "sensor": { - "platform": DOMAIN, - "ip_address": "192.168.1.55", - CONF_CLOUD_ID: "abcdef", - CONF_INSTALL_CODE: "123456", - } - }, - ) - await hass.async_block_till_done() - - entries = hass.config_entries.async_entries(DOMAIN) - assert len(entries) == 1 - entry = entries[0] - - assert entry.title == "abcdef" - assert entry.data == { - CONF_TYPE: TYPE_EAGLE_200, - CONF_HOST: "192.168.1.55", - CONF_CLOUD_ID: "abcdef", - CONF_INSTALL_CODE: "123456", - CONF_HARDWARE_ADDRESS: "mock-hw", - } - assert len(mock_setup_entry.mock_calls) == 1 - - # Second time we should get already_configured - result2 = await hass.config_entries.flow.async_init( - DOMAIN, - data={CONF_CLOUD_ID: "abcdef", CONF_INSTALL_CODE: "123456"}, - context={"source": config_entries.SOURCE_IMPORT}, - ) - - assert result2["type"] == RESULT_TYPE_ABORT - assert result2["reason"] == "already_configured"