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