Skip to content

Commit

Permalink
Merge pull request #112 from uvjim/attempt-to-fix-host-overwriting-wi…
Browse files Browse the repository at this point in the history
…th-ipv6
  • Loading branch information
uvjim authored Nov 28, 2024
2 parents efd6f59 + 6891820 commit a651ebc
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions custom_components/hdhomerun/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

import asyncio
import ipaddress
import json
import logging
from enum import StrEnum, auto
Expand Down Expand Up @@ -374,19 +375,30 @@ async def async_step_ssdp(

# region #-- set a unique_id, update details if device has changed IP --#
_LOGGER.debug(self.format("setting unique_id: %s"), serial)
await self.async_set_unique_id(unique_id=serial)
matching_instance: (
list[config_entries.ConfigEntry] | config_entries.ConfigEntry
) = list(self.hass.config_entries.async_entries(DOMAIN))
if matching_instance:
matching_instance = matching_instance[0]
if matching_instance.source == "ssdp":
_LOGGER.debug(self.format("instance already configured, updating host"))
self._abort_if_unique_id_configured(updates={CONF_HOST: self._host})
config_entry: config_entries.ConfigEntry = await self.async_set_unique_id(
unique_id=serial
)
if config_entry.source == "ssdp":
ip: ipaddress.IPv4Address | ipaddress.IPv6Address = ipaddress.ip_address(
self._host
)
if ip.version == 4:
if self._host != config_entry.data.get(CONF_HOST):
_LOGGER.debug(
self.format("instance already configured, updating host")
)
self._abort_if_unique_id_configured(updates={CONF_HOST: self._host})
else:
_LOGGER.debug(
self.format("instance already configured, no change in host")
)
self._abort_if_unique_id_configured()
else:
_LOGGER.debug(
self.format("instance already configured, not updating host")
self.format("instance already configured, rejecting IPv6 address")
)
else:
_LOGGER.debug(self.format("instance already configured, not updating host"))
# endregion

self.context["title_placeholders"] = {
Expand Down

0 comments on commit a651ebc

Please sign in to comment.