mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Merge pull request #68825 from home-assistant/rc
This commit is contained in:
commit
be39a3cee0
@ -88,8 +88,6 @@ class AbodeCamera(AbodeDevice, Camera):
|
||||
self, width: int | None = None, height: int | None = None
|
||||
) -> bytes | None:
|
||||
"""Get a camera image."""
|
||||
if not self.capture():
|
||||
return None
|
||||
self.refresh_image()
|
||||
|
||||
if self._response:
|
||||
|
@ -37,7 +37,9 @@ from .discovery import (
|
||||
|
||||
CONF_DEVICE = "device"
|
||||
|
||||
NON_SECURE_PORT = 2101
|
||||
SECURE_PORT = 2601
|
||||
STANDARD_PORTS = {NON_SECURE_PORT, SECURE_PORT}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -48,6 +50,7 @@ PROTOCOL_MAP = {
|
||||
"serial": "serial://",
|
||||
}
|
||||
|
||||
|
||||
VALIDATE_TIMEOUT = 35
|
||||
|
||||
BASE_SCHEMA = {
|
||||
@ -60,6 +63,11 @@ ALL_PROTOCOLS = [*SECURE_PROTOCOLS, "non-secure", "serial"]
|
||||
DEFAULT_SECURE_PROTOCOL = "secure"
|
||||
DEFAULT_NON_SECURE_PROTOCOL = "non-secure"
|
||||
|
||||
PORT_PROTOCOL_MAP = {
|
||||
NON_SECURE_PORT: DEFAULT_NON_SECURE_PROTOCOL,
|
||||
SECURE_PORT: DEFAULT_SECURE_PROTOCOL,
|
||||
}
|
||||
|
||||
|
||||
async def validate_input(data: dict[str, str], mac: str | None) -> dict[str, str]:
|
||||
"""Validate the user input allows us to connect.
|
||||
@ -97,6 +105,13 @@ async def validate_input(data: dict[str, str], mac: str | None) -> dict[str, str
|
||||
return {"title": device_name, CONF_HOST: url, CONF_PREFIX: slugify(prefix)}
|
||||
|
||||
|
||||
def _address_from_discovery(device: ElkSystem):
|
||||
"""Append the port only if its non-standard."""
|
||||
if device.port in STANDARD_PORTS:
|
||||
return device.ip_address
|
||||
return f"{device.ip_address}:{device.port}"
|
||||
|
||||
|
||||
def _make_url_from_data(data):
|
||||
if host := data.get(CONF_HOST):
|
||||
return host
|
||||
@ -109,7 +124,7 @@ def _make_url_from_data(data):
|
||||
def _placeholders_from_device(device: ElkSystem) -> dict[str, str]:
|
||||
return {
|
||||
"mac_address": _short_mac(device.mac_address),
|
||||
"host": f"{device.ip_address}:{device.port}",
|
||||
"host": _address_from_discovery(device),
|
||||
}
|
||||
|
||||
|
||||
@ -166,6 +181,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
for progress in self._async_in_progress():
|
||||
if progress.get("context", {}).get(CONF_HOST) == host:
|
||||
return self.async_abort(reason="already_in_progress")
|
||||
# Handled ignored case since _async_current_entries
|
||||
# is called with include_ignore=False
|
||||
self._abort_if_unique_id_configured()
|
||||
if not device.port:
|
||||
if discovered_device := await async_discover_device(self.hass, host):
|
||||
self._discovered_device = discovered_device
|
||||
@ -255,26 +273,26 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
device = self._discovered_device
|
||||
assert device is not None
|
||||
if user_input is not None:
|
||||
user_input[CONF_ADDRESS] = f"{device.ip_address}:{device.port}"
|
||||
user_input[CONF_ADDRESS] = _address_from_discovery(device)
|
||||
if self._async_current_entries():
|
||||
user_input[CONF_PREFIX] = _short_mac(device.mac_address)
|
||||
else:
|
||||
user_input[CONF_PREFIX] = ""
|
||||
if device.port != SECURE_PORT:
|
||||
user_input[CONF_PROTOCOL] = DEFAULT_NON_SECURE_PROTOCOL
|
||||
errors, result = await self._async_create_or_error(user_input, False)
|
||||
if not errors:
|
||||
return result
|
||||
|
||||
base_schmea = BASE_SCHEMA.copy()
|
||||
if device.port == SECURE_PORT:
|
||||
base_schmea[
|
||||
vol.Required(CONF_PROTOCOL, default=DEFAULT_SECURE_PROTOCOL)
|
||||
] = vol.In(SECURE_PROTOCOLS)
|
||||
|
||||
default_proto = PORT_PROTOCOL_MAP.get(device.port, DEFAULT_SECURE_PROTOCOL)
|
||||
return self.async_show_form(
|
||||
step_id="discovered_connection",
|
||||
data_schema=vol.Schema(base_schmea),
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
**BASE_SCHEMA,
|
||||
vol.Required(CONF_PROTOCOL, default=default_proto): vol.In(
|
||||
ALL_PROTOCOLS
|
||||
),
|
||||
}
|
||||
),
|
||||
errors=errors,
|
||||
description_placeholders=_placeholders_from_device(device),
|
||||
)
|
||||
@ -334,7 +352,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return (await self._async_create_or_error(user_input, True))[1]
|
||||
errors, result = await self._async_create_or_error(user_input, True)
|
||||
if errors:
|
||||
return self.async_abort(reason=list(errors.values())[0])
|
||||
return result
|
||||
|
||||
def _url_already_configured(self, url):
|
||||
"""See if we already have a elkm1 matching user input configured."""
|
||||
|
@ -38,6 +38,8 @@
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
},
|
||||
"abort": {
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]",
|
||||
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"already_configured": "An ElkM1 with this prefix is already configured",
|
||||
|
@ -4,7 +4,9 @@
|
||||
"address_already_configured": "An ElkM1 with this address is already configured",
|
||||
"already_configured": "An ElkM1 with this prefix is already configured",
|
||||
"already_in_progress": "Configuration flow is already in progress",
|
||||
"cannot_connect": "Failed to connect"
|
||||
"cannot_connect": "Failed to connect",
|
||||
"invalid_auth": "Invalid authentication",
|
||||
"unknown": "Unexpected error"
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "Failed to connect",
|
||||
@ -37,13 +39,7 @@
|
||||
},
|
||||
"user": {
|
||||
"data": {
|
||||
"address": "The IP address or domain or serial port if connecting via serial.",
|
||||
"device": "Device",
|
||||
"password": "Password",
|
||||
"prefix": "A unique prefix (leave blank if you only have one ElkM1).",
|
||||
"protocol": "Protocol",
|
||||
"temperature_unit": "The temperature unit ElkM1 uses.",
|
||||
"username": "Username"
|
||||
"device": "Device"
|
||||
},
|
||||
"description": "Choose a discovered system or 'Manual Entry' if no devices have been discovered.",
|
||||
"title": "Connect to Elk-M1 Control"
|
||||
|
@ -2,7 +2,7 @@
|
||||
"domain": "emulated_kasa",
|
||||
"name": "Emulated Kasa",
|
||||
"documentation": "https://www.home-assistant.io/integrations/emulated_kasa",
|
||||
"requirements": ["sense_energy==0.10.3"],
|
||||
"requirements": ["sense_energy==0.10.4"],
|
||||
"codeowners": ["@kbickar"],
|
||||
"quality_scale": "internal",
|
||||
"iot_class": "local_push",
|
||||
|
@ -79,7 +79,7 @@ class ScreenlogicConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
|
||||
"""Handle dhcp discovery."""
|
||||
mac = _extract_mac_from_name(discovery_info.hostname)
|
||||
mac = format_mac(discovery_info.macaddress)
|
||||
await self.async_set_unique_id(mac)
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_IP_ADDRESS: discovery_info.ip}
|
||||
|
@ -8,7 +8,7 @@
|
||||
"dhcp": [
|
||||
{"registered_devices": true},
|
||||
{
|
||||
"hostname": "pentair: *",
|
||||
"hostname": "pentair*",
|
||||
"macaddress": "00C033*"
|
||||
}
|
||||
],
|
||||
|
@ -2,7 +2,7 @@
|
||||
"domain": "sense",
|
||||
"name": "Sense",
|
||||
"documentation": "https://www.home-assistant.io/integrations/sense",
|
||||
"requirements": ["sense_energy==0.10.3"],
|
||||
"requirements": ["sense_energy==0.10.4"],
|
||||
"codeowners": ["@kbickar"],
|
||||
"config_flow": true,
|
||||
"dhcp": [
|
||||
|
@ -9,22 +9,13 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import CONF_SITE_ID, DEFAULT_NAME, DOMAIN
|
||||
|
||||
|
||||
@callback
|
||||
def solaredge_entries(hass: HomeAssistant):
|
||||
"""Return the site_ids for the domain."""
|
||||
return {
|
||||
(entry.data[CONF_SITE_ID])
|
||||
for entry in hass.config_entries.async_entries(DOMAIN)
|
||||
}
|
||||
|
||||
|
||||
class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow."""
|
||||
|
||||
@ -34,9 +25,18 @@ class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Initialize the config flow."""
|
||||
self._errors = {}
|
||||
|
||||
@callback
|
||||
def _async_current_site_ids(self) -> set[str]:
|
||||
"""Return the site_ids for the domain."""
|
||||
return {
|
||||
entry.data[CONF_SITE_ID]
|
||||
for entry in self._async_current_entries(include_ignore=False)
|
||||
if CONF_SITE_ID in entry.data
|
||||
}
|
||||
|
||||
def _site_in_configuration_exists(self, site_id: str) -> bool:
|
||||
"""Return True if site_id exists in configuration."""
|
||||
return site_id in solaredge_entries(self.hass)
|
||||
return site_id in self._async_current_site_ids()
|
||||
|
||||
def _check_site(self, site_id: str, api_key: str) -> bool:
|
||||
"""Check if we can connect to the soleredge api service."""
|
||||
|
@ -51,7 +51,7 @@ DEFAULT_URL = "ws://localhost:3000"
|
||||
TITLE = "Z-Wave JS"
|
||||
|
||||
ADDON_SETUP_TIMEOUT = 5
|
||||
ADDON_SETUP_TIMEOUT_ROUNDS = 4
|
||||
ADDON_SETUP_TIMEOUT_ROUNDS = 40
|
||||
CONF_EMULATE_HARDWARE = "emulate_hardware"
|
||||
CONF_LOG_LEVEL = "log_level"
|
||||
SERVER_VERSION_TIMEOUT = 10
|
||||
|
@ -7,7 +7,7 @@ from .backports.enum import StrEnum
|
||||
|
||||
MAJOR_VERSION: Final = 2022
|
||||
MINOR_VERSION: Final = 3
|
||||
PATCH_VERSION: Final = "7"
|
||||
PATCH_VERSION: Final = "8"
|
||||
__short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}"
|
||||
__version__: Final = f"{__short_version__}.{PATCH_VERSION}"
|
||||
REQUIRED_PYTHON_VER: Final[tuple[int, int, int]] = (3, 9, 0)
|
||||
|
@ -81,7 +81,7 @@ DHCP: list[dict[str, str | bool]] = [
|
||||
{'domain': 'samsungtv', 'macaddress': '4844F7*'},
|
||||
{'domain': 'samsungtv', 'macaddress': '8CEA48*'},
|
||||
{'domain': 'screenlogic', 'registered_devices': True},
|
||||
{'domain': 'screenlogic', 'hostname': 'pentair: *', 'macaddress': '00C033*'},
|
||||
{'domain': 'screenlogic', 'hostname': 'pentair*', 'macaddress': '00C033*'},
|
||||
{'domain': 'sense', 'hostname': 'sense-*', 'macaddress': '009D6B*'},
|
||||
{'domain': 'sense', 'hostname': 'sense-*', 'macaddress': 'DCEFCA*'},
|
||||
{'domain': 'sense', 'hostname': 'sense-*', 'macaddress': 'A4D578*'},
|
||||
|
@ -99,3 +99,7 @@ multidict>=6.0.2
|
||||
# Required for compatibility with point integration - ensure_active_token
|
||||
# https://github.com/home-assistant/core/pull/68176
|
||||
authlib<1.0
|
||||
|
||||
# Required for compatibility with typer, used by pyunifiprotect integration
|
||||
# https://github.com/tiangolo/typer/pull/375
|
||||
click<=8.0.4
|
||||
|
@ -2179,7 +2179,7 @@ sense-hat==2.2.0
|
||||
|
||||
# homeassistant.components.emulated_kasa
|
||||
# homeassistant.components.sense
|
||||
sense_energy==0.10.3
|
||||
sense_energy==0.10.4
|
||||
|
||||
# homeassistant.components.sentry
|
||||
sentry-sdk==1.5.5
|
||||
|
@ -1344,7 +1344,7 @@ screenlogicpy==0.5.4
|
||||
|
||||
# homeassistant.components.emulated_kasa
|
||||
# homeassistant.components.sense
|
||||
sense_energy==0.10.3
|
||||
sense_energy==0.10.4
|
||||
|
||||
# homeassistant.components.sentry
|
||||
sentry-sdk==1.5.5
|
||||
|
@ -128,6 +128,10 @@ multidict>=6.0.2
|
||||
# Required for compatibility with point integration - ensure_active_token
|
||||
# https://github.com/home-assistant/core/pull/68176
|
||||
authlib<1.0
|
||||
|
||||
# Required for compatibility with typer, used by pyunifiprotect integration
|
||||
# https://github.com/tiangolo/typer/pull/375
|
||||
click<=8.0.4
|
||||
"""
|
||||
|
||||
IGNORE_PRE_COMMIT_HOOK_ID = (
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = homeassistant
|
||||
version = 2022.3.7
|
||||
version = 2022.3.8
|
||||
author = The Home Assistant Authors
|
||||
author_email = hello@home-assistant.io
|
||||
license = Apache-2.0
|
||||
|
@ -9,6 +9,7 @@ MOCK_IP_ADDRESS = "127.0.0.1"
|
||||
MOCK_MAC = "aa:bb:cc:dd:ee:ff"
|
||||
ELK_DISCOVERY = ElkSystem(MOCK_MAC, MOCK_IP_ADDRESS, 2601)
|
||||
ELK_NON_SECURE_DISCOVERY = ElkSystem(MOCK_MAC, MOCK_IP_ADDRESS, 2101)
|
||||
ELK_DISCOVERY_NON_STANDARD_PORT = ElkSystem(MOCK_MAC, MOCK_IP_ADDRESS, 444)
|
||||
|
||||
|
||||
def mock_elk(invalid_auth=None, sync_complete=None, exception=None):
|
||||
|
@ -12,6 +12,7 @@ from homeassistant.data_entry_flow import RESULT_TYPE_ABORT, RESULT_TYPE_FORM
|
||||
|
||||
from . import (
|
||||
ELK_DISCOVERY,
|
||||
ELK_DISCOVERY_NON_STANDARD_PORT,
|
||||
ELK_NON_SECURE_DISCOVERY,
|
||||
MOCK_IP_ADDRESS,
|
||||
MOCK_MAC,
|
||||
@ -24,9 +25,32 @@ from tests.common import MockConfigEntry
|
||||
|
||||
DHCP_DISCOVERY = dhcp.DhcpServiceInfo(MOCK_IP_ADDRESS, "", MOCK_MAC)
|
||||
ELK_DISCOVERY_INFO = asdict(ELK_DISCOVERY)
|
||||
ELK_DISCOVERY_INFO_NON_STANDARD_PORT = asdict(ELK_DISCOVERY_NON_STANDARD_PORT)
|
||||
|
||||
MODULE = "homeassistant.components.elkm1"
|
||||
|
||||
|
||||
async def test_discovery_ignored_entry(hass):
|
||||
"""Test we abort on ignored entry."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_HOST: f"elks://{MOCK_IP_ADDRESS}"},
|
||||
unique_id="aa:bb:cc:dd:ee:ff",
|
||||
source=config_entries.SOURCE_IGNORE,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with _patch_discovery(), _patch_elk():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=ELK_DISCOVERY_INFO,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_form_user_with_secure_elk_no_discovery(hass):
|
||||
"""Test we can setup a secure elk."""
|
||||
|
||||
@ -301,7 +325,7 @@ async def test_form_user_with_secure_elk_with_discovery(hass):
|
||||
assert result3["title"] == "ElkM1 ddeeff"
|
||||
assert result3["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elks://127.0.0.1:2601",
|
||||
"host": "elks://127.0.0.1",
|
||||
"password": "test-password",
|
||||
"prefix": "",
|
||||
"username": "test-username",
|
||||
@ -801,6 +825,102 @@ async def test_form_import_device_discovered(hass):
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_import_non_secure_device_discovered(hass):
|
||||
"""Test we can import non-secure with discovery."""
|
||||
|
||||
mocked_elk = mock_elk(invalid_auth=False, sync_complete=True)
|
||||
with _patch_discovery(), _patch_elk(elk=mocked_elk), patch(
|
||||
"homeassistant.components.elkm1.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.elkm1.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
"host": "elk://127.0.0.1:2101",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"auto_configure": True,
|
||||
"prefix": "ohana",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "ohana"
|
||||
assert result["result"].unique_id == MOCK_MAC
|
||||
assert result["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elk://127.0.0.1:2101",
|
||||
"password": "",
|
||||
"prefix": "ohana",
|
||||
"username": "",
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_import_non_secure_non_stanadard_port_device_discovered(hass):
|
||||
"""Test we can import non-secure non standard port with discovery."""
|
||||
|
||||
mocked_elk = mock_elk(invalid_auth=False, sync_complete=True)
|
||||
with _patch_discovery(), _patch_elk(elk=mocked_elk), patch(
|
||||
"homeassistant.components.elkm1.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.elkm1.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
"host": "elk://127.0.0.1:444",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"auto_configure": True,
|
||||
"prefix": "ohana",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "ohana"
|
||||
assert result["result"].unique_id == MOCK_MAC
|
||||
assert result["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elk://127.0.0.1:444",
|
||||
"password": "",
|
||||
"prefix": "ohana",
|
||||
"username": "",
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_import_non_secure_device_discovered_invalid_auth(hass):
|
||||
"""Test we abort import with invalid auth."""
|
||||
|
||||
mocked_elk = mock_elk(invalid_auth=True, sync_complete=False)
|
||||
with _patch_discovery(), _patch_elk(elk=mocked_elk):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
"host": "elks://127.0.0.1",
|
||||
"username": "invalid",
|
||||
"password": "",
|
||||
"auto_configure": False,
|
||||
"prefix": "ohana",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "invalid_auth"
|
||||
|
||||
|
||||
async def test_form_import_existing(hass):
|
||||
"""Test we abort on existing import."""
|
||||
config_entry = MockConfigEntry(
|
||||
@ -978,7 +1098,52 @@ async def test_discovered_by_discovery(hass):
|
||||
assert result2["title"] == "ElkM1 ddeeff"
|
||||
assert result2["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elks://127.0.0.1:2601",
|
||||
"host": "elks://127.0.0.1",
|
||||
"password": "test-password",
|
||||
"prefix": "",
|
||||
"username": "test-username",
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_discovered_by_discovery_non_standard_port(hass):
|
||||
"""Test we can setup when discovered from discovery with a non-standard port."""
|
||||
|
||||
with _patch_discovery(), _patch_elk():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=ELK_DISCOVERY_INFO_NON_STANDARD_PORT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "discovered_connection"
|
||||
assert result["errors"] == {}
|
||||
|
||||
mocked_elk = mock_elk(invalid_auth=False, sync_complete=True)
|
||||
|
||||
with _patch_discovery(), _patch_elk(elk=mocked_elk), patch(
|
||||
"homeassistant.components.elkm1.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.elkm1.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "ElkM1 ddeeff"
|
||||
assert result2["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elks://127.0.0.1:444",
|
||||
"password": "test-password",
|
||||
"prefix": "",
|
||||
"username": "test-username",
|
||||
@ -1042,7 +1207,7 @@ async def test_discovered_by_dhcp_udp_responds(hass):
|
||||
assert result2["title"] == "ElkM1 ddeeff"
|
||||
assert result2["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elks://127.0.0.1:2601",
|
||||
"host": "elks://127.0.0.1",
|
||||
"password": "test-password",
|
||||
"prefix": "",
|
||||
"username": "test-username",
|
||||
@ -1077,8 +1242,7 @@ async def test_discovered_by_dhcp_udp_responds_with_nonsecure_port(hass):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"protocol": "non-secure",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -1087,10 +1251,10 @@ async def test_discovered_by_dhcp_udp_responds_with_nonsecure_port(hass):
|
||||
assert result2["title"] == "ElkM1 ddeeff"
|
||||
assert result2["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elk://127.0.0.1:2101",
|
||||
"password": "test-password",
|
||||
"host": "elk://127.0.0.1",
|
||||
"password": "",
|
||||
"prefix": "",
|
||||
"username": "test-username",
|
||||
"username": "",
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
@ -1125,10 +1289,7 @@ async def test_discovered_by_dhcp_udp_responds_existing_config_entry(hass):
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
},
|
||||
{"username": "test-username", "password": "test-password"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@ -1136,7 +1297,7 @@ async def test_discovered_by_dhcp_udp_responds_existing_config_entry(hass):
|
||||
assert result2["title"] == "ElkM1 ddeeff"
|
||||
assert result2["data"] == {
|
||||
"auto_configure": True,
|
||||
"host": "elks://127.0.0.1:2601",
|
||||
"host": "elks://127.0.0.1",
|
||||
"password": "test-password",
|
||||
"prefix": "ddeeff",
|
||||
"username": "test-username",
|
||||
|
@ -6,7 +6,7 @@ from requests.exceptions import ConnectTimeout, HTTPError
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.solaredge.const import CONF_SITE_ID, DEFAULT_NAME, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_IGNORE, SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -66,6 +66,31 @@ async def test_abort_if_already_setup(hass: HomeAssistant, test_api: str) -> Non
|
||||
assert result.get("errors") == {CONF_SITE_ID: "already_configured"}
|
||||
|
||||
|
||||
async def test_ignored_entry_does_not_cause_error(
|
||||
hass: HomeAssistant, test_api: str
|
||||
) -> None:
|
||||
"""Test an ignored entry does not cause and error and we can still create an new entry."""
|
||||
MockConfigEntry(
|
||||
domain="solaredge",
|
||||
data={CONF_NAME: DEFAULT_NAME, CONF_API_KEY: API_KEY},
|
||||
source=SOURCE_IGNORE,
|
||||
).add_to_hass(hass)
|
||||
|
||||
# user: Should fail, same SITE_ID
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_NAME: "test", CONF_SITE_ID: SITE_ID, CONF_API_KEY: "test"},
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "test"
|
||||
|
||||
data = result["data"]
|
||||
assert data
|
||||
assert data[CONF_SITE_ID] == SITE_ID
|
||||
assert data[CONF_API_KEY] == "test"
|
||||
|
||||
|
||||
async def test_asserts(hass: HomeAssistant, test_api: Mock) -> None:
|
||||
"""Test the _site_in_configuration_exists method."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user