mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Ensure host is always set with samsungtv SSDP discovery (#51527)
There was a case where self._host could have been None before _async_set_unique_id_from_udn was called Fixes #51186
This commit is contained in:
parent
984695e99d
commit
8c00c24234
@ -112,6 +112,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def _async_set_unique_id_from_udn(self, raise_on_progress=True):
|
async def _async_set_unique_id_from_udn(self, raise_on_progress=True):
|
||||||
"""Set the unique id from the udn."""
|
"""Set the unique id from the udn."""
|
||||||
|
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)
|
||||||
self._async_update_existing_host_entry(self._host)
|
self._async_update_existing_host_entry(self._host)
|
||||||
updates = {CONF_HOST: self._host}
|
updates = {CONF_HOST: self._host}
|
||||||
@ -206,30 +207,28 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
return entry
|
return entry
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def _async_start_discovery_for_host(self, host):
|
async def _async_start_discovery(self):
|
||||||
"""Start discovery for a host."""
|
"""Start discovery."""
|
||||||
if entry := self._async_update_existing_host_entry(host):
|
assert self._host is not None
|
||||||
|
if entry := self._async_update_existing_host_entry(self._host):
|
||||||
if entry.unique_id:
|
if entry.unique_id:
|
||||||
# Let the flow continue to fill the missing
|
# Let the flow continue to fill the missing
|
||||||
# unique id as we may be able to obtain it
|
# unique id as we may be able to obtain it
|
||||||
# in the next step
|
# in the next step
|
||||||
raise data_entry_flow.AbortFlow("already_configured")
|
raise data_entry_flow.AbortFlow("already_configured")
|
||||||
|
|
||||||
self.context[CONF_HOST] = host
|
self.context[CONF_HOST] = self._host
|
||||||
for progress in self._async_in_progress():
|
for progress in self._async_in_progress():
|
||||||
if progress.get("context", {}).get(CONF_HOST) == host:
|
if progress.get("context", {}).get(CONF_HOST) == self._host:
|
||||||
raise data_entry_flow.AbortFlow("already_in_progress")
|
raise data_entry_flow.AbortFlow("already_in_progress")
|
||||||
|
|
||||||
self._host = host
|
|
||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: DiscoveryInfoType):
|
async def async_step_ssdp(self, discovery_info: DiscoveryInfoType):
|
||||||
"""Handle a flow initialized by ssdp discovery."""
|
"""Handle a flow initialized by ssdp discovery."""
|
||||||
LOGGER.debug("Samsung device found via SSDP: %s", discovery_info)
|
LOGGER.debug("Samsung device found via SSDP: %s", discovery_info)
|
||||||
self._udn = _strip_uuid(discovery_info[ATTR_UPNP_UDN])
|
self._udn = _strip_uuid(discovery_info[ATTR_UPNP_UDN])
|
||||||
|
self._host = urlparse(discovery_info[ATTR_SSDP_LOCATION]).hostname
|
||||||
await self._async_set_unique_id_from_udn()
|
await self._async_set_unique_id_from_udn()
|
||||||
await self._async_start_discovery_for_host(
|
await self._async_start_discovery()
|
||||||
urlparse(discovery_info[ATTR_SSDP_LOCATION]).hostname
|
|
||||||
)
|
|
||||||
self._manufacturer = discovery_info[ATTR_UPNP_MANUFACTURER]
|
self._manufacturer = discovery_info[ATTR_UPNP_MANUFACTURER]
|
||||||
if not self._manufacturer or not self._manufacturer.lower().startswith(
|
if not self._manufacturer or not self._manufacturer.lower().startswith(
|
||||||
"samsung"
|
"samsung"
|
||||||
@ -245,7 +244,8 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a flow initialized by dhcp discovery."""
|
"""Handle a flow initialized by dhcp discovery."""
|
||||||
LOGGER.debug("Samsung device found via DHCP: %s", discovery_info)
|
LOGGER.debug("Samsung device found via DHCP: %s", discovery_info)
|
||||||
self._mac = discovery_info[MAC_ADDRESS]
|
self._mac = discovery_info[MAC_ADDRESS]
|
||||||
await self._async_start_discovery_for_host(discovery_info[IP_ADDRESS])
|
self._host = discovery_info[IP_ADDRESS]
|
||||||
|
await self._async_start_discovery()
|
||||||
await self._async_set_device_unique_id()
|
await self._async_set_device_unique_id()
|
||||||
self.context["title_placeholders"] = {"device": self._title}
|
self.context["title_placeholders"] = {"device": self._title}
|
||||||
return await self.async_step_confirm()
|
return await self.async_step_confirm()
|
||||||
@ -254,7 +254,8 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a flow initialized by zeroconf discovery."""
|
"""Handle a flow initialized by zeroconf discovery."""
|
||||||
LOGGER.debug("Samsung device found via ZEROCONF: %s", discovery_info)
|
LOGGER.debug("Samsung device found via ZEROCONF: %s", discovery_info)
|
||||||
self._mac = format_mac(discovery_info[ATTR_PROPERTIES]["deviceid"])
|
self._mac = format_mac(discovery_info[ATTR_PROPERTIES]["deviceid"])
|
||||||
await self._async_start_discovery_for_host(discovery_info[CONF_HOST])
|
self._host = discovery_info[CONF_HOST]
|
||||||
|
await self._async_start_discovery()
|
||||||
await self._async_set_device_unique_id()
|
await self._async_set_device_unique_id()
|
||||||
self.context["title_placeholders"] = {"device": self._title}
|
self.context["title_placeholders"] = {"device": self._title}
|
||||||
return await self.async_step_confirm()
|
return await self.async_step_confirm()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user