Remove yaml import from imap integration (#89981)
* Remove yaml import from imap integration * Cleanup sensor code and strings.json
This commit is contained in:
parent
9a5ceb9ef8
commit
e4275a053c
4 changed files with 6 additions and 110 deletions
|
@ -9,7 +9,7 @@ from aioimaplib import AioImapException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
|
@ -87,8 +87,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
)
|
)
|
||||||
|
|
||||||
if not (errors := await validate_input(user_input)):
|
if not (errors := await validate_input(user_input)):
|
||||||
# To be removed when YAML import is removed
|
title = user_input[CONF_USERNAME]
|
||||||
title = user_input.get(CONF_NAME, user_input[CONF_USERNAME])
|
|
||||||
|
|
||||||
return self.async_create_entry(title=title, data=user_input)
|
return self.async_create_entry(title=title, data=user_input)
|
||||||
|
|
||||||
|
@ -96,10 +95,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult:
|
|
||||||
"""Import a config entry from configuration.yaml."""
|
|
||||||
return await self.async_step_user(import_config)
|
|
||||||
|
|
||||||
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
|
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
||||||
|
|
|
@ -1,67 +1,17 @@
|
||||||
"""IMAP sensor support."""
|
"""IMAP sensor support."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import voluptuous as vol
|
from homeassistant.components.sensor import SensorEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.const import CONF_NAME, CONF_USERNAME
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import ImapPollingDataUpdateCoordinator, ImapPushDataUpdateCoordinator
|
from . import ImapPollingDataUpdateCoordinator, ImapPushDataUpdateCoordinator
|
||||||
from .const import (
|
from .const import DOMAIN
|
||||||
CONF_CHARSET,
|
|
||||||
CONF_FOLDER,
|
|
||||||
CONF_SEARCH,
|
|
||||||
CONF_SERVER,
|
|
||||||
DEFAULT_PORT,
|
|
||||||
DOMAIN,
|
|
||||||
)
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Optional(CONF_NAME): cv.string,
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Required(CONF_SERVER): cv.string,
|
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
|
||||||
vol.Optional(CONF_CHARSET, default="utf-8"): cv.string,
|
|
||||||
vol.Optional(CONF_FOLDER, default="INBOX"): cv.string,
|
|
||||||
vol.Optional(CONF_SEARCH, default="UnSeen UnDeleted"): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the IMAP platform."""
|
|
||||||
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(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -30,11 +30,5 @@
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"issues": {
|
|
||||||
"deprecated_yaml": {
|
|
||||||
"title": "The IMAP YAML configuration is being removed",
|
|
||||||
"description": "Configuring IMAP using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the IMAP YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,49 +59,6 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_success(hass: HomeAssistant) -> None:
|
|
||||||
"""Test a successful import of yaml."""
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.imap.config_flow.connect_to_server"
|
|
||||||
) as mock_client, patch(
|
|
||||||
"homeassistant.components.imap.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
) as mock_setup_entry:
|
|
||||||
mock_client.return_value.search.return_value = (
|
|
||||||
"OK",
|
|
||||||
[b""],
|
|
||||||
)
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
"name": "IMAP",
|
|
||||||
"username": "email@email.com",
|
|
||||||
"password": "password",
|
|
||||||
"server": "imap.server.com",
|
|
||||||
"port": 993,
|
|
||||||
"charset": "utf-8",
|
|
||||||
"folder": "INBOX",
|
|
||||||
"search": "UnSeen UnDeleted",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
|
||||||
assert result2["title"] == "IMAP"
|
|
||||||
assert result2["data"] == {
|
|
||||||
"name": "IMAP",
|
|
||||||
"username": "email@email.com",
|
|
||||||
"password": "password",
|
|
||||||
"server": "imap.server.com",
|
|
||||||
"port": 993,
|
|
||||||
"charset": "utf-8",
|
|
||||||
"folder": "INBOX",
|
|
||||||
"search": "UnSeen UnDeleted",
|
|
||||||
}
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_already_configured(hass: HomeAssistant) -> None:
|
async def test_entry_already_configured(hass: HomeAssistant) -> None:
|
||||||
"""Test aborting if the entry is already configured."""
|
"""Test aborting if the entry is already configured."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG)
|
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue