mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 08:13:23 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e0fd6c21b | ||
|
|
3bf52f5da0 | ||
|
|
bd856d8f9e | ||
|
|
73b2be752e | ||
|
|
dda7a7a34a | ||
|
|
f238e05533 | ||
|
|
9a1924422e |
18
README.md
18
README.md
@@ -86,6 +86,8 @@ The user name of the MyHarmony.com account for the Harmony Hub. This needs to be
|
||||
The password for the user name of the MyHarmony.com account for the Harmony Hub. This needs to be given if you are using the Harmony Hub Features.
|
||||
#### Hue Names and IP Addresses
|
||||
Provide IP Addresses of your Hue Bridges that you want to proxy through the bridge. Also, give a meaningful name to each one so it is easy to decipher in the helper tab. When these names and IP's are given, the bridge will passthru the call it receives to the target Hue and device you configure.
|
||||
|
||||
Don't forget - You will need to push the link button when you got to the Hue Tab the first time ater the process comes up. (The user name is not persistent when the process comes up.)
|
||||
#### Nest Username
|
||||
The user name of the home.nest.com account for the Nest user. This needs to be given if you are using the Nest features. There is no need to give any ip address or host information as this contacts your cloud account.
|
||||
#### Nest Password
|
||||
@@ -117,7 +119,7 @@ The helper tabs will also show you what you have already configured for that tar
|
||||
#### The Manual Add Tab
|
||||
Another way to add a device is through the Manual Add Tab. This allows you to manually enter the name, the on and off URLs and select if there are custom handling with the type of call that can be made. This allows for control of anything that has a distinct request that can be executed so you are not limited to the Vera, Harmony, Nest or other Hue.
|
||||
|
||||
The format of these can be the default HTTP request which executes the URLs formatted as http://<your stuff here> as a GET. Other options to this are to select the HTTP Verb and add the data type and add a body that is passed with the request. Secure https is supported as well, just use https://<your secure call here>. When using POST and PUT, you have the ability to specify the body that will be sent with the request as well as the application type for the http call.
|
||||
The format of these can be the default HTTP request which executes the URLs formatted as `http://<your stuff here>` as a GET. Other options to this are to select the HTTP Verb and add the data type and add a body that is passed with the request. Secure https is supported as well, just use `https://<your secure call here>`. When using POST and PUT, you have the ability to specify the body that will be sent with the request as well as the application type for the http call.
|
||||
|
||||
Headers can be added as well using a Json construct [{"name":"header type name","value":"the header value"}] with the format example:
|
||||
```
|
||||
@@ -125,7 +127,7 @@ Headers can be added as well using a Json construct [{"name":"header type name",
|
||||
{"name":"Pragma","value":"no-cache"}]
|
||||
```
|
||||
|
||||
Another option that is detected by the bridge is to use UDP or TCP direct calls such as udp://<ip_address>:<port>/<your stuff here> to send a UDP request. TCP calls are handled the same way as tcp://<ip_address>:<port>/<your stuff here>. If your data for the UDP or TCP request is formatted as "0x00F009B9" lexical hex format, the bridge will convert the data into a binary stream to send.
|
||||
Another option that is detected by the bridge is to use UDP or TCP direct calls such as `udp://<ip_address>:<port>/<your stuff here>` to send a UDP request. TCP calls are handled the same way as `tcp://<ip_address>:<port>/<your stuff here>`. If your data for the UDP or TCP request is formatted as "0x00F009B9" lexical hex format, the bridge will convert the data into a binary stream to send.
|
||||
|
||||
You can also use the value replacement constructs within these statements. Such as using the expressions ${intensity.percent} for 0-100 or ${intensity.byte} for 0-255 for straight pass through of the value or items that require special calculated values using ${intensity.math()} i.e. "${intensity.math(X/4)}".
|
||||
Examples:
|
||||
@@ -138,6 +140,14 @@ http://192.168.1.1:8280/set/this
|
||||
ContentBody: {"someValue":"${intensity..byte}"}
|
||||
|
||||
udp://192.168.1.1:5000/0x45${intensity.percent}55
|
||||
|
||||
udp://192.168.2.2:6000/fireoffthismessage\n
|
||||
|
||||
tcp://192.168.3.3:9000/sendthismessage
|
||||
|
||||
tcp://192.168.4.4:10000/0x435f12dd${intensity.math((X -4)*50)}438c
|
||||
|
||||
tcp://192.168.5.5:110000/0x
|
||||
```
|
||||
|
||||
#### Multiple Call Construct
|
||||
@@ -158,7 +168,7 @@ Format Example in the URL areas:
|
||||
{"item":"https://192.168.12.1/do/this/secure/thing"}]
|
||||
```
|
||||
#### Script or Command Execution
|
||||
The release as of v2.0.0 will no support the execution of a local script or program. This will blindly fire off a process to run and is bound by the privileges of the java process.
|
||||
The release as of v2.0.0 will now support the execution of a local script or program. This will blindly fire off a process to run and is bound by the privileges of the java process.
|
||||
|
||||
To configure this type of manual add, you will need to select the Device type of "Execute Script/Program".
|
||||
|
||||
@@ -951,4 +961,4 @@ To turn on debugging for the bridge, use the following extra parm in the command
|
||||
To turn on development mode so that it will not need an Harmony Hub for testing, use the following extra parm in the command line and the harmony ip and login info will not be needed:
|
||||
```
|
||||
java -jar -Ddev.mode=true ha-bridge-0.X.Y.jar
|
||||
```
|
||||
```
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
// import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -7,7 +8,7 @@ import java.util.List;
|
||||
*/
|
||||
public class DeviceState {
|
||||
private boolean on;
|
||||
private int bri = 255;
|
||||
private int bri;
|
||||
private int hue;
|
||||
private int sat;
|
||||
private String effect;
|
||||
@@ -96,7 +97,24 @@ public class DeviceState {
|
||||
public void setXy(List<Double> xy) {
|
||||
this.xy = xy;
|
||||
}
|
||||
|
||||
public static DeviceState createDeviceState() {
|
||||
DeviceState newDeviceState = new DeviceState();
|
||||
newDeviceState.fillIn();
|
||||
// newDeviceState.setColormode("none");
|
||||
// ArrayList<Double> doubleArray = new ArrayList<Double>();
|
||||
// doubleArray.add(new Double(0));
|
||||
// doubleArray.add(new Double(0));
|
||||
// newDeviceState.setXy(doubleArray);
|
||||
|
||||
return newDeviceState;
|
||||
}
|
||||
public void fillIn() {
|
||||
if(this.getAlert() == null)
|
||||
this.setAlert("none");
|
||||
if(this.getEffect() == null)
|
||||
this.setEffect("none");
|
||||
this.setReachable(true);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceState{" +
|
||||
|
||||
@@ -166,6 +166,8 @@ public class DeviceDescriptor{
|
||||
}
|
||||
|
||||
public DeviceState getDeviceState() {
|
||||
if(deviceState == null)
|
||||
deviceState = DeviceState.createDeviceState();
|
||||
return deviceState;
|
||||
}
|
||||
|
||||
|
||||
@@ -381,6 +381,7 @@ public class HueMulator implements HueErrorStringSet {
|
||||
responseString = "[{\"error\":{\"type\": 3, \"address\": \"/lights/" + lightId + "\",\"description\": \"Could not find device\", \"resource\": \"/lights/" + lightId + "\"}}]";
|
||||
return responseString;
|
||||
}
|
||||
state.fillIn();
|
||||
|
||||
theHeaders = new Gson().fromJson(device.getHeaders(), NameValue[].class);
|
||||
responseString = this.formatSuccessHueResponse(state, request.body(), lightId);
|
||||
@@ -582,41 +583,43 @@ public class HueMulator implements HueErrorStringSet {
|
||||
Thread.sleep(bridgeSettings.getButtonsleep());
|
||||
}
|
||||
try {
|
||||
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
|
||||
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
|
||||
String theUrlBody = intermediate.substring(intermediate.indexOf('/')+1);
|
||||
String hostAddr = null;
|
||||
String port = null;
|
||||
if(hostPortion.contains(":")) {
|
||||
hostAddr = hostPortion.substring(0, intermediate.indexOf(':'));
|
||||
port = hostPortion.substring(intermediate.indexOf(':') + 1);
|
||||
}
|
||||
else
|
||||
hostAddr = hostPortion;
|
||||
InetAddress IPAddress = InetAddress.getByName(hostAddr);;
|
||||
if(theUrlBody.startsWith("0x")) {
|
||||
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), true);
|
||||
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
|
||||
}
|
||||
else {
|
||||
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), false);
|
||||
sendData = theUrlBody.getBytes();
|
||||
}
|
||||
if(callItems[i].getItem().contains("udp://")) {
|
||||
log.debug("executing HUE api request to UDP: " + callItems[i].getItem());
|
||||
DatagramSocket responseSocket = new DatagramSocket(Integer.parseInt(port));
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Integer.parseInt(port));
|
||||
responseSocket.send(sendPacket);
|
||||
responseSocket.close();
|
||||
}
|
||||
else if(callItems[i].getItem().contains("tcp://"))
|
||||
{
|
||||
log.debug("executing HUE api request to TCP: " + callItems[i].getItem());
|
||||
Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port));
|
||||
DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream());
|
||||
outToClient.write(sendData);
|
||||
outToClient.flush();
|
||||
dataSendSocket.close();
|
||||
if(callItems[i].getItem().contains("udp://") || callItems[i].getItem().contains("tcp://")) {
|
||||
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
|
||||
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
|
||||
String theUrlBody = intermediate.substring(intermediate.indexOf('/')+1);
|
||||
String hostAddr = null;
|
||||
String port = null;
|
||||
if(hostPortion.contains(":")) {
|
||||
hostAddr = hostPortion.substring(0, intermediate.indexOf(':'));
|
||||
port = hostPortion.substring(intermediate.indexOf(':') + 1);
|
||||
}
|
||||
else
|
||||
hostAddr = hostPortion;
|
||||
InetAddress IPAddress = InetAddress.getByName(hostAddr);;
|
||||
if(theUrlBody.startsWith("0x")) {
|
||||
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), true);
|
||||
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
|
||||
}
|
||||
else {
|
||||
theUrlBody = replaceIntensityValue(theUrlBody, state.getBri(), false);
|
||||
sendData = theUrlBody.getBytes();
|
||||
}
|
||||
if(callItems[i].getItem().contains("udp://")) {
|
||||
log.debug("executing HUE api request to UDP: " + callItems[i].getItem());
|
||||
DatagramSocket responseSocket = new DatagramSocket(Integer.parseInt(port));
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Integer.parseInt(port));
|
||||
responseSocket.send(sendPacket);
|
||||
responseSocket.close();
|
||||
}
|
||||
else if(callItems[i].getItem().contains("tcp://"))
|
||||
{
|
||||
log.debug("executing HUE api request to TCP: " + callItems[i].getItem());
|
||||
Socket dataSendSocket = new Socket(IPAddress, Integer.parseInt(port));
|
||||
DataOutputStream outToClient = new DataOutputStream(dataSendSocket.getOutputStream());
|
||||
outToClient.write(sendData);
|
||||
outToClient.flush();
|
||||
dataSendSocket.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());
|
||||
|
||||
@@ -21,11 +21,7 @@ public class HueUtil {
|
||||
|
||||
public static final String registerWithHue(HttpClient anHttpClient, String ipAddress, String aName, String theUser, HueErrorStringSet errorStringSet) {
|
||||
UserCreateRequest theLogin = new UserCreateRequest();
|
||||
theLogin.setDevicetype("HA Bridge");
|
||||
if(theUser == null)
|
||||
theLogin.setUsername("habridge");
|
||||
else
|
||||
theLogin.setUsername(theUser);
|
||||
theLogin.setDevicetype("HABridge#MyMachine");
|
||||
HttpPost postRequest = new HttpPost("http://" + ipAddress + HUE_REQUEST);
|
||||
ContentType parsedContentType = ContentType.parse("application/json");
|
||||
StringEntity requestBody = new StringEntity(new Gson().toJson(theLogin), parsedContentType);
|
||||
|
||||
Reference in New Issue
Block a user