mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Skip auto-update when fqdn and ssl-verfiy is used for Synology DSM (#57568)
This commit is contained in:
parent
a6aff613d7
commit
445c7301f8
@ -1,6 +1,7 @@
|
||||
"""Config flow to configure the Synology DSM integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from ipaddress import ip_address
|
||||
import logging
|
||||
from typing import Any
|
||||
from urllib.parse import urlparse
|
||||
@ -92,6 +93,14 @@ def _ordered_shared_schema(
|
||||
}
|
||||
|
||||
|
||||
def _is_valid_ip(text: str) -> bool:
|
||||
try:
|
||||
ip_address(text)
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow."""
|
||||
|
||||
@ -245,7 +254,17 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
if not existing_entry:
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
if existing_entry and existing_entry.data[CONF_HOST] != parsed_url.hostname:
|
||||
fqdn_with_ssl_verification = (
|
||||
existing_entry
|
||||
and not _is_valid_ip(existing_entry.data[CONF_HOST])
|
||||
and existing_entry.data[CONF_VERIFY_SSL]
|
||||
)
|
||||
|
||||
if (
|
||||
existing_entry
|
||||
and existing_entry.data[CONF_HOST] != parsed_url.hostname
|
||||
and not fqdn_with_ssl_verification
|
||||
):
|
||||
_LOGGER.debug(
|
||||
"Update host from '%s' to '%s' for NAS '%s' via SSDP discovery",
|
||||
existing_entry.data[CONF_HOST],
|
||||
|
@ -423,6 +423,7 @@ async def test_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_HOST: "wrong_host",
|
||||
CONF_VERIFY_SSL: VERIFY_SSL,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
CONF_MAC: MACS,
|
||||
@ -443,6 +444,34 @@ async def test_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
|
||||
|
||||
async def test_skip_reconfig_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||
"""Test re-configuration of already existing entry by ssdp."""
|
||||
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_HOST: "wrong_host",
|
||||
CONF_VERIFY_SSL: True,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
CONF_MAC: MACS,
|
||||
},
|
||||
unique_id=SERIAL,
|
||||
).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_SSDP},
|
||||
data={
|
||||
ssdp.ATTR_SSDP_LOCATION: "http://192.168.1.5:5000",
|
||||
ssdp.ATTR_UPNP_FRIENDLY_NAME: "mydsm",
|
||||
ssdp.ATTR_UPNP_SERIAL: "001132XXXX59", # Existing in MACS[0], but SSDP does not have `-`
|
||||
},
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_existing_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||
"""Test abort of already existing entry by ssdp."""
|
||||
|
||||
@ -450,6 +479,7 @@ async def test_existing_ssdp(hass: HomeAssistant, service: MagicMock):
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_HOST: "192.168.1.5",
|
||||
CONF_VERIFY_SSL: VERIFY_SSL,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
CONF_MAC: MACS,
|
||||
|
Loading…
x
Reference in New Issue
Block a user