Remove YAML import from homeworks (#120171)
This commit is contained in:
parent
9b341f5b67
commit
f06bd1b66f
4 changed files with 6 additions and 304 deletions
|
@ -9,21 +9,17 @@ from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAI
|
|||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN
|
||||
from homeassistant.components.homeworks.const import (
|
||||
CONF_ADDR,
|
||||
CONF_DIMMERS,
|
||||
CONF_INDEX,
|
||||
CONF_KEYPADS,
|
||||
CONF_LED,
|
||||
CONF_NUMBER,
|
||||
CONF_RATE,
|
||||
CONF_RELEASE_DELAY,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_RECONFIGURE, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_RECONFIGURE, SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -129,114 +125,6 @@ async def test_user_flow_cannot_connect(
|
|||
assert result["step_id"] == "user"
|
||||
|
||||
|
||||
async def test_import_flow(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_homeworks: MagicMock,
|
||||
mock_setup_entry,
|
||||
) -> None:
|
||||
"""Test importing yaml config."""
|
||||
entry = entity_registry.async_get_or_create(
|
||||
LIGHT_DOMAIN, DOMAIN, "homeworks.[02:08:01:01]"
|
||||
)
|
||||
|
||||
mock_controller = MagicMock()
|
||||
mock_homeworks.return_value = mock_controller
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_HOST: "192.168.0.1",
|
||||
CONF_PORT: 1234,
|
||||
CONF_DIMMERS: [
|
||||
{
|
||||
CONF_ADDR: "[02:08:01:01]",
|
||||
CONF_NAME: "Foyer Sconces",
|
||||
CONF_RATE: 1.0,
|
||||
}
|
||||
],
|
||||
CONF_KEYPADS: [
|
||||
{
|
||||
CONF_ADDR: "[02:08:02:01]",
|
||||
CONF_NAME: "Foyer Keypad",
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "import_controller_name"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_NAME: "Main controller"}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "import_finish"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={}
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Main controller"
|
||||
assert result["data"] == {}
|
||||
assert result["options"] == {
|
||||
"controller_id": "main_controller",
|
||||
"dimmers": [{"addr": "[02:08:01:01]", "name": "Foyer Sconces", "rate": 1.0}],
|
||||
"host": "192.168.0.1",
|
||||
"keypads": [
|
||||
{
|
||||
"addr": "[02:08:02:01]",
|
||||
"buttons": [],
|
||||
"name": "Foyer Keypad",
|
||||
}
|
||||
],
|
||||
"port": 1234,
|
||||
}
|
||||
assert len(issue_registry.issues) == 0
|
||||
|
||||
# Check unique ID is updated in entity registry
|
||||
entry = entity_registry.async_get(entry.id)
|
||||
assert entry.unique_id == "homeworks.main_controller.[02:08:01:01].0"
|
||||
|
||||
|
||||
async def test_import_flow_already_exists(
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_empty_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test importing yaml config where entry already exists."""
|
||||
mock_empty_config_entry.add_to_hass(hass)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={"host": "192.168.0.1", "port": 1234, CONF_DIMMERS: [], CONF_KEYPADS: []},
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert len(issue_registry.issues) == 1
|
||||
|
||||
|
||||
async def test_import_flow_controller_id_exists(
|
||||
hass: HomeAssistant, mock_empty_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test importing yaml config where entry already exists."""
|
||||
mock_empty_config_entry.add_to_hass(hass)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={"host": "192.168.0.2", "port": 1234, CONF_DIMMERS: [], CONF_KEYPADS: []},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "import_controller_name"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_NAME: "Main controller"}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "import_controller_name"
|
||||
assert result["errors"] == {"base": "duplicated_controller_id"}
|
||||
|
||||
|
||||
async def test_reconfigure_flow(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_homeworks: MagicMock
|
||||
) -> None:
|
||||
|
|
|
@ -6,39 +6,14 @@ from pyhomeworks.pyhomeworks import HW_BUTTON_PRESSED, HW_BUTTON_RELEASED
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.homeworks import EVENT_BUTTON_PRESS, EVENT_BUTTON_RELEASE
|
||||
from homeassistant.components.homeworks.const import CONF_DIMMERS, CONF_KEYPADS, DOMAIN
|
||||
from homeassistant.components.homeworks.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, async_capture_events
|
||||
|
||||
|
||||
async def test_import(
|
||||
hass: HomeAssistant,
|
||||
mock_homeworks: MagicMock,
|
||||
) -> None:
|
||||
"""Test the Homeworks YAML import."""
|
||||
await async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
DOMAIN: {
|
||||
CONF_HOST: "192.168.0.1",
|
||||
CONF_PORT: 1234,
|
||||
CONF_DIMMERS: [],
|
||||
CONF_KEYPADS: [],
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
||||
assert hass.config_entries.flow.async_progress()[0]["context"]["source"] == "import"
|
||||
|
||||
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue