Skip to content

Commit

Permalink
Rearrange/improve
Browse files Browse the repository at this point in the history
  • Loading branch information
bouwew committed Oct 15, 2024
1 parent 661ee99 commit 5187186
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions homeassistant/components/plugwise/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,22 @@ async def async_step_zeroconf(
"""Prepare configuration for a discovered Plugwise Smile."""
self.discovery_info = discovery_info
_properties = discovery_info.properties
_version = _properties.get("version", "n/a")
self.product = _product = _properties.get("product", "Unknown Smile")

unique_id = discovery_info.hostname.split(".")[0].split("-")[0]
if DEFAULT_USERNAME not in unique_id:
self._username = STRETCH_USERNAME

if config_entry := await self.async_set_unique_id(unique_id):
try:
await validate_input(
self.hass,
{
CONF_HOST: discovery_info.host,
CONF_PORT: discovery_info.port,
CONF_USERNAME: config_entry.data[CONF_USERNAME],
CONF_PASSWORD: config_entry.data[CONF_PASSWORD],
CONF_USERNAME: self._username,
},
)
except Exception: # noqa: BLE001
Expand All @@ -129,12 +134,6 @@ async def async_step_zeroconf(
}
)

if DEFAULT_USERNAME not in unique_id:
self._username = STRETCH_USERNAME
self.product = _product = _properties.get("product", "Unknown Smile")
_version = _properties.get("version", "n/a")
_name = f"{ZEROCONF_MAP.get(_product, _product)} v{_version}"

# This is an Anna, but we already have config entries.
# Assuming that the user has already configured Adam, aborting discovery.
if self._async_current_entries() and _product == "smile_thermo":
Expand All @@ -146,6 +145,7 @@ async def async_step_zeroconf(
if self.hass.config_entries.flow.async_has_matching_flow(self):
return self.async_abort(reason="anna_with_adam")

_name = f"{ZEROCONF_MAP.get(_product, _product)} v{_version}"
self.context.update(
{
"title_placeholders": {CONF_NAME: _name},
Expand Down

0 comments on commit 5187186

Please sign in to comment.