Remove deprecated YAML configuration from Yale Smart Alarm (#69025)

pull/69031/head
Franck Nijhof 2022-03-31 22:09:24 +02:00 committed by GitHub
parent af6953157f
commit a9a14d6544
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 106 deletions

View File

@ -3,70 +3,28 @@ from __future__ import annotations
from typing import TYPE_CHECKING
import voluptuous as vol
from yalesmartalarmclient.const import (
YALE_STATE_ARM_FULL,
YALE_STATE_ARM_PARTIAL,
YALE_STATE_DISARM,
)
from homeassistant.components.alarm_control_panel import (
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
AlarmControlPanelEntity,
)
from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity
from homeassistant.components.alarm_control_panel.const import (
SUPPORT_ALARM_ARM_AWAY,
SUPPORT_ALARM_ARM_HOME,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_USERNAME
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
from homeassistant.helpers.typing import StateType
from .const import (
CONF_AREA_ID,
COORDINATOR,
DEFAULT_AREA_ID,
DEFAULT_NAME,
DOMAIN,
LOGGER,
STATE_MAP,
YALE_ALL_ERRORS,
)
from .const import COORDINATOR, DOMAIN, STATE_MAP, YALE_ALL_ERRORS
from .coordinator import YaleDataUpdateCoordinator
from .entity import YaleAlarmEntity
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_AREA_ID, default=DEFAULT_AREA_ID): cv.string,
}
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Import Yale configuration from YAML."""
LOGGER.warning(
"Loading Yale Alarm via platform setup is deprecated; Please remove it from your configuration"
)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=config,
)
)
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback

View File

@ -53,11 +53,6 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
"""Get the options flow for this handler."""
return YaleOptionsFlowHandler(config_entry)
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
"""Import a configuration from config.yaml."""
return await self.async_step_user(user_input=config)
async def async_step_reauth(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:

View File

@ -114,60 +114,6 @@ async def test_form_invalid_auth(
}
@pytest.mark.parametrize(
"p_input,p_output",
[
(
{
"username": "test-username",
"password": "test-password",
"area_id": "1",
},
{
"username": "test-username",
"password": "test-password",
"name": "Yale Smart Alarm",
"area_id": "1",
},
),
(
{
"username": "test-username",
"password": "test-password",
},
{
"username": "test-username",
"password": "test-password",
"name": "Yale Smart Alarm",
"area_id": "1",
},
),
],
)
async def test_import_flow_success(
hass, p_input: dict[str, str], p_output: dict[str, str]
):
"""Test a successful import of yaml."""
with patch(
"homeassistant.components.yale_smart_alarm.config_flow.YaleSmartAlarmClient",
), patch(
"homeassistant.components.yale_smart_alarm.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=p_input,
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == "test-username"
assert result2["data"] == p_output
assert len(mock_setup_entry.mock_calls) == 1
async def test_reauth_flow(hass: HomeAssistant) -> None:
"""Test a reauthentication flow."""
entry = MockConfigEntry(