Skip to content

Commit

Permalink
Remove EDL21 YAML configuration (#93551)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed May 26, 2023
1 parent 3633062 commit 1f467fc
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 86 deletions.
13 changes: 0 additions & 13 deletions homeassistant/components/edl21/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""Config flow for EDL21 integration."""
from typing import Any

import voluptuous as vol

from homeassistant import config_entries
from homeassistant.const import CONF_NAME
from homeassistant.data_entry_flow import FlowResult

from .const import CONF_SERIAL_PORT, DEFAULT_TITLE, DOMAIN
Expand All @@ -21,17 +19,6 @@ class EDL21ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult:
"""Import a config entry from configuration.yaml."""

self._async_abort_entries_match(
{CONF_SERIAL_PORT: import_config[CONF_SERIAL_PORT]}
)
return self.async_create_entry(
title=import_config[CONF_NAME] or DEFAULT_TITLE,
data=import_config,
)

async def async_step_user(
self, user_input: dict[str, str] | None = None
) -> FlowResult:
Expand Down
39 changes: 1 addition & 38 deletions homeassistant/components/edl21/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

from sml import SmlGetListResponse
from sml.asyncio import SmlProtocol
import voluptuous as vol

from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_NAME,
DEGREE,
Expand All @@ -27,15 +25,12 @@
UnitOfPower,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.entity import DeviceInfo
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 homeassistant.util.dt import utcnow

from .const import (
Expand All @@ -48,13 +43,6 @@

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_SERIAL_PORT): cv.string,
vol.Optional(CONF_NAME, default=""): cv.string,
},
)

# OBIS format: A-B:C.D.E*F
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
# A=1: Electricity
Expand Down Expand Up @@ -279,31 +267,6 @@
}


async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up EDL21 sensors via configuration.yaml and show deprecation warning."""
async_create_issue(
hass,
DOMAIN,
"deprecated_yaml",
breaks_in_ha_version="2023.6.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,
config_entry: ConfigEntry,
Expand Down
6 changes: 0 additions & 6 deletions homeassistant/components/edl21/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,5 @@
}
}
}
},
"issues": {
"deprecated_yaml": {
"title": "EDL21 YAML configuration is being removed",
"description": "Configuring EDL21 using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the EDL21 YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
}
}
30 changes: 1 addition & 29 deletions tests/components/edl21/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from homeassistant.components.edl21.const import CONF_SERIAL_PORT, DEFAULT_TITLE, DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -51,31 +51,3 @@ async def test_integration_already_exists(hass: HomeAssistant) -> None:

assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"


async def test_create_entry_by_import(hass: HomeAssistant) -> None:
"""Test that the import step works."""

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=VALID_LEGACY_CONFIG,
)

assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == VALID_LEGACY_CONFIG[CONF_NAME]
assert result["data"][CONF_NAME] == VALID_LEGACY_CONFIG[CONF_NAME]
assert result["data"][CONF_SERIAL_PORT] == VALID_LEGACY_CONFIG[CONF_SERIAL_PORT]

# Test the import step with an empty string as name
# (the name is optional in the old schema and defaults to "")
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_SERIAL_PORT: "/dev/ttyUSB2", CONF_NAME: ""},
)

assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == DEFAULT_TITLE
assert result["data"][CONF_NAME] == ""
assert result["data"][CONF_SERIAL_PORT] == "/dev/ttyUSB2"

0 comments on commit 1f467fc

Please sign in to comment.