Passively discover devices and update IP addresses
This commit is contained in:
@@ -21,15 +21,13 @@ from .const import ( # pylint: disable=unused-import
|
||||
CONF_LOCAL_KEY,
|
||||
CONF_PROTOCOL_VERSION,
|
||||
CONF_DPS_STRINGS,
|
||||
DATA_DISCOVERY,
|
||||
DOMAIN,
|
||||
PLATFORMS,
|
||||
)
|
||||
from .discovery import discover
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DISCOVER_TIMEOUT = 6.0
|
||||
|
||||
PLATFORM_TO_ADD = "platform_to_add"
|
||||
NO_ADDITIONAL_PLATFORMS = "no_additional_platforms"
|
||||
DISCOVERED_DEVICE = "discovered_device"
|
||||
@@ -211,16 +209,12 @@ class LocaltuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self.selected_device = user_input[DISCOVERED_DEVICE].split(" ")[0]
|
||||
return await self.async_step_basic_info()
|
||||
|
||||
try:
|
||||
devices = await discover(DISCOVER_TIMEOUT, self.hass.loop)
|
||||
self.devices = {
|
||||
ip: dev
|
||||
for ip, dev in devices.items()
|
||||
if dev["gwId"] not in self._async_current_ids()
|
||||
}
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("discovery failed")
|
||||
errors["base"] = "discovery_failed"
|
||||
devices = self.hass.data[DOMAIN][DATA_DISCOVERY].devices
|
||||
self.devices = {
|
||||
ip: dev
|
||||
for ip, dev in devices.items()
|
||||
if dev["gwId"] not in self._async_current_ids()
|
||||
}
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", errors=errors, data_schema=user_schema(self.devices)
|
||||
|
Reference in New Issue
Block a user