mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 00:10:20 +00:00
Updated Broadlink for port binding, added debug for RM2 Device ir call
data return, updated Harmony library to be the latest version.
This commit is contained in:
14
pom.xml
14
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>5.2.0RC10</version>
|
||||
<version>5.2.0RC11</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.bwssytems</groupId>
|
||||
<artifactId>harmony-java-client</artifactId>
|
||||
<version>1.1.5</version>
|
||||
<version>master-SNAPSHOT</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@@ -84,12 +84,12 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
<version>1.7.24</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.5</version>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
@@ -104,12 +104,12 @@
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>4.0-beta4</version>
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.igniterealtime.smack</groupId>
|
||||
<artifactId>smack-core</artifactId>
|
||||
<version>4.0.7</version>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
@@ -119,7 +119,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.bwssytems</groupId>
|
||||
|
||||
@@ -45,6 +45,7 @@ public class HABridge {
|
||||
@SuppressWarnings("unused")
|
||||
HttpClientPool thePool;
|
||||
|
||||
log.info("HA Bridge startup sequence...");
|
||||
theVersion = new Version();
|
||||
// Singleton initialization
|
||||
thePool = new HttpClientPool();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.bwssystems.HABridge.plugins.broadlink;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.BindException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -62,13 +64,15 @@ public class BroadlinkHome implements Home {
|
||||
log.info("Broadlink Home created." + (validBroadlink ? "" : " No Broadlinks configured.") + (isDevMode ? " DevMode is set." : ""));
|
||||
if(validBroadlink) {
|
||||
broadlinkMap = new HashMap<String, BLDevice>();
|
||||
int aDiscoverPort = Configuration.BROADLINK_DISCOVER_PORT;
|
||||
while(aDiscoverPort > 0) {
|
||||
try {
|
||||
log.info("Broadlink discover....");
|
||||
if(isDevMode) {
|
||||
clients = TestBLDevice.discoverDevices(InetAddress.getByName(bridgeSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress()), Configuration.BROADLINK_DISCOVER_PORT, Configuration.BROADLINK_DISCONVER_TIMEOUT);
|
||||
clients = TestBLDevice.discoverDevices(InetAddress.getByName(bridgeSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress()), aDiscoverPort, Configuration.BROADLINK_DISCONVER_TIMEOUT);
|
||||
}
|
||||
else
|
||||
clients = BLDevice.discoverDevices(InetAddress.getByName(bridgeSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress()), Configuration.BROADLINK_DISCOVER_PORT, Configuration.BROADLINK_DISCONVER_TIMEOUT);
|
||||
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;
|
||||
@@ -83,12 +87,18 @@ public class BroadlinkHome implements Home {
|
||||
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;
|
||||
}
|
||||
@@ -229,7 +239,9 @@ public class BroadlinkHome implements Home {
|
||||
try {
|
||||
if(!isDevMode)
|
||||
theDevice.auth();
|
||||
((RM2Device) theDevice).sendCmdPkt(Configuration.BROADLINK_DISCONVER_TIMEOUT, thePayload);
|
||||
DatagramPacket thePacket = ((RM2Device) theDevice).sendCmdPkt(Configuration.BROADLINK_DISCONVER_TIMEOUT, thePayload);
|
||||
String returnData = DatatypeConverter.printHexBinary(thePacket.getData());
|
||||
log.debug("RM2 Device data return: <<<" + returnData + ">>>");
|
||||
} catch (IOException e) {
|
||||
log.error("Call to " + _rm2 + " device failed with exception.", e);
|
||||
theReturn = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
|
||||
|
||||
@@ -19,9 +19,7 @@ import com.bwssystems.HABridge.NamedIP;
|
||||
import com.bwssystems.HABridge.plugins.homewizard.json.Device;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import us.monoid.json.JSONException;
|
||||
import us.monoid.json.JSONObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
/**
|
||||
* Control HomeWizard devices over HomeWizard Cloud
|
||||
@@ -75,10 +73,12 @@ public class HomeWizzardSmartPlugInfo {
|
||||
br.close();
|
||||
|
||||
// Get session id from result JSON
|
||||
JSONObject json = new JSONObject(buffer.toString());
|
||||
cloudSessionId = json.get("session").toString();
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject json = parser.parse(buffer.toString()).getAsJsonObject();
|
||||
|
||||
cloudSessionId = json.get("session").getAsString();
|
||||
}
|
||||
catch(IOException | JSONException e)
|
||||
catch(Exception e)
|
||||
{
|
||||
log.warn("Error while login to cloud service ", e);
|
||||
return false;
|
||||
@@ -191,8 +191,9 @@ public class HomeWizzardSmartPlugInfo {
|
||||
try {
|
||||
|
||||
String result = requestJson(EMPTY_STRING);
|
||||
JSONObject resultJson = new JSONObject(result);
|
||||
cloudPlugId = resultJson.getString("id");
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject resultJson = parser.parse(result).getAsJsonObject();
|
||||
cloudPlugId = resultJson.get("id").getAsString();
|
||||
|
||||
String all_devices_json = resultJson.get("devices").toString();
|
||||
Device[] devices = gson.fromJson(all_devices_json, Device[].class);
|
||||
@@ -203,7 +204,7 @@ public class HomeWizzardSmartPlugInfo {
|
||||
homewizardDevices.add(mapDeviceToHomeWizardSmartPlugDevice(device));
|
||||
}
|
||||
}
|
||||
catch(JSONException e) {
|
||||
catch(Exception e) {
|
||||
log.warn("Error while get devices from cloud service ", e);
|
||||
}
|
||||
|
||||
@@ -211,12 +212,13 @@ public class HomeWizzardSmartPlugInfo {
|
||||
return homewizardDevices;
|
||||
}
|
||||
|
||||
public void execApply(String jsonToPost) throws JSONException, IOException {
|
||||
public void execApply(String jsonToPost) throws Exception {
|
||||
|
||||
// Extract
|
||||
JSONObject resultJson = new JSONObject(jsonToPost);
|
||||
String deviceId = resultJson.getString("deviceid");
|
||||
String action = resultJson.getString("action");
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject resultJson = parser.parse(jsonToPost).getAsJsonObject();
|
||||
String deviceId = resultJson.get("deviceid").getAsString();
|
||||
String action = resultJson.get("action").getAsString();
|
||||
|
||||
// Check if we have an plug id stored
|
||||
if (StringUtils.isBlank(cloudPlugId)) {
|
||||
|
||||
Reference in New Issue
Block a user