Fix songpal already configured check in config flow (#37813)

* Fix already configured check

* Mark endpoint duplicate check as callback
This commit is contained in:
Xiaonan Shen 2020-07-29 07:49:43 +08:00 committed by Paulus Schoutsen
parent 7a2f6a5006
commit 1b73bcbff7

View file

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import ssdp from homeassistant.components import ssdp
from homeassistant.const import CONF_HOST, CONF_NAME from homeassistant.const import CONF_HOST, CONF_NAME
from homeassistant.core import callback
from .const import CONF_ENDPOINT, DOMAIN # pylint: disable=unused-import from .const import CONF_ENDPOINT, DOMAIN # pylint: disable=unused-import
@ -74,7 +75,7 @@ class SongpalConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_init(self, user_input=None): async def async_step_init(self, user_input=None):
"""Handle a flow start.""" """Handle a flow start."""
# Check if already configured # Check if already configured
if self._endpoint_already_configured(): if self._async_endpoint_already_configured():
return self.async_abort(reason="already_configured") return self.async_abort(reason="already_configured")
if user_input is None: if user_input is None:
@ -145,9 +146,10 @@ class SongpalConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return await self.async_step_init(user_input) return await self.async_step_init(user_input)
def _endpoint_already_configured(self): @callback
def _async_endpoint_already_configured(self):
"""See if we already have an endpoint matching user input configured.""" """See if we already have an endpoint matching user input configured."""
existing_endpoints = [ for entry in self._async_current_entries():
entry.data[CONF_ENDPOINT] for entry in self._async_current_entries() if entry.data.get(CONF_ENDPOINT) == self.conf.endpoint:
] return True
return self.conf.endpoint in existing_endpoints return False