From 879d3b5326e33e5a533f2b906f801237e2276180 Mon Sep 17 00:00:00 2001 From: bsamuels Date: Wed, 31 Jan 2018 12:19:06 -0600 Subject: [PATCH] Fixed broadlink discover loop --- pom.xml | 2 +- .../plugins/broadlink/BroadlinkHome.java | 59 ++++++++++--------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index 118516f..ac4959d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 5.2.0RC11 + 5.2.0RC12 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java index 8916ad0..4e4cdd1 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java @@ -66,38 +66,39 @@ public class BroadlinkHome implements Home { broadlinkMap = new HashMap(); int aDiscoverPort = Configuration.BROADLINK_DISCOVER_PORT; while(aDiscoverPort > 0) { - try { - log.info("Broadlink discover...."); - if(isDevMode) { - clients = TestBLDevice.discoverDevices(InetAddress.getByName(bridgeSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress()), aDiscoverPort, Configuration.BROADLINK_DISCONVER_TIMEOUT); - } - else - clients = BLDevice.discoverDevices(InetAddress.getByName(bridgeSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress()), aDiscoverPort, Configuration.BROADLINK_DISCONVER_TIMEOUT); - if(clients.length <= 0) { - log.warn("Did not discover any Broadlinks, try again with bridge reinitialization"); + try { + log.info("Broadlink discover...."); + if(isDevMode) { + clients = TestBLDevice.discoverDevices(InetAddress.getByName(bridgeSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress()), aDiscoverPort, Configuration.BROADLINK_DISCONVER_TIMEOUT); + } + else + clients = BLDevice.discoverDevices(InetAddress.getByName(bridgeSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress()), aDiscoverPort, Configuration.BROADLINK_DISCONVER_TIMEOUT); + if(clients.length <= 0) { + log.warn("Did not discover any Broadlinks, try again with bridge reinitialization"); + broadlinkMap = null; + validBroadlink = false; + return this; + } + for(int i = 0; i < clients.length; i++) { + if(clients[i].getDeviceType() != BLDevice.DEV_A1) { + broadlinkMap.put(clients[i].getHost() + "-" + String.format("%04x", clients[i].getDeviceType()), clients[i]); + log.debug("Adding Device to Map - host: " + clients[i].getHost() + ", device Type: " + clients[i].getDeviceDescription() + ", mac: " + (clients[i].getMac() == null ? "no Mac in client" : clients[i].getMac().getMacString())); + } else { + log.debug("Ignoring A1 Device - host: " + clients[i].getHost() + ", device Type: " + clients[i].getDeviceDescription() + ", mac: " + (clients[i].getMac() == null ? "no Mac in client" : clients[i].getMac().getMacString())); + } + } + aDiscoverPort = 0; + } catch (BindException e) { + log.warn("Could not discover Broadlinks, Port in use, increasing by 11"); + aDiscoverPort += 11; + if(aDiscoverPort > Configuration.BROADLINK_DISCOVER_PORT + 110) + aDiscoverPort = 0; + } catch (IOException e) { + log.warn("Could not discover Broadlinks, with IO Exception", e); broadlinkMap = null; validBroadlink = false; - return this; - } - for(int i = 0; i < clients.length; i++) { - if(clients[i].getDeviceType() != BLDevice.DEV_A1) { - broadlinkMap.put(clients[i].getHost() + "-" + String.format("%04x", clients[i].getDeviceType()), clients[i]); - log.debug("Adding Device to Map - host: " + clients[i].getHost() + ", device Type: " + clients[i].getDeviceDescription() + ", mac: " + (clients[i].getMac() == null ? "no Mac in client" : clients[i].getMac().getMacString())); - } else { - log.debug("Ignoring A1 Device - host: " + clients[i].getHost() + ", device Type: " + clients[i].getDeviceDescription() + ", mac: " + (clients[i].getMac() == null ? "no Mac in client" : clients[i].getMac().getMacString())); - } - } - } catch (BindException e) { - log.warn("Could not discover Broadlinks, Port in use, increasing by 11"); - aDiscoverPort += 11; - if(aDiscoverPort > Configuration.BROADLINK_DISCOVER_PORT + 110) aDiscoverPort = 0; - } catch (IOException e) { - log.warn("Could not discover Broadlinks, with IO Exception", e); - broadlinkMap = null; - validBroadlink = false; - return this; - } + } } } return this;