mirror of
https://github.com/home-assistant/core.git
synced 2026-09-12 10:06:22 -05:00
Implement stable unique id for Huawei LTE, requires credentials on setup (#49878)
This commit is contained in:
@@ -10,7 +10,7 @@ from requests_mock import ANY
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components import ssdp
|
||||
from homeassistant.components.huawei_lte.const import DOMAIN
|
||||
from homeassistant.components.huawei_lte.const import CONF_UNAUTHENTICATED_MODE, DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
@@ -21,6 +21,8 @@ from homeassistant.const import (
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
FIXTURE_UNIQUE_ID = "SERIALNUMBER"
|
||||
|
||||
FIXTURE_USER_INPUT = {
|
||||
CONF_URL: "http://192.168.1.1/",
|
||||
CONF_USERNAME: "admin",
|
||||
@@ -57,20 +59,30 @@ async def test_urlize_plain_host(hass, requests_mock):
|
||||
assert user_input[CONF_URL] == f"http://{host}/"
|
||||
|
||||
|
||||
async def test_already_configured(hass):
|
||||
async def test_already_configured(hass, requests_mock, login_requests_mock):
|
||||
"""Test we reject already configured devices."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN, data=FIXTURE_USER_INPUT, title="Already configured"
|
||||
domain=DOMAIN,
|
||||
unique_id=FIXTURE_UNIQUE_ID,
|
||||
data=FIXTURE_USER_INPUT,
|
||||
title="Already configured",
|
||||
).add_to_hass(hass)
|
||||
|
||||
login_requests_mock.request(
|
||||
ANY,
|
||||
f"{FIXTURE_USER_INPUT[CONF_URL]}api/user/login",
|
||||
text="<response>OK</response>",
|
||||
)
|
||||
requests_mock.request(
|
||||
ANY,
|
||||
f"{FIXTURE_USER_INPUT[CONF_URL]}api/device/information",
|
||||
text=f"<response><SerialNumber>{FIXTURE_UNIQUE_ID}</SerialNumber></response>",
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data={
|
||||
**FIXTURE_USER_INPUT,
|
||||
# Tweak URL a bit to check that doesn't fail duplicate detection
|
||||
CONF_URL: FIXTURE_USER_INPUT[CONF_URL].replace("http", "HTTP"),
|
||||
},
|
||||
data=FIXTURE_USER_INPUT,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
@@ -182,7 +194,7 @@ async def test_ssdp(hass):
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert context[CONF_URL] == url
|
||||
assert result["data_schema"]({})[CONF_URL] == url
|
||||
|
||||
|
||||
async def test_options(hass):
|
||||
@@ -203,3 +215,4 @@ async def test_options(hass):
|
||||
)
|
||||
assert result["data"][CONF_NAME] == DOMAIN
|
||||
assert result["data"][CONF_RECIPIENT] == [recipient]
|
||||
assert result["data"][CONF_UNAUTHENTICATED_MODE] is False
|
||||
|
||||
Reference in New Issue
Block a user