Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing or incorrect device name and unique id for ESPHome during manual add #95678

Merged
merged 11 commits into from
Jul 2, 2023
Prev Previous commit
Next Next commit
coverage shows it works but it does not
  • Loading branch information
bdraco committed Jul 1, 2023
commit dbbb7d92eec7c20d6b952b5929138b92dab4e0c9
47 changes: 47 additions & 0 deletions tests/components/esphome/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,53 @@ async def test_user_connection_updates_host(
assert entry.data[CONF_HOST] == "127.0.0.1"


async def test_user_sets_unique_id(
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
) -> None:
"""Test that the user flow sets the unique id."""
service_info = zeroconf.ZeroconfServiceInfo(
host="192.168.43.183",
addresses=["192.168.43.183"],
hostname="test8266.local.",
name="mock_name",
port=6053,
properties={
"mac": "1122334455aa",
},
type="mock_type",
)
discovery_result = await hass.config_entries.flow.async_init(
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
)

assert discovery_result["type"] == FlowResultType.FORM
assert discovery_result["step_id"] == "discovery_confirm"

result = await hass.config_entries.flow.async_init(
"esphome",
context={"source": config_entries.SOURCE_USER},
data=None,
)

assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"] == {
CONF_HOST: "127.0.0.1",
CONF_PORT: 6053,
CONF_PASSWORD: "",
CONF_NOISE_PSK: "",
CONF_DEVICE_NAME: "test",
}

assert not hass.config_entries.flow.async_progress_by_handler(DOMAIN)


async def test_user_resolve_error(
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
) -> None:
Expand Down