mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 05:06:13 +01:00
Synology DSM: Don't reinitialize API during configuration (#153739)
This commit is contained in:
committed by
GitHub
parent
d9691c2a3b
commit
42370ba203
@@ -143,6 +143,7 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
self.reauth_conf: Mapping[str, Any] = {}
|
||||
self.reauth_reason: str | None = None
|
||||
self.shares: list[SynoFileSharedFolder] | None = None
|
||||
self.api: SynologyDSM | None = None
|
||||
|
||||
def _show_form(
|
||||
self,
|
||||
@@ -156,6 +157,7 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
description_placeholders = {}
|
||||
data_schema = None
|
||||
self.api = None
|
||||
|
||||
if step_id == "link":
|
||||
user_input.update(self.discovered_conf)
|
||||
@@ -194,14 +196,21 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
else:
|
||||
port = DEFAULT_PORT
|
||||
|
||||
session = async_get_clientsession(self.hass, verify_ssl)
|
||||
api = SynologyDSM(
|
||||
session, host, port, username, password, use_ssl, timeout=DEFAULT_TIMEOUT
|
||||
)
|
||||
if self.api is None:
|
||||
session = async_get_clientsession(self.hass, verify_ssl)
|
||||
self.api = SynologyDSM(
|
||||
session,
|
||||
host,
|
||||
port,
|
||||
username,
|
||||
password,
|
||||
use_ssl,
|
||||
timeout=DEFAULT_TIMEOUT,
|
||||
)
|
||||
|
||||
errors = {}
|
||||
try:
|
||||
serial = await _login_and_fetch_syno_info(api, otp_code)
|
||||
serial = await _login_and_fetch_syno_info(self.api, otp_code)
|
||||
except SynologyDSMLogin2SARequiredException:
|
||||
return await self.async_step_2sa(user_input)
|
||||
except SynologyDSMLogin2SAFailedException:
|
||||
@@ -221,10 +230,11 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
errors["base"] = "missing_data"
|
||||
|
||||
if errors:
|
||||
self.api = None
|
||||
return self._show_form(step_id, user_input, errors)
|
||||
|
||||
with suppress(*SYNOLOGY_CONNECTION_EXCEPTIONS):
|
||||
self.shares = await api.file.get_shared_folders(only_writable=True)
|
||||
self.shares = await self.api.file.get_shared_folders(only_writable=True)
|
||||
|
||||
if self.shares and not backup_path:
|
||||
return await self.async_step_backup_share(user_input)
|
||||
@@ -239,14 +249,14 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
CONF_VERIFY_SSL: verify_ssl,
|
||||
CONF_USERNAME: username,
|
||||
CONF_PASSWORD: password,
|
||||
CONF_MAC: api.network.macs,
|
||||
CONF_MAC: self.api.network.macs,
|
||||
}
|
||||
config_options = {
|
||||
CONF_BACKUP_PATH: backup_path,
|
||||
CONF_BACKUP_SHARE: backup_share,
|
||||
}
|
||||
if otp_code:
|
||||
config_data[CONF_DEVICE_TOKEN] = api.device_token
|
||||
config_data[CONF_DEVICE_TOKEN] = self.api.device_token
|
||||
if user_input.get(CONF_DISKS):
|
||||
config_data[CONF_DISKS] = user_input[CONF_DISKS]
|
||||
if user_input.get(CONF_VOLUMES):
|
||||
|
||||
@@ -252,9 +252,7 @@ async def test_user_2sa(
|
||||
assert result["step_id"] == "2sa"
|
||||
|
||||
# Failed the first time because was too slow to enter the code
|
||||
service_2sa.return_value.login = Mock(
|
||||
side_effect=SynologyDSMLogin2SAFailedException
|
||||
)
|
||||
service_2sa.login = AsyncMock(side_effect=SynologyDSMLogin2SAFailedException)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {CONF_OTP_CODE: "000000"}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user