Add Xiaomi Miio vacuum config flow (#46669)
This commit is contained in:
parent
23c2bd4e69
commit
338c07a56b
9 changed files with 278 additions and 189 deletions
|
@ -257,6 +257,53 @@ async def test_import_flow_success(hass):
|
|||
}
|
||||
|
||||
|
||||
async def test_config_flow_step_device_manual_model_succes(hass):
|
||||
"""Test config flow, device connection error, manual model."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "device"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.xiaomi_miio.device.Device.info",
|
||||
side_effect=DeviceException({}),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: TEST_HOST, CONF_TOKEN: TEST_TOKEN},
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "device"
|
||||
assert result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
overwrite_model = const.MODELS_VACUUM[0]
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.xiaomi_miio.device.Device.info",
|
||||
side_effect=DeviceException({}),
|
||||
), patch(
|
||||
"homeassistant.components.xiaomi_miio.async_setup_entry", return_value=True
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_TOKEN: TEST_TOKEN, const.CONF_MODEL: overwrite_model},
|
||||
)
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == DEFAULT_DEVICE_NAME
|
||||
assert result["data"] == {
|
||||
const.CONF_FLOW_TYPE: const.CONF_DEVICE,
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_TOKEN: TEST_TOKEN,
|
||||
const.CONF_MODEL: overwrite_model,
|
||||
const.CONF_MAC: None,
|
||||
}
|
||||
|
||||
|
||||
async def config_flow_device_success(hass, model_to_test):
|
||||
"""Test a successful config flow for a device (base class)."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -342,3 +389,16 @@ async def test_zeroconf_plug_success(hass):
|
|||
test_plug_model = const.MODELS_SWITCH[0]
|
||||
test_zeroconf_name = const.MODELS_SWITCH[0].replace(".", "-")
|
||||
await zeroconf_device_success(hass, test_zeroconf_name, test_plug_model)
|
||||
|
||||
|
||||
async def test_config_flow_vacuum_success(hass):
|
||||
"""Test a successful config flow for a vacuum."""
|
||||
test_vacuum_model = const.MODELS_VACUUM[0]
|
||||
await config_flow_device_success(hass, test_vacuum_model)
|
||||
|
||||
|
||||
async def test_zeroconf_vacuum_success(hass):
|
||||
"""Test a successful zeroconf discovery of a vacuum."""
|
||||
test_vacuum_model = const.MODELS_VACUUM[0]
|
||||
test_zeroconf_name = const.MODELS_VACUUM[0].replace(".", "-")
|
||||
await zeroconf_device_success(hass, test_zeroconf_name, test_vacuum_model)
|
||||
|
|
|
@ -22,6 +22,7 @@ from homeassistant.components.vacuum import (
|
|||
STATE_CLEANING,
|
||||
STATE_ERROR,
|
||||
)
|
||||
from homeassistant.components.xiaomi_miio import const
|
||||
from homeassistant.components.xiaomi_miio.const import DOMAIN as XIAOMI_DOMAIN
|
||||
from homeassistant.components.xiaomi_miio.vacuum import (
|
||||
ATTR_CLEANED_AREA,
|
||||
|
@ -38,7 +39,6 @@ from homeassistant.components.xiaomi_miio.vacuum import (
|
|||
ATTR_SIDE_BRUSH_LEFT,
|
||||
ATTR_TIMERS,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_TOKEN,
|
||||
SERVICE_CLEAN_SEGMENT,
|
||||
SERVICE_CLEAN_ZONE,
|
||||
|
@ -51,12 +51,14 @@ from homeassistant.components.xiaomi_miio.vacuum import (
|
|||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
CONF_PLATFORM,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_config_flow import TEST_MAC
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
PLATFORM = "xiaomi_miio"
|
||||
|
||||
|
@ -521,17 +523,21 @@ async def setup_component(hass, entity_name):
|
|||
"""Set up vacuum component."""
|
||||
entity_id = f"{DOMAIN}.{entity_name}"
|
||||
|
||||
await async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
DOMAIN: {
|
||||
CONF_PLATFORM: PLATFORM,
|
||||
CONF_HOST: "192.168.1.100",
|
||||
CONF_NAME: entity_name,
|
||||
CONF_TOKEN: "12345678901234567890123456789012",
|
||||
}
|
||||
config_entry = MockConfigEntry(
|
||||
domain=XIAOMI_DOMAIN,
|
||||
unique_id="123456",
|
||||
title=entity_name,
|
||||
data={
|
||||
const.CONF_FLOW_TYPE: const.CONF_DEVICE,
|
||||
CONF_HOST: "192.168.1.100",
|
||||
CONF_TOKEN: "12345678901234567890123456789012",
|
||||
const.CONF_MODEL: const.MODELS_VACUUM[0],
|
||||
const.CONF_MAC: TEST_MAC,
|
||||
},
|
||||
)
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return entity_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue