mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 05:35:11 +02:00
fix recursion
This commit is contained in:
@@ -43,8 +43,10 @@ async def async_setup(hass, config):
|
||||
"""Set up the Samsung TV integration."""
|
||||
if DOMAIN in config:
|
||||
for entry_config in config[DOMAIN]:
|
||||
await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "import"}, data=entry_config
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "import"}, data=entry_config
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
@@ -34,6 +34,10 @@ RESULT_NOT_FOUND = "not_found"
|
||||
RESULT_NOT_SUPPORTED = "not_supported"
|
||||
|
||||
|
||||
def _is_already_in_progress(flows, ip_address):
|
||||
return any(ip_address == flow["context"].get(CONF_IP_ADDRESS) for flow in flows)
|
||||
|
||||
|
||||
def _is_already_configured(hass, ip_address):
|
||||
return any(
|
||||
ip_address == entry.data.get(CONF_IP_ADDRESS)
|
||||
@@ -127,6 +131,9 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
_get_ip, user_input[CONF_HOST]
|
||||
)
|
||||
|
||||
if _is_already_in_progress(self._async_in_progress(), ip_address):
|
||||
return self.async_abort(reason="already_in_progress")
|
||||
|
||||
if _is_already_configured(self.hass, ip_address):
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
@@ -154,10 +161,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
_get_ip, user_input[ATTR_SSDP_LOCATION]
|
||||
)
|
||||
|
||||
if any(
|
||||
ip_address == flow["context"].get(CONF_IP_ADDRESS)
|
||||
for flow in self._async_in_progress()
|
||||
):
|
||||
if _is_already_in_progress(self._async_in_progress(), ip_address):
|
||||
return self.async_abort(reason="already_in_progress")
|
||||
|
||||
if _is_already_configured(self.hass, ip_address):
|
||||
|
@@ -10,7 +10,6 @@ from samsungctl import exceptions
|
||||
import wakeonlan
|
||||
from websocket import WebSocketException
|
||||
|
||||
from homeassistant.components import samsungtv
|
||||
from homeassistant.components.media_player import DEVICE_CLASS_TV
|
||||
from homeassistant.components.media_player.const import (
|
||||
ATTR_INPUT_SOURCE,
|
||||
@@ -24,7 +23,10 @@ from homeassistant.components.media_player.const import (
|
||||
SERVICE_SELECT_SOURCE,
|
||||
SUPPORT_TURN_ON,
|
||||
)
|
||||
from homeassistant.components.samsungtv.const import DOMAIN as SAMSUNGTV_DOMAIN
|
||||
from homeassistant.components.samsungtv.const import (
|
||||
DEFAULT_TIMEOUT,
|
||||
DOMAIN as SAMSUNGTV_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.samsungtv.media_player import (
|
||||
CONF_TIMEOUT,
|
||||
SUPPORT_SAMSUNGTV,
|
||||
@@ -52,6 +54,7 @@ from homeassistant.const import (
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
@@ -131,7 +134,7 @@ AUTODETECT_WEBSOCKET = {
|
||||
"method": "websocket",
|
||||
"port": None,
|
||||
"host": "fake_auto",
|
||||
"timeout": None,
|
||||
"timeout": DEFAULT_TIMEOUT,
|
||||
}
|
||||
AUTODETECT_LEGACY = {
|
||||
"name": "HomeAssistant",
|
||||
@@ -140,7 +143,7 @@ AUTODETECT_LEGACY = {
|
||||
"method": "legacy",
|
||||
"port": None,
|
||||
"host": "fake_auto",
|
||||
"timeout": None,
|
||||
"timeout": DEFAULT_TIMEOUT,
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +178,7 @@ def mock_now():
|
||||
|
||||
async def setup_samsungtv(hass, config):
|
||||
"""Set up mock Samsung TV."""
|
||||
await samsungtv.async_setup(hass, config)
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user