1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add Mill config flow (#35136)

* Mill config, wip

* add tests

* fix merge

* update tests

* unique id

* Mill strings

* mill config flow

* mill config flow

* test import

* test import

* req

* ccoverage

* Apply suggestions from code review

Co-authored-by: J. Nick Koston <nick@koston.org>

* style

* Apply suggestions from code review

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* update strings

* add test

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Daniel Høyer Iversen
2020-05-10 15:44:05 +02:00
committed by GitHub
parent 8050d8555e
commit f302c6fd65
9 changed files with 213 additions and 11 deletions

View File

@@ -0,0 +1,86 @@
"""Tests for Mill config flow."""
import pytest
from homeassistant.components.mill.const import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from tests.async_mock import patch
from tests.common import MockConfigEntry
@pytest.fixture(name="mill_setup", autouse=True)
def mill_setup_fixture():
"""Patch mill setup entry."""
with patch("homeassistant.components.mill.async_setup_entry", return_value=True):
yield
async def test_show_config_form(hass):
"""Test show configuration form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}
)
assert result["type"] == "form"
assert result["step_id"] == "user"
async def test_create_entry(hass):
"""Test create entry from user input."""
test_data = {
CONF_USERNAME: "user",
CONF_PASSWORD: "pswd",
}
with patch("mill.Mill.connect", return_value=True):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}, data=test_data
)
assert result["type"] == "create_entry"
assert result["title"] == test_data[CONF_USERNAME]
assert result["data"] == test_data
async def test_flow_entry_already_exists(hass):
"""Test user input for config_entry that already exists."""
test_data = {
CONF_USERNAME: "user",
CONF_PASSWORD: "pswd",
}
first_entry = MockConfigEntry(
domain="mill", data=test_data, unique_id=test_data[CONF_USERNAME],
)
first_entry.add_to_hass(hass)
with patch("mill.Mill.connect", return_value=True):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}, data=test_data
)
assert result["type"] == "abort"
assert result["reason"] == "already_configured"
async def test_connection_error(hass):
"""Test connection error."""
test_data = {
CONF_USERNAME: "user",
CONF_PASSWORD: "pswd",
}
first_entry = MockConfigEntry(
domain="mill", data=test_data, unique_id=test_data[CONF_USERNAME],
)
first_entry.add_to_hass(hass)
with patch("mill.Mill.connect", return_value=False):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}, data=test_data
)
assert result["type"] == "form"
assert result["errors"]["connection_error"] == "connection_error"