mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Use config_entries.SOURCE_* constants (#49631)
This commit is contained in:
@@ -4,6 +4,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.esphome import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
||||
from homeassistant.data_entry_flow import (
|
||||
@@ -51,7 +52,7 @@ async def test_user_connection_works(hass, mock_client):
|
||||
"""Test we can finish a config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome",
|
||||
context={"source": "user"},
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data=None,
|
||||
)
|
||||
|
||||
@@ -62,7 +63,7 @@ async def test_user_connection_works(hass, mock_client):
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome",
|
||||
context={"source": "user"},
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data={CONF_HOST: "127.0.0.1", CONF_PORT: 80},
|
||||
)
|
||||
|
||||
@@ -95,7 +96,7 @@ async def test_user_resolve_error(hass, mock_api_connection_error, mock_client):
|
||||
mock_client.device_info.side_effect = exc
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome",
|
||||
context={"source": "user"},
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
|
||||
)
|
||||
|
||||
@@ -114,7 +115,7 @@ async def test_user_connection_error(hass, mock_api_connection_error, mock_clien
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome",
|
||||
context={"source": "user"},
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
|
||||
)
|
||||
|
||||
@@ -133,7 +134,7 @@ async def test_user_with_password(hass, mock_client):
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome",
|
||||
context={"source": "user"},
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
|
||||
)
|
||||
|
||||
@@ -159,7 +160,7 @@ async def test_user_invalid_password(hass, mock_api_connection_error, mock_clien
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome",
|
||||
context={"source": "user"},
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
|
||||
)
|
||||
|
||||
@@ -188,7 +189,7 @@ async def test_discovery_initiation(hass, mock_client):
|
||||
"properties": {},
|
||||
}
|
||||
flow = await hass.config_entries.flow.async_init(
|
||||
"esphome", context={"source": "zeroconf"}, data=service_info
|
||||
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
@@ -220,7 +221,7 @@ async def test_discovery_already_configured_hostname(hass, mock_client):
|
||||
"properties": {},
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome", context={"source": "zeroconf"}, data=service_info
|
||||
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
@@ -245,7 +246,7 @@ async def test_discovery_already_configured_ip(hass, mock_client):
|
||||
"properties": {"address": "192.168.43.183"},
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome", context={"source": "zeroconf"}, data=service_info
|
||||
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
@@ -273,7 +274,7 @@ async def test_discovery_already_configured_name(hass, mock_client):
|
||||
"properties": {"address": "test8266.local"},
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome", context={"source": "zeroconf"}, data=service_info
|
||||
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
@@ -295,13 +296,13 @@ async def test_discovery_duplicate_data(hass, mock_client):
|
||||
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test8266"))
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome", data=service_info, context={"source": "zeroconf"}
|
||||
"esphome", data=service_info, context={"source": config_entries.SOURCE_ZEROCONF}
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "discovery_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome", data=service_info, context={"source": "zeroconf"}
|
||||
"esphome", data=service_info, context={"source": config_entries.SOURCE_ZEROCONF}
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_in_progress"
|
||||
@@ -323,7 +324,7 @@ async def test_discovery_updates_unique_id(hass, mock_client):
|
||||
"properties": {"address": "test8266.local"},
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome", context={"source": "zeroconf"}, data=service_info
|
||||
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
|
||||
Reference in New Issue
Block a user