Skip to content

Commit

Permalink
Specify a unique ID for config flows to prevent adding the same devic…
Browse files Browse the repository at this point in the history
…e twice
  • Loading branch information
Jalle19 committed Sep 13, 2024
1 parent 0b2d56c commit b4faeac
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions custom_components/extron/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.helpers.device_registry import format_mac
from homeassistant.helpers.selector import selector

from .const import CONF_DEVICE_TYPE, CONF_HOST, CONF_PASSWORD, CONF_PORT, DOMAIN, OPTION_INPUT_NAMES
Expand Down Expand Up @@ -51,6 +52,11 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None):
model_name = await extron_device.query_model_name()
title = f"Extron {model_name}"

# Make a unique ID for the entry, prevent adding the same device twice
unique_id = format_mac(await extron_device.query_mac_address())
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()

# Disconnect, we'll connect again later, this was just for validation
await extron_device.disconnect()
except AuthenticationError:
Expand Down

0 comments on commit b4faeac

Please sign in to comment.