Fix reconfigure by SSDP or Zeroconf discovery in Synology DSM (#92088)
This commit is contained in:
parent
29ca43acf6
commit
4e7f39e3d0
2 changed files with 20 additions and 21 deletions
|
@ -2,7 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from ipaddress import ip_address
|
||||
from ipaddress import ip_address as ip
|
||||
import logging
|
||||
from typing import Any, cast
|
||||
from urllib.parse import urlparse
|
||||
|
@ -38,6 +38,7 @@ from homeassistant.data_entry_flow import FlowResult
|
|||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
from homeassistant.util.network import is_ip_address as is_ip
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE_TOKEN,
|
||||
|
@ -99,14 +100,6 @@ def _ordered_shared_schema(
|
|||
}
|
||||
|
||||
|
||||
def _is_valid_ip(text: str) -> bool:
|
||||
try:
|
||||
ip_address(text)
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def format_synology_mac(mac: str) -> str:
|
||||
"""Format a mac address to the format used by Synology DSM."""
|
||||
return mac.replace(":", "").replace("-", "").upper()
|
||||
|
@ -284,16 +277,12 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
break
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
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 is_ip(existing_entry.data[CONF_HOST])
|
||||
and is_ip(host)
|
||||
and existing_entry.data[CONF_HOST] != host
|
||||
and not fqdn_with_ssl_verification
|
||||
and ip(existing_entry.data[CONF_HOST]).version == ip(host).version
|
||||
):
|
||||
_LOGGER.info(
|
||||
"Update host from '%s' to '%s' for NAS '%s' via discovery",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue