mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Updated code for issues and included new pull requests from others.
This commit is contained in:
28
README.md
28
README.md
@@ -513,8 +513,8 @@ contentBodyOff | string | This is the content body that you would like to send w
|
|||||||
{
|
{
|
||||||
"name" : "bedroom light",
|
"name" : "bedroom light",
|
||||||
"deviceType" : "switch",
|
"deviceType" : "switch",
|
||||||
"onUrl" : [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=41","type":"veraDevice"}],
|
"onUrl" : "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=41\",\"type\":\"veraDevice\"}]",
|
||||||
"offUrl" : [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=41","type":"veraDevice"}]
|
"offUrl" : "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=41\",\"type\":\"veraDevice\"}]"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Dimming Control Example
|
#### Dimming Control Example
|
||||||
@@ -524,8 +524,8 @@ e.g.
|
|||||||
{
|
{
|
||||||
"name": "entry light",
|
"name": "entry light",
|
||||||
"deviceType": "switch",
|
"deviceType": "switch",
|
||||||
"offUrl": [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=31","type":"veraDevice"}],
|
"offUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=31\",\"type\":\"veraDevice\"}]",
|
||||||
"onUrl": [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=31&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.percent}","type":"veraDevice"}]
|
"onUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=31&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.percent}\",\"type\":\"veraDevice\"}]"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
See the echo's documentation for the dimming phrase.
|
See the echo's documentation for the dimming phrase.
|
||||||
@@ -537,8 +537,8 @@ e.g.
|
|||||||
{
|
{
|
||||||
"name": "Thermostat,
|
"name": "Thermostat,
|
||||||
"deviceType": "custom",
|
"deviceType": "custom",
|
||||||
"offUrl": [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=10","type":"veraDevice"}],
|
"offUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=10\",\"type\":\"veraDevice\"}]",
|
||||||
"onUrl": [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=10&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.math(X/4)}","type":"veraDevice"}]
|
"onUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=10&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.math(X/4)}\",\"type\":\"veraDevice\"}]"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
See the echo's documentation for the dimming phrase.
|
See the echo's documentation for the dimming phrase.
|
||||||
@@ -550,8 +550,8 @@ e.g:
|
|||||||
{
|
{
|
||||||
"name": "test device",
|
"name": "test device",
|
||||||
"deviceType": "custom",
|
"deviceType": "custom",
|
||||||
"offUrl": [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=31","httpVerb":"POST","contentType" : "application/json","httpBody" : "{\"fooBar\":\"baz_off\"}],
|
"offUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=31\",\"httpVerb\":\"POST\",\"contentType\" : \"application/json\",\"httpBody\" : \"{\"fooBar\":\"baz_off\"}]",
|
||||||
"onUrl": [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=31&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.percent}","type":"httpDevice","httpVerb":"POST","contentType" : "application/json","httpBody" : "{\"fooBar\":\"baz_on\"}]
|
"onUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=31&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.percent}\",\"type\":\"httpDevice\",\"httpVerb\":\"POST\",\"contentType\" : \"application/json\",\"httpBody\" : \"{\"fooBar\":\"baz_on\"}]"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Custom Usage URLs Example
|
#### Custom Usage URLs Example
|
||||||
@@ -560,8 +560,8 @@ Anything that takes an action as a result of an HTTP request will probably work
|
|||||||
{
|
{
|
||||||
"name": "night mode",
|
"name": "night mode",
|
||||||
"deviceType": ""custom",
|
"deviceType": ""custom",
|
||||||
"offUrl": [{"item":"http://192.168.1.201:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=1","type":"httpDevice"}],
|
"offUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=1\",\"type\":\"httpDevice\"}]",
|
||||||
"onUrl": [{"item":"http://192.168.1.201:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=3","type":"httpDevice"}]
|
"onUrl": "[{\"item\":\"http://192.168.1.201:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=3\",\"type\":\"httpDevice\"}]"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Here is a UDP example that can send binary data.
|
Here is a UDP example that can send binary data.
|
||||||
@@ -569,8 +569,8 @@ Here is a UDP example that can send binary data.
|
|||||||
{
|
{
|
||||||
"name": "UDPPacket",
|
"name": "UDPPacket",
|
||||||
"deviceType": "custom",
|
"deviceType": "custom",
|
||||||
"offUrl": [{"item":"udp://192.168.1.1:8899/0x460055","type":"udpDevice"}],
|
"offUrl": "[{\"item\":\"udp://192.168.1.1:8899/0x460055\",\"type\":\"udpDevice\"}]",
|
||||||
"onUrl": [{"item":"udp://192.168.1.1:8899/0x450055","type":"udpDevice"}]
|
"onUrl": "[{\"item\":\"udp://192.168.1.1:8899/0x450055\",\"type\":\"udpDevice\"}]"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Response
|
#### Response
|
||||||
@@ -629,8 +629,8 @@ contentBodyOff | string | This is the content body that you would like to send w
|
|||||||
"id" : "6789",
|
"id" : "6789",
|
||||||
"name" : "table light",
|
"name" : "table light",
|
||||||
"deviceType" : "switch",
|
"deviceType" : "switch",
|
||||||
"onUrl" : [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=41","type":"veraDevice"}],
|
"onUrl" : "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=41\",\"type\":\"veraDevice\"}]",
|
||||||
"offUrl" : [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=41","type":"veraDevice"}]
|
"offUrl" : "[{\"item\":\"http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=41\",\"type\":\"veraDevice\"}]"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Response
|
#### Response
|
||||||
|
|||||||
2
pom.xml
2
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>4.5.0</version>
|
<version>4.5.0a</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public class HueMulator {
|
|||||||
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
||||||
response.type("application/json");
|
response.type("application/json");
|
||||||
response.status(HttpStatus.SC_OK);
|
response.status(HttpStatus.SC_OK);
|
||||||
log.debug("put to groups API from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
log.debug("put action to groups API from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
||||||
return "[{\"error\":{\"address\": \"/groups/0/action/scene\", \"type\":7, \"description\": \"invalid value, dummy for parameter, scene\"}}]";
|
return "[{\"error\":{\"address\": \"/groups/0/action/scene\", \"type\":7, \"description\": \"invalid value, dummy for parameter, scene\"}}]";
|
||||||
});
|
});
|
||||||
// http://ip_address:port/api/{userId}/scenes returns json objects of
|
// http://ip_address:port/api/{userId}/scenes returns json objects of
|
||||||
|
|||||||
@@ -13,8 +13,15 @@ import com.bwssystems.HABridge.BridgeSettings;
|
|||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
|
import com.bwssystems.HABridge.api.NameValue;
|
||||||
|
import com.bwssystems.HABridge.api.hue.HueError;
|
||||||
|
import com.bwssystems.HABridge.api.hue.HueErrorResponse;
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
|
import com.bwssystems.HABridge.hue.DeviceDataDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
|
import com.bwssystems.HABridge.hue.TimeDecode;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class HalHome implements Home {
|
public class HalHome implements Home {
|
||||||
private static final Logger log = LoggerFactory.getLogger(HalHome.class);
|
private static final Logger log = LoggerFactory.getLogger(HalHome.class);
|
||||||
@@ -30,7 +37,7 @@ public class HalHome implements Home {
|
|||||||
public Object getItems(String type) {
|
public Object getItems(String type) {
|
||||||
if(!validHal)
|
if(!validHal)
|
||||||
return null;
|
return null;
|
||||||
log.debug("consolidating devices for hues");
|
log.debug("consolidating devices for HALs");
|
||||||
List<HalDevice> theResponse = null;
|
List<HalDevice> theResponse = null;
|
||||||
Iterator<String> keys = hals.keySet().iterator();
|
Iterator<String> keys = hals.keySet().iterator();
|
||||||
List<HalDevice> deviceList = new ArrayList<HalDevice>();
|
List<HalDevice> deviceList = new ArrayList<HalDevice>();
|
||||||
@@ -106,8 +113,41 @@ public class HalHome implements Home {
|
|||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
// Not a device handler
|
String responseString = null;
|
||||||
return null;
|
String theUrl = anItem.getItem().getAsString();
|
||||||
|
if(theUrl != null && !theUrl.isEmpty () && theUrl.contains("http://")) {
|
||||||
|
String intermediate = theUrl.substring(theUrl.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;
|
||||||
|
log.debug("executing HUE api request to Http "
|
||||||
|
+ (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": "
|
||||||
|
+ anItem.getItem().getAsString());
|
||||||
|
|
||||||
|
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(theUrl,
|
||||||
|
intensity, targetBri, targetBriInc, false);
|
||||||
|
anUrl = DeviceDataDecode.replaceDeviceData(anUrl, device);
|
||||||
|
anUrl = TimeDecode.replaceTimeValue(anUrl);
|
||||||
|
|
||||||
|
for (Map.Entry<String, HalInfo> entry : hals.entrySet())
|
||||||
|
{
|
||||||
|
if(entry.getValue().getHalAddress().getIp().equals(hostAddr)) {
|
||||||
|
if (entry.getValue().deviceCommand(anUrl) == null) {
|
||||||
|
log.warn("Error on calling hal to change device state: " + anUrl);
|
||||||
|
responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId,
|
||||||
|
"Error on calling url to change device state", "/lights/"
|
||||||
|
+ lightId + "state", null, null).getTheErrors(), HueError[].class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
|
import com.bwssystems.HABridge.api.hue.HueError;
|
||||||
|
import com.bwssystems.HABridge.api.hue.HueErrorResponse;
|
||||||
import com.bwssystems.HABridge.plugins.http.HTTPHandler;
|
import com.bwssystems.HABridge.plugins.http.HTTPHandler;
|
||||||
import com.bwssystems.HABridge.util.TextStringFormatter;
|
import com.bwssystems.HABridge.util.TextStringFormatter;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -177,6 +179,12 @@ public class HalInfo {
|
|||||||
return deviceList;
|
return deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String deviceCommand(String theUrl) {
|
||||||
|
String theData = null;
|
||||||
|
theData = httpClient.doHttpRequest(theUrl, null, null, null, null);
|
||||||
|
return theData;
|
||||||
|
}
|
||||||
|
|
||||||
public NamedIP getHalAddress() {
|
public NamedIP getHalAddress() {
|
||||||
return halAddress;
|
return halAddress;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1285,11 +1285,11 @@ app.controller ('SystemController', function ($scope, $location, bridgeService,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$scope.addHarmonytoSettings = function (newharmonyname, newharmonyip) {
|
$scope.addHarmonytoSettings = function (newharmonyname, newharmonyip, newharmonywebhook) {
|
||||||
if($scope.bridge.settings.harmonyaddress === undefined || $scope.bridge.settings.harmonyaddress === null) {
|
if($scope.bridge.settings.harmonyaddress === undefined || $scope.bridge.settings.harmonyaddress === null) {
|
||||||
$scope.bridge.settings.harmonyaddress = { devices: [] };
|
$scope.bridge.settings.harmonyaddress = { devices: [] };
|
||||||
}
|
}
|
||||||
var newharmony = {name: newharmonyname, ip: newharmonyip }
|
var newharmony = {name: newharmonyname, ip: newharmonyip, webhook: newharmonywebhook}
|
||||||
$scope.bridge.settings.harmonyaddress.devices.push(newharmony);
|
$scope.bridge.settings.harmonyaddress.devices.push(newharmony);
|
||||||
$scope.newharmonyname = null;
|
$scope.newharmonyname = null;
|
||||||
$scope.newharmonyip = null;
|
$scope.newharmonyip = null;
|
||||||
|
|||||||
@@ -147,7 +147,7 @@
|
|||||||
<td>{{harmony.ip}}</td>
|
<td>{{harmony.ip}}</td>
|
||||||
<td>{{harmony.webhook}}</td>
|
<td>{{harmony.webhook}}</td>
|
||||||
<td><button class="btn btn-danger" type="submit"
|
<td><button class="btn btn-danger" type="submit"
|
||||||
ng-click="removeHarmonytoSettings(harmony.name, harmony.ip, harmony.webhook)">Del</button></td>
|
ng-click="removeHarmonytoSettings(harmony.name, harmony.ip)">Del</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><input id="bridge-settings-next-harmony-name"
|
<td><input id="bridge-settings-next-harmony-name"
|
||||||
|
|||||||
Reference in New Issue
Block a user