Skip to content
Snippets Groups Projects
Unverified Commit e1b57d83 authored by epenet's avatar epenet Committed by GitHub
Browse files

Adjust config entry matching in SamsungTV (#67842)

parent 6f38eda1
No related branches found
No related tags found
No related merge requests found
...@@ -113,9 +113,9 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ...@@ -113,9 +113,9 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Set the unique id from the udn.""" """Set the unique id from the udn."""
assert self._host is not None assert self._host is not None
await self.async_set_unique_id(self._udn, raise_on_progress=raise_on_progress) await self.async_set_unique_id(self._udn, raise_on_progress=raise_on_progress)
if (entry := self._async_update_existing_host_entry()) and _entry_is_complete( if (
entry entry := self._async_update_existing_matching_entry()
): ) and _entry_is_complete(entry):
raise data_entry_flow.AbortFlow("already_configured") raise data_entry_flow.AbortFlow("already_configured")
def _async_update_and_abort_for_matching_unique_id(self) -> None: def _async_update_and_abort_for_matching_unique_id(self) -> None:
...@@ -215,21 +215,25 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ...@@ -215,21 +215,25 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA) return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)
@callback @callback
def _async_update_existing_host_entry(self) -> config_entries.ConfigEntry | None: def _async_get_existing_matching_entry(self) -> config_entries.ConfigEntry | None:
"""Check existing entries and update them. """Get first existing matching entry."""
Returns the existing entry if it was updated.
"""
for entry in self._async_current_entries(include_ignore=False): for entry in self._async_current_entries(include_ignore=False):
mac = entry.data.get(CONF_MAC) mac = entry.data.get(CONF_MAC)
mac_match = mac and self._mac and mac == self._mac mac_match = mac and self._mac and mac == self._mac
upnp_udn_match = self._upnp_udn and self._upnp_udn == entry.unique_id upnp_udn_match = self._upnp_udn and self._upnp_udn == entry.unique_id
if ( if entry.data[CONF_HOST] == self._host or mac_match or upnp_udn_match:
entry.data[CONF_HOST] != self._host return entry
and not mac_match return None
and not upnp_udn_match
): @callback
continue def _async_update_existing_matching_entry(
self,
) -> config_entries.ConfigEntry | None:
"""Check existing entries and update them.
Returns the existing entry if it was updated.
"""
if entry := self._async_get_existing_matching_entry():
entry_kw_args: dict = {} entry_kw_args: dict = {}
if (self._udn and self._upnp_udn and self._upnp_udn != self._udn) or ( if (self._udn and self._upnp_udn and self._upnp_udn != self._udn) or (
self.unique_id and entry.unique_id is None self.unique_id and entry.unique_id is None
...@@ -248,7 +252,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ...@@ -248,7 +252,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def _async_start_discovery_with_mac_address(self) -> None: async def _async_start_discovery_with_mac_address(self) -> None:
"""Start discovery.""" """Start discovery."""
assert self._host is not None assert self._host is not None
if (entry := self._async_update_existing_host_entry()) and entry.unique_id: if (entry := self._async_update_existing_matching_entry()) and entry.unique_id:
# If we have the unique id and the mac we abort # If we have the unique id and the mac we abort
# as we do not need anything else # as we do not need anything else
raise data_entry_flow.AbortFlow("already_configured") raise data_entry_flow.AbortFlow("already_configured")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment