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 | |
|---|---|---|---|
|
|
aebde7ee48 | ||
|
|
c8fb93eeb6 | ||
|
|
1602ed004a | ||
|
|
7514e36edb | ||
|
|
2789d8c180 | ||
|
|
af1777aeb3 | ||
|
|
fc2d587e1a |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,3 +10,5 @@ data
|
||||
.idea
|
||||
/target/
|
||||
/.settings/
|
||||
/start.bat
|
||||
/.classpath
|
||||
|
||||
23
.project
Normal file
23
.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ha-bridge</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
17
README.md
17
README.md
@@ -1,5 +1,5 @@
|
||||
# ha-bridge
|
||||
Emulates philips hue api to other home automation gateways. The Amazon echo now supports wemo and philips hue.
|
||||
Emulates Philips Hue api to other home automation gateways such as an Amazon Echo. The Bridge has helpers to build devices for the gateway for the Vera, Vera Lite or Vera Edge. Alternatively the Bridge supports custom calls as well. The Bridge handles basic commands such as "On", "Off" and "brightness" commands of the hue protocol.
|
||||
## Build
|
||||
To customize and build it yourself, build a new jar with maven:
|
||||
```
|
||||
@@ -44,8 +44,8 @@ POST http://host:8080/api/devices
|
||||
"offUrl" : "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"
|
||||
}
|
||||
```
|
||||
## Dimming
|
||||
Dimming is also supported by using the expessions ${intensity.percent} or ${intensity.byte} for 0-100 and 0-255 respectively.
|
||||
## Dimming and value passing control
|
||||
Dimming is also supported by using the expressions ${intensity.percent} for 0-100 or ${intensity.byte} for 0-255 or $intensity{match(<your expression using "X" as the value to operate on>)} i.e. "$intensity.math(X/4)}".
|
||||
e.g.
|
||||
```
|
||||
{
|
||||
@@ -61,9 +61,10 @@ See the echo's documentation for the dimming phrase.
|
||||
added optional fields
|
||||
* contentType (currently un-validated)
|
||||
* httpVerb (POST/PUT/GET only supported)
|
||||
* contentBody your post/put body here
|
||||
* contentBody your post/put body for onUrl here
|
||||
* contentBodyOff your post/put body for offUrl here
|
||||
|
||||
This will allow control of any other application that may need more then GET.
|
||||
This will allow control of any other application that may need more then GET. You can also use the dimming and value control commands within the URLs as well.
|
||||
e.g:
|
||||
```
|
||||
{
|
||||
@@ -73,10 +74,12 @@ e.g:
|
||||
"onUrl": "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}",
|
||||
"contentType" : "application/json",
|
||||
"httpVerb":"POST",
|
||||
"contentBody" : "{\"fooBar\":\"baz\"}"
|
||||
"contentBody" : "{\"fooBar\":\"baz_on\"}"
|
||||
"contentBodyOff" : "{\"fooBar\":\"baz_off\"}"
|
||||
}
|
||||
```
|
||||
Anything that takes an action as a result of an HTTP request will probably work - like putting Vera in and out of night mode:
|
||||
## Custom Usage URLs
|
||||
Anything that takes an action as a result of an HTTP request will probably work and you can also use the dimming and value control commands within the URLs as well - like putting Vera in and out of night mode:
|
||||
```
|
||||
{
|
||||
"name": "night mode",
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>0.4.4</version>
|
||||
<version>0.4.8</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -70,8 +70,10 @@ public class HABridge {
|
||||
theResources = new DeviceResource(bridgeSettings);
|
||||
// setup the class to handle the hue emulator rest api
|
||||
theHueMulator = new HueMulator(theResources.getDeviceRepository());
|
||||
theHueMulator.setupServer();
|
||||
// setup the class to handle the upnp response rest api
|
||||
theSettingResponder = new UpnpSettingsResource(bridgeSettings);
|
||||
theSettingResponder.setupServer();
|
||||
// wait for the sparkjava initialization of the rest api classes to be complete
|
||||
awaitInitialization();
|
||||
|
||||
|
||||
@@ -75,17 +75,20 @@ public class DeviceResponse {
|
||||
}
|
||||
|
||||
public Map<String, String> getPointsymbol() {
|
||||
Map<String, String> dummyValue = new HashMap<>();
|
||||
dummyValue.put("1", "none");
|
||||
dummyValue.put("2", "none");
|
||||
dummyValue.put("3", "none");
|
||||
dummyValue.put("4", "none");
|
||||
dummyValue.put("5", "none");
|
||||
dummyValue.put("6", "none");
|
||||
dummyValue.put("7", "none");
|
||||
dummyValue.put("8", "none");
|
||||
if(pointsymbol == null)
|
||||
{
|
||||
pointsymbol = new HashMap<>();
|
||||
pointsymbol.put("1", "none");
|
||||
pointsymbol.put("2", "none");
|
||||
pointsymbol.put("3", "none");
|
||||
pointsymbol.put("4", "none");
|
||||
pointsymbol.put("5", "none");
|
||||
pointsymbol.put("6", "none");
|
||||
pointsymbol.put("7", "none");
|
||||
pointsymbol.put("8", "none");
|
||||
}
|
||||
|
||||
return dummyValue;
|
||||
return pointsymbol;
|
||||
}
|
||||
|
||||
public void setPointsymbol(Map<String, String> pointsymbol) {
|
||||
|
||||
@@ -11,6 +11,7 @@ public class DeviceDescriptor{
|
||||
private String httpVerb;
|
||||
private String contentType;
|
||||
private String contentBody;
|
||||
private String contentBodyOff;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -75,6 +76,14 @@ public class DeviceDescriptor{
|
||||
public void setContentBody(String contentBody) {
|
||||
this.contentBody = contentBody;
|
||||
}
|
||||
|
||||
public String getContentBodyOff() {
|
||||
return contentBodyOff;
|
||||
}
|
||||
|
||||
public void setContentBodyOff(String contentBodyOff) {
|
||||
this.contentBodyOff = contentBodyOff;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.bwssystems.HABridge.dao;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@@ -106,7 +108,10 @@ public class DeviceRepository {
|
||||
}
|
||||
|
||||
try {
|
||||
Path target = FileSystems.getDefault().getPath("data", "device.db.old");
|
||||
Files.move(filePath, target);
|
||||
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
|
||||
Files.delete(target);
|
||||
} catch (IOException e) {
|
||||
log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e);
|
||||
}
|
||||
@@ -188,6 +193,9 @@ public class DeviceRepository {
|
||||
} else if (name.equals("contentBody")) {
|
||||
deviceEntry.setContentBody(reader.nextString());
|
||||
log.debug("Read a Device - device json contentBody:" + deviceEntry.getContentBody());
|
||||
} else if (name.equals("contentBodyOff")) {
|
||||
deviceEntry.setContentBodyOff(reader.nextString());
|
||||
log.debug("Read a Device - device json contentBodyOff:" + deviceEntry.getContentBodyOff());
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ public class DeviceResource {
|
||||
deviceEntry.setHttpVerb(device.getHttpVerb());
|
||||
deviceEntry.setContentType(device.getContentType());
|
||||
deviceEntry.setContentBody(device.getContentBody());
|
||||
deviceEntry.setContentBodyOff(device.getContentBodyOff());
|
||||
|
||||
deviceRepository.save(deviceEntry);
|
||||
response.status(HttpStatus.SC_OK);
|
||||
|
||||
@@ -9,7 +9,9 @@ import com.bwssystems.HABridge.dao.*;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import javax.script.ScriptEngine;
|
||||
import static spark.Spark.get;
|
||||
import static spark.Spark.post;
|
||||
import static spark.Spark.put;
|
||||
@@ -42,6 +44,10 @@ public class HueMulator {
|
||||
private static final Logger log = LoggerFactory.getLogger(HueMulator.class);
|
||||
private static final String INTENSITY_PERCENT = "${intensity.percent}";
|
||||
private static final String INTENSITY_BYTE = "${intensity.byte}";
|
||||
private static final String INTENSITY_MATH = "${intensity.math(";
|
||||
private static final String INTENSITY_MATH_VALUE = "X";
|
||||
private static final String INTENSITY_MATH_CLOSE = ")}";
|
||||
private static final String ENGINE_JAVASCRIPT = "JavaScript";
|
||||
private static final String HUE_CONTEXT = "/api";
|
||||
|
||||
private DeviceRepository repository;
|
||||
@@ -54,11 +60,10 @@ public class HueMulator {
|
||||
mapper = new ObjectMapper(); //armzilla: work around Echo incorrect content type and breaking mapping. Map manually
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
repository = aDeviceRepository;
|
||||
setupEndpoints();
|
||||
}
|
||||
|
||||
// This function sets up the sparkjava rest calls for the hue api
|
||||
private void setupEndpoints() {
|
||||
public void setupServer() {
|
||||
log.info("Hue emulator service started....");
|
||||
// http://ip_address:port/api/{userId}/lights returns json objects of all lights configured
|
||||
get(HUE_CONTEXT + "/:userid/lights", "application/json", (request, response) -> {
|
||||
@@ -205,8 +210,12 @@ public class HueMulator {
|
||||
}
|
||||
|
||||
//quick template
|
||||
String body;
|
||||
url = replaceIntensityValue(url, state.getBri());
|
||||
String body = replaceIntensityValue(device.getContentBody(), state.getBri());
|
||||
if (state.isOn())
|
||||
body = replaceIntensityValue(device.getContentBody(), state.getBri());
|
||||
else
|
||||
body = replaceIntensityValue(device.getContentBodyOff(), state.getBri());
|
||||
//make call
|
||||
if(!doHttpRequest(url, device.getHttpVerb(), device.getContentType(), body)){
|
||||
response.status(HttpStatus.SC_SERVICE_UNAVAILABLE);
|
||||
@@ -238,7 +247,18 @@ public class HueMulator {
|
||||
int percentBrightness = (int) Math.round(intensity/255.0*100);
|
||||
String intensityPercent = String.valueOf(percentBrightness);
|
||||
request = request.replace(INTENSITY_PERCENT, intensityPercent);
|
||||
}
|
||||
} else if(request.contains(INTENSITY_MATH)){
|
||||
String mathDescriptor = request.substring(request.indexOf(INTENSITY_MATH) + INTENSITY_MATH.length(),request.indexOf(INTENSITY_MATH_CLOSE));
|
||||
String updatedMath = mathDescriptor.replace(INTENSITY_MATH_VALUE, String.valueOf(intensity));
|
||||
ScriptEngineManager mgr = new ScriptEngineManager();
|
||||
ScriptEngine engine = mgr.getEngineByName(ENGINE_JAVASCRIPT);
|
||||
try {
|
||||
log.debug("Math eval is: " + updatedMath);
|
||||
Integer endResult = (Integer) engine.eval(updatedMath);
|
||||
request = request.replace(INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE, endResult.toString());
|
||||
} catch (ScriptException e) {
|
||||
log.error("Could not execute Math: " + updatedMath, e);
|
||||
} }
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,10 +90,9 @@ public class UpnpSettingsResource {
|
||||
public UpnpSettingsResource(BridgeSettings theSettings) {
|
||||
super();
|
||||
this.theSettings = theSettings;
|
||||
setupListener(this.theSettings);
|
||||
}
|
||||
|
||||
private void setupListener (BridgeSettings theSettings) {
|
||||
public void setupServer() {
|
||||
log.info("Hue description service started....");
|
||||
// http://ip_adress:port/description.xml which returns the xml configuration for the hue emulator
|
||||
get("/description.xml", "application/xml; charset=utf-8", (request, response) -> {
|
||||
|
||||
@@ -30,13 +30,13 @@
|
||||
<li class="active"><a href="#">Home</a></li>
|
||||
<li><a href="http://echo.amazon.com/#cards" target="_blank">My Echo</a></li>
|
||||
<li class="dropdown">
|
||||
<a id="dropdownMenu1" href="#" class="dropdown-toggle"
|
||||
<a id="dropdownMenu1" href="" class="dropdown-toggle"
|
||||
data-toggle="dropdown" role="button" aria-haspopup="true"
|
||||
aria-expanded="false">About <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||
<li><a href="http://www.bwssystems.com" target="_blank">Developed by BWS Systems</a></li>
|
||||
<li><a href="http://www.amazon.com/echo" target="_blank">Amazon Echo</a></li>
|
||||
<li><a href="#">HA Bridge Version 0.4.4</a></li>
|
||||
<li><a href="">HA Bridge Version 0.4.8</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -72,7 +72,7 @@ app.factory('BridgeSettings', function() {
|
||||
return BridgeSettings;
|
||||
});
|
||||
|
||||
app.service('bridgeService', function ($http, BridgeSettings) {
|
||||
app.service('bridgeService', function ($http, $window, BridgeSettings) {
|
||||
var self = this;
|
||||
self.BridgeSettings = BridgeSettings;
|
||||
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], device: [], error: ""};
|
||||
@@ -110,10 +110,9 @@ app.service('bridgeService', function ($http, BridgeSettings) {
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
$window.alert("Load Bridge Settings Error: " + error.data.message);
|
||||
} else {
|
||||
self.state.error = "If you're not seeing any settings, you may be running into problems with CORS. " +
|
||||
"You can work around this by running a fresh launch of Chrome with the --disable-web-security flag.";
|
||||
$window.alert("Load Bridge Settings Error: unknown");
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
@@ -128,12 +127,10 @@ app.service('bridgeService', function ($http, BridgeSettings) {
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
$window.alert("Get Vera Devices Error: " + error.data.message);
|
||||
} else {
|
||||
self.state.error = "If you're not seeing any address, you may be running into problems with CORS. " +
|
||||
"You can work around this by running a fresh launch of Chrome with the --disable-web-security flag.";
|
||||
$window.alert("Get Vera Devices Error: unknown");
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -146,17 +143,15 @@ app.service('bridgeService', function ($http, BridgeSettings) {
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
$window.alert("Get Vera Scenes Error: " + error.data.message);
|
||||
} else {
|
||||
self.state.error = "If you're not seeing any address, you may be running into problems with CORS. " +
|
||||
"You can work around this by running a fresh launch of Chrome with the --disable-web-security flag.";
|
||||
$window.alert("Get Vera Scenes Error: unknown");
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.addDevice = function (id, name, type, onUrl, offUrl, httpVerb, contentType, contentBody) {
|
||||
this.addDevice = function (id, name, type, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) {
|
||||
this.state.error = "";
|
||||
if (id) {
|
||||
var putUrl = this.state.base + "/" + id;
|
||||
@@ -168,19 +163,22 @@ app.service('bridgeService', function ($http, BridgeSettings) {
|
||||
offUrl: offUrl,
|
||||
httpVerb: httpVerb,
|
||||
contentType: contentType,
|
||||
contentBody: contentBody
|
||||
contentBody: contentBody,
|
||||
contentBodyOff: contentBodyOff
|
||||
}).then(
|
||||
function (response) {
|
||||
self.viewDevices();
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
$window.alert("Edit Device Error: " + error.data.message);
|
||||
}
|
||||
console.log(error);
|
||||
$window.alert("Edit Device Error: unknown");
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if(type == null || type == "")
|
||||
type = "switch";
|
||||
return $http.post(this.state.base, {
|
||||
name: name,
|
||||
deviceType: type,
|
||||
@@ -188,16 +186,17 @@ app.service('bridgeService', function ($http, BridgeSettings) {
|
||||
offUrl: offUrl,
|
||||
httpVerb: httpVerb,
|
||||
contentType: contentType,
|
||||
contentBody: contentBody
|
||||
contentBody: contentBody,
|
||||
contentBodyOff: contentBodyOff
|
||||
}).then(
|
||||
function (response) {
|
||||
self.viewDevices();
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
$window.alert("Add new Device Error: " + error.data.message);
|
||||
}
|
||||
console.log(error);
|
||||
$window.alert("Add new Device Error: unknown");
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -213,17 +212,17 @@ app.service('bridgeService', function ($http, BridgeSettings) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
}
|
||||
console.log(error);
|
||||
$window.alert("Delete Device Error: unknown");
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.editDevice = function (id, name, onUrl, offUrl, httpVerb, contentType, contentBody) {
|
||||
self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl, httpVerb: httpVerb, contentType: contentType, contentBody: contentBody};
|
||||
this.editDevice = function (id, name, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) {
|
||||
self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl, httpVerb: httpVerb, contentType: contentType, contentBody: contentBody, contentBodyOff: contentBodyOff};
|
||||
};
|
||||
});
|
||||
|
||||
app.controller('ViewingController', function ($scope, $location, bridgeService, BridgeSettings) {
|
||||
app.controller('ViewingController', function ($scope, $location, $http, $window, bridgeService, BridgeSettings) {
|
||||
|
||||
$scope.BridgeSettings = bridgeService.BridgeSettings;
|
||||
bridgeService.viewDevices();
|
||||
@@ -237,20 +236,63 @@ app.controller('ViewingController', function ($scope, $location, bridgeService,
|
||||
$scope.deleteDevice = function (device) {
|
||||
bridgeService.deleteDevice(device.id);
|
||||
};
|
||||
$scope.testUrl = function (url) {
|
||||
window.open(url, "_blank");
|
||||
$scope.testUrl = function (device, type) {
|
||||
if(type == "on") {
|
||||
if(device.httpVerb == "PUT")
|
||||
$http.put(device.onUrl, device.contentBody).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else if(device.httpVerb == "POST")
|
||||
$http.post(device.onUrl, device.contentBody).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else
|
||||
window.open(device.onUrl, "_blank");
|
||||
}
|
||||
else {
|
||||
if(device.httpVerb == "PUT")
|
||||
$http.put(device.offUrl, device.contentBodyOff).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else if(device.httpVerb == "POST")
|
||||
$http.post(device.offUrl, device.contentBody).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else
|
||||
window.open(device.offUrl, "_blank");
|
||||
}
|
||||
};
|
||||
$scope.setBridgeUrl = function (url) {
|
||||
bridgeService.state.base = url;
|
||||
bridgeService.viewDevices();
|
||||
};
|
||||
$scope.editDevice = function (device) {
|
||||
bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl, device.httpVerb, device.contentType, device.contentBody);
|
||||
bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl, device.httpVerb, device.contentType, device.contentBody, device.contentBodyOff);
|
||||
$location.path('/editdevice');
|
||||
};
|
||||
});
|
||||
|
||||
app.controller('AddingController', function ($scope, $location, bridgeService, BridgeSettings) {
|
||||
app.controller('AddingController', function ($scope, $location, $http, bridgeService, BridgeSettings) {
|
||||
|
||||
$scope.device = {id: "", name: "", deviceType: "switch", onUrl: "", offUrl: ""};
|
||||
$scope.vera = {base: "", port: "3480", id: ""};
|
||||
@@ -262,18 +304,26 @@ app.controller('AddingController', function ($scope, $location, bridgeService, B
|
||||
$scope.device = bridgeService.state.device;
|
||||
$scope.predicate = '';
|
||||
$scope.reverse = true;
|
||||
$scope.device_dim_control = "";
|
||||
$scope.order = function(predicate) {
|
||||
$scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
|
||||
$scope.predicate = predicate;
|
||||
};
|
||||
|
||||
$scope.buildUrlsUsingDevice = function () {
|
||||
$scope.buildUrlsUsingDevice = function (dim_control) {
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + $scope.vera.base;
|
||||
}
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ $scope.vera.id;
|
||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&DeviceNum="
|
||||
+ $scope.vera.id
|
||||
+ "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget="
|
||||
+ dim_control;
|
||||
else
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ $scope.vera.id;
|
||||
$scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum="
|
||||
+ $scope.vera.id;
|
||||
@@ -292,15 +342,22 @@ app.controller('AddingController', function ($scope, $location, bridgeService, B
|
||||
+ $scope.vera.id;
|
||||
};
|
||||
|
||||
$scope.buildDeviceUrls = function (veradevice) {
|
||||
$scope.buildDeviceUrls = function (veradevice, dim_control) {
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + $scope.vera.base;
|
||||
}
|
||||
$scope.device.deviceType = "switch";
|
||||
$scope.device.name = veradevice.name;
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ veradevice.id;
|
||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&DeviceNum="
|
||||
+ veradevice.id
|
||||
+ "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget="
|
||||
+ dim_control;
|
||||
else
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ veradevice.id;
|
||||
$scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum="
|
||||
+ veradevice.id;
|
||||
@@ -321,11 +378,54 @@ app.controller('AddingController', function ($scope, $location, bridgeService, B
|
||||
};
|
||||
|
||||
$scope.testUrl = function (url) {
|
||||
window.open(url, "_blank");
|
||||
if(type == "on") {
|
||||
if(device.httpVerb == "PUT")
|
||||
$http.put(device.onUrl, device.contentBody).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else if(device.httpVerb == "POST")
|
||||
$http.post(device.onUrl, device.contentBody).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else
|
||||
window.open(device.onUrl, "_blank");
|
||||
}
|
||||
else {
|
||||
if(device.httpVerb == "PUT")
|
||||
$http.put(device.offUrl, device.contentBodyOff).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else if(device.httpVerb == "POST")
|
||||
$http.post(device.offUrl, device.contentBody).then(
|
||||
function (response) {
|
||||
$window.alert("Request Exceuted: " + response.statusText);
|
||||
},
|
||||
function (error) {
|
||||
$window.alert("Request Error: " + error.data.message);
|
||||
}
|
||||
);
|
||||
else
|
||||
window.open(device.offUrl, "_blank");
|
||||
}
|
||||
};
|
||||
|
||||
$scope.addDevice = function () {
|
||||
bridgeService.addDevice($scope.device.id, $scope.device.name, $scope.device.deviceType, $scope.device.onUrl, $scope.device.offUrl, $scope.device.httpVerb, $scope.device.contentType, $scope.device.contentBody).then(
|
||||
bridgeService.addDevice($scope.device.id, $scope.device.name, $scope.device.deviceType, $scope.device.onUrl, $scope.device.offUrl, $scope.device.httpVerb, $scope.device.contentType, $scope.device.contentBody, $scope.device.contentBodyOff).then(
|
||||
function () {
|
||||
$scope.device.id = "";
|
||||
$scope.device.name = "";
|
||||
@@ -335,6 +435,7 @@ app.controller('AddingController', function ($scope, $location, bridgeService, B
|
||||
$scope.device.httpVerb = null;
|
||||
$scope.device.contentType = null;
|
||||
$scope.device.contentBody = null;
|
||||
$scope.device.contentBodyOff = null;
|
||||
$location.path('/#');
|
||||
},
|
||||
function (error) {
|
||||
|
||||
@@ -107,9 +107,9 @@
|
||||
<td>{{device.deviceType}}</td>
|
||||
<td>
|
||||
<button class="btn btn-info" type="submit"
|
||||
ng-click="testUrl(device.onUrl)">Test ON</button>
|
||||
ng-click="testUrl(device, 'on')">Test ON</button>
|
||||
<button class="btn btn-info" type="submit"
|
||||
ng-click="testUrl(device.offUrl)">Test OFF</button>
|
||||
ng-click="testUrl(device, 'off')">Test OFF</button>
|
||||
<button class="btn btn-warning" type="submit"
|
||||
ng-click="editDevice(device)">Edit</button>
|
||||
<button class="btn btn-danger" type="submit"
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.onUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'on')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -49,7 +49,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.offUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'off')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -58,30 +58,60 @@
|
||||
</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input type="text" class="form-control" id="device-http-verb"
|
||||
ng-model="device.httpVerb" placeholder="Http Verb, i.e. GET/PUT/POST">
|
||||
<select name="device-http-verb" id="device-http-verb" ng-model="device.httpVerb">
|
||||
<option value="">---Please select---</option> <!-- not selected / blank option -->
|
||||
<option value="GET">GET</option>
|
||||
<option value="PUT">PUT</option>
|
||||
<option value="POST">POST</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-content-type">Name
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-content-type">Content Type
|
||||
</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input type="text" class="form-control" id="device-content-type"
|
||||
ng-model="device.contentType" placeholder="Content type, i.e. application/json">
|
||||
<select name="device-content-type" id="device-content-type" ng-model="device.contentType">
|
||||
<option value="">---Please select---</option> <!-- not selected / blank option -->
|
||||
<option value="application/atom+xml">application/atom+xml</option>
|
||||
<option value="application/x-www-form-urlencoded">application/x-www-form-urlencoded</option>
|
||||
<option value="application/json">application/json</option>
|
||||
<option value="application/octet-stream">application/octet-stream</option>
|
||||
<option value="application/svg+xml">application/svg+xml</option>
|
||||
<option value="application/xhtml+xml">application/xhtml+xml</option>
|
||||
<option value="application/xml">application/xml</option>
|
||||
<option value="*">*</option>
|
||||
<option value="multipart/form-data">multipart/form-data</option>
|
||||
<option value="text/html">text/html</option>
|
||||
<option value="text/plain">text/plain</option>
|
||||
<option value="text/xml">text/xml</option>
|
||||
<option value="*/*">*/*</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body">Content Body </label>
|
||||
for="device-content-body">Content Body On</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<textarea rows="3" class="form-control" id="device-content-body"
|
||||
ng-model="device.contentBody" placeholder="Content Body for specific GET/PUT/POST type"></textarea>
|
||||
ng-model="device.contentBody" placeholder="Content Body On for specific GET/PUT/POST type"></textarea>
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body-off">Content Body Off</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<textarea rows="3" class="form-control" id="device-content-body-off"
|
||||
ng-model="device.contentBodyOff" placeholder="Content Body Off for specific GET/PUT/POST type"></textarea>
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
</div>
|
||||
|
||||
@@ -44,7 +44,19 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" ng-click="buildUrlsUsingDevice()"
|
||||
<label class="col-xs-2 col-sm-2 control-label" for="device-dim-control">Device Dim Control</label>
|
||||
|
||||
<div class="col-xs-10 col-sm-2">
|
||||
<select name="device-dim-control" id="device-dim-control" ng-model="device_dim_control">
|
||||
<option value="">none</option>
|
||||
<option value="${intensity..byte}">Pass-thru Value</option>
|
||||
<option value="${intensity.percent}">Percentage</option>
|
||||
<option value="${intensity.math(X*1)}">Custom Math</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" ng-click="buildUrlsUsingDevice(device_dim_control)"
|
||||
class="col-xs-2 col-sm-2 col-xs-offset-2 col-sm-offset-2 btn btn-success">Generate Device
|
||||
URLs</button>
|
||||
<button type="submit" ng-click="buildUrlsUsingScene()"
|
||||
@@ -86,7 +98,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.onUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'on')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -100,7 +112,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.offUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'off')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -109,30 +121,60 @@
|
||||
</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input type="text" class="form-control" id="device-http-verb"
|
||||
ng-model="device.httpVerb" placeholder="Http Verb, i.e. GET/PUT/POST">
|
||||
</div>
|
||||
<select name="device-http-verb" id="device-http-verb" ng-model="device.httpVerb">
|
||||
<option value="">---Please select---</option> <!-- not selected / blank option -->
|
||||
<option value="GET">GET</option>
|
||||
<option value="PUT">PUT</option>
|
||||
<option value="POST">POST</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-content-type">Name
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-content-type">Content Type
|
||||
</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input type="text" class="form-control" id="device-content-type"
|
||||
ng-model="device.contentType" placeholder="Content type, i.e. application/json">
|
||||
<select name="device-content-type" id="device-content-type" ng-model="device.contentType">
|
||||
<option value="">---Please select---</option> <!-- not selected / blank option -->
|
||||
<option value="application/atom+xml">application/atom+xml</option>
|
||||
<option value="application/x-www-form-urlencoded">application/x-www-form-urlencoded</option>
|
||||
<option value="application/json">application/json</option>
|
||||
<option value="application/octet-stream">application/octet-stream</option>
|
||||
<option value="application/svg+xml">application/svg+xml</option>
|
||||
<option value="application/xhtml+xml">application/xhtml+xml</option>
|
||||
<option value="application/xml">application/xml</option>
|
||||
<option value="*">*</option>
|
||||
<option value="multipart/form-data">multipart/form-data</option>
|
||||
<option value="text/html">text/html</option>
|
||||
<option value="text/plain">text/plain</option>
|
||||
<option value="text/xml">text/xml</option>
|
||||
<option value="*/*">*/*</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body">Content Body </label>
|
||||
for="device-content-body">Content Body On</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<textarea rows="3" class="form-control" id="device-content-body"
|
||||
ng-model="device.contentBody" placeholder="Content Body for specific GET/PUT/POST type"></textarea>
|
||||
ng-model="device.contentBody" placeholder="Content Body On for specific GET/PUT/POST type"></textarea>
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body-off">Content Body Off</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<textarea rows="3" class="form-control" id="device-content-body-off"
|
||||
ng-model="device.contentBodyOff" placeholder="Content Body Off for specific GET/PUT/POST type"></textarea>
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
</div>
|
||||
|
||||
@@ -12,8 +12,15 @@
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<p class="text-muted">You can select a Vera device and generate
|
||||
the add device box selections automatically.</p>
|
||||
|
||||
the add device box selections automatically.</p><p>Also, use this select menu for which type of dim
|
||||
control you would like to be generated:
|
||||
<select name="device-dim-control" id="device-dim-control" ng-model="device_dim_control">
|
||||
<option value="">none</option>
|
||||
<option value="${intensity..byte}">Pass-thru Value</option>
|
||||
<option value="${intensity.percent}">Percentage</option>
|
||||
<option value="${intensity.math(X*1)}">Custom Math</option>
|
||||
</select>
|
||||
</p>
|
||||
<table class="table table-bordered table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -43,7 +50,7 @@
|
||||
<td>{{veradevice.room}}</td>
|
||||
<td>
|
||||
<button class="btn btn-success" type="submit"
|
||||
ng-click="buildDeviceUrls(veradevice)">Generate
|
||||
ng-click="buildDeviceUrls(veradevice, device_dim_control)">Generate
|
||||
Device URLs</button>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -80,7 +87,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.onUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'on')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -94,7 +101,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.offUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'off')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.onUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'on')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -89,7 +89,7 @@
|
||||
</div>
|
||||
<div class="clearfix visible-xs"></div>
|
||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
||||
ng-click="testUrl(device.offUrl)">Test</button>
|
||||
ng-click="testUrl(device, 'off')">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TestBean {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
InetAddress address = InetAddress.getLocalHost();
|
||||
System.out.println("Using InetAddress");
|
||||
System.out.println("Host Address: "+ address.getHostAddress());
|
||||
System.out.println("Host Name: "+ address.getHostName());
|
||||
System.out.println("Address List: "+ Arrays.toString(InetAddress.getAllByName(address.getHostName())));
|
||||
System.out.println("CanonicalHostName: "+ address.getCanonicalHostName());
|
||||
System.out.println("Address: "+ address.getAddress());
|
||||
System.out.println("LocalHost: "+ address.getLocalHost());
|
||||
System.out.println("LoopbackAddress: "+ address.getLoopbackAddress());
|
||||
|
||||
String os = "os.name";
|
||||
String version = "os.version";
|
||||
String arch = "os.arch";
|
||||
System.out.println("Name of the OS: "+ System.getProperty(os));
|
||||
System.out.println("Version of the OS: "+ System.getProperty(version));
|
||||
System.out.println("Architecture of the OS: "+ System.getProperty(arch));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package demo;
|
||||
|
||||
import com.bwssystems.HABridge.HABridge;
|
||||
|
||||
/*
|
||||
* Dummy test holder
|
||||
*/
|
||||
|
||||
public class DemoApplicationTests {
|
||||
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user