Remove deprecated yaml config from enphase envoy (#61840)
This commit is contained in:
parent
5372871727
commit
cc3a4fef53
3 changed files with 2 additions and 102 deletions
|
@ -11,13 +11,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
@ -60,7 +54,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
def __init__(self):
|
||||
"""Initialize an envoy flow."""
|
||||
self.ip_address = None
|
||||
self.name = None
|
||||
self.username = None
|
||||
self._reauth_entry = None
|
||||
|
||||
|
@ -80,19 +73,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
schema[vol.Optional(CONF_PASSWORD, default="")] = str
|
||||
return vol.Schema(schema)
|
||||
|
||||
async def async_step_import(self, import_config):
|
||||
"""Handle a flow import."""
|
||||
self.ip_address = import_config[CONF_IP_ADDRESS]
|
||||
self.username = import_config[CONF_USERNAME]
|
||||
self.name = import_config[CONF_NAME]
|
||||
return await self.async_step_user(
|
||||
{
|
||||
CONF_HOST: import_config[CONF_IP_ADDRESS],
|
||||
CONF_USERNAME: import_config[CONF_USERNAME],
|
||||
CONF_PASSWORD: import_config[CONF_PASSWORD],
|
||||
}
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_current_hosts(self):
|
||||
"""Return a set of hosts."""
|
||||
|
@ -136,8 +116,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
def _async_envoy_name(self) -> str:
|
||||
"""Return the name of the envoy."""
|
||||
if self.name:
|
||||
return self.name
|
||||
if self.unique_id:
|
||||
return f"{ENVOY} {self.unique_id}"
|
||||
return ENVOY
|
||||
|
|
|
@ -1,55 +1,13 @@
|
|||
"""Support for Enphase Envoy solar energy monitor."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import (
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import COORDINATOR, DOMAIN, NAME, SENSORS
|
||||
|
||||
ICON = "mdi:flash"
|
||||
CONST_DEFAULT_HOST = "envoy"
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSOR_KEYS: list[str] = [desc.key for desc in SENSORS]
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_IP_ADDRESS, default=CONST_DEFAULT_HOST): cv.string,
|
||||
vol.Optional(CONF_USERNAME, default="envoy"): cv.string,
|
||||
vol.Optional(CONF_PASSWORD, default=""): cv.string,
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=SENSOR_KEYS): vol.All(
|
||||
cv.ensure_list, [vol.In(SENSOR_KEYS)]
|
||||
),
|
||||
vol.Optional(CONF_NAME, default=""): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Enphase Envoy sensor."""
|
||||
_LOGGER.warning(
|
||||
"Loading enphase_envoy via platform config is deprecated; The configuration"
|
||||
" has been migrated to a config entry and can be safely removed"
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
|
|
@ -204,42 +204,6 @@ async def test_form_unknown_error(hass: HomeAssistant) -> None:
|
|||
assert result2["errors"] == {"base": "unknown"}
|
||||
|
||||
|
||||
async def test_import(hass: HomeAssistant) -> None:
|
||||
"""Test we can import from yaml."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.enphase_envoy.config_flow.EnvoyReader.getData",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.enphase_envoy.config_flow.EnvoyReader.get_full_serial_number",
|
||||
return_value="1234",
|
||||
), patch(
|
||||
"homeassistant.components.enphase_envoy.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
"ip_address": "1.1.1.1",
|
||||
"name": "Pool Envoy",
|
||||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "Pool Envoy"
|
||||
assert result2["data"] == {
|
||||
"host": "1.1.1.1",
|
||||
"name": "Pool Envoy",
|
||||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_zeroconf(hass: HomeAssistant) -> None:
|
||||
"""Test we can setup from zeroconf."""
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue