Remove YAML configuration from Rainforest Eagle (#57636)

This commit is contained in:
Franck Nijhof 2021-10-14 08:46:39 +02:00 committed by GitHub
parent 0da1f9544e
commit 26faac0567
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 118 deletions

View file

@ -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)

View file

@ -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

View file

@ -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"