Compare commits

...

6 Commits

Author SHA1 Message Date
Admin
7746938c62 Updated upnp discovery logic to only respond to the echo request for a
upnp device and updated hue response when getting lights to be more
accurate with the hue.
2015-08-21 16:06:06 -05:00
Admin
96074628fb Merge remote-tracking branch 'origin/master' 2015-08-21 08:56:05 -05:00
Admin
9dc8d8f8bc Updated call for hue user create/addition call. Updated upnp response
variables.
2015-08-20 16:49:12 -05:00
Admin
8de39a8bee Work on naming scenes 2015-08-19 16:43:46 -05:00
Admin
626f0641cc Changed navigation to use nav tab pills look. 2015-08-19 15:17:24 -05:00
Admin
020da99e1c Update .gitignore attributes for eclipse 2015-08-18 14:18:24 -05:00
12 changed files with 95 additions and 50 deletions

1
.gitignore vendored
View File

@@ -9,3 +9,4 @@ buildNumber.properties
data
.idea
/target/
/.settings/

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>0.3.0</version>
<version>0.3.1</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

View File

@@ -0,0 +1,19 @@
package com.bwssystems.HABridge.api;
public class UserCreateRequest {
private String devicetype;
private String username;
public String getDevicetype() {
return devicetype;
}
public void setDevicetype(String devicetype) {
this.devicetype = devicetype;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

View File

@@ -1,12 +1,14 @@
package com.bwssystems.HABridge.hue;
import com.bwssystems.HABridge.JsonTransformer;
import com.bwssystems.HABridge.api.UserCreateRequest;
import com.bwssystems.HABridge.api.hue.DeviceResponse;
import com.bwssystems.HABridge.api.hue.DeviceState;
import com.bwssystems.HABridge.api.hue.HueApiResponse;
import com.bwssystems.HABridge.dao.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import static spark.Spark.get;
import static spark.Spark.post;
@@ -55,29 +57,34 @@ public class HueMulator {
get(HUE_CONTEXT + "/:userid/lights", "application/json", (request, response) -> {
String userId = request.params(":userid");
log.info("hue lights list requested: " + userId + " from " + request.ip());
List<DeviceDescriptor> deviceList = repository.findByDeviceType("switch");
JsonTransformer aRenderer = new JsonTransformer();
String theStream = aRenderer.render(deviceList);
log.debug("The Device List: " + theStream);
Map<String, String> deviceResponseMap = new HashMap<>();
List<DeviceDescriptor> deviceList = repository.findAll();
Map<String, DeviceResponse> deviceResponseMap = new HashMap<>();
for (DeviceDescriptor device : deviceList) {
deviceResponseMap.put(device.getId(), device.getName());
DeviceResponse deviceResponse = DeviceResponse.createResponse(device.getName(), device.getId());
deviceResponseMap.put(device.getId(), deviceResponse);
}
response.status(200);
return deviceResponseMap;
} , new JsonTransformer());
// http://ip_address:port/api/* returns json object for a test call
post(HUE_CONTEXT + "/*", "application/json", (request, response) -> {
response.status(200);
return "[{\"success\":{\"username\":\"lights\"}}]";
// http://ip_address:port/api with body of user request returns json object for a success of user add
post(HUE_CONTEXT, "application/json", (request, response) -> {
log.debug("hue api user create requested: " + request.body() + " from " + request.ip());
UserCreateRequest aNewUser = new Gson().fromJson(request.body(), UserCreateRequest.class);
String newUser = aNewUser.getUsername();
if(newUser == null)
newUser = "lightssystem";
log.debug("hue api user create requested for device type: " + aNewUser.getDevicetype() + " and username: " + newUser);
response.status(200);
return "[{\"success\":{\"username\":\"" + newUser + "\"}}]";
} );
// http://ip_address:port/api/{userId} returns json objects for the list of names of lights
// http://ip_address:port/api/{userId} returns json objects for the full state
get(HUE_CONTEXT + "/:userid", "application/json", (request, response) -> {
String userId = request.params(":userid");
log.info("hue api root requested: " + userId + " from " + request.ip());
List<DeviceDescriptor> descriptorList = repository.findByDeviceType("switch");
log.info("hue api full state requested: " + userId + " from " + request.ip());
List<DeviceDescriptor> descriptorList = repository.findAll();
if (descriptorList == null) {
response.status(404);
return null;
@@ -160,10 +167,12 @@ public class HueMulator {
if(url.contains(INTENSITY_BYTE)){
String intensityByte = String.valueOf(state.getBri());
url = url.replace(INTENSITY_BYTE, intensityByte);
responseString = "[{\"success\":{\"/lights/" + lightId + "/state/bri\":"+ String.valueOf(state.getBri()) + "}}]";
}else if(url.contains(INTENSITY_PERCENT)){
int percentBrightness = (int) Math.round(state.getBri()/255.0*100);
String intensityPercent = String.valueOf(percentBrightness);
url = url.replace(INTENSITY_PERCENT, intensityPercent);
responseString = "[{\"success\":{\"/lights/" + lightId + "/state/bri\":"+ String.valueOf(state.getBri()) + "}}]";
}
//make call

View File

@@ -64,6 +64,12 @@ public class UpnpListener {
upnpMulticastSocket.receive(packet);
String packetString = new String(packet.getData());
if(isSSDPDiscovery(packetString)){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
log.error("could not sleep");
}
log.debug("Got SSDP Discovery packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort());
sendUpnpResponse(responseSocket, packet.getAddress(), packet.getPort());
}
@@ -83,7 +89,9 @@ public class UpnpListener {
* @return
*/
protected boolean isSSDPDiscovery(String body){
if(body != null && body.startsWith("M-SEARCH * HTTP/1.1") && body.contains("MAN: \"ssdp:discover\"")){
// log.debug("Check if this is a MAN ssdp-discover packet for a upnp basic device: " + body);
//Only respond to discover request for upnp basic device from echo, the others are for the wemo
if(body != null && body.startsWith("M-SEARCH * HTTP/1.1") && body.contains("MAN: \"ssdp:discover\"")&& body.contains("ST: urn:schemas-upnp-org:device:basic:1")){
return true;
}
return false;
@@ -92,11 +100,10 @@ public class UpnpListener {
String discoveryTemplate = "HTTP/1.1 200 OK\r\n" +
"CACHE-CONTROL: max-age=86400\r\n" +
"EXT:\r\n" +
"LOCATION: http://%s:%s/upnp/amazon-ha-bridge/setup.xml\r\n" +
"OPT: \"http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n" +
"01-NLS: %s\r\n" +
"LOCATION: http://%s:%s/upnp/ha-bridge/description.xml\r\n" +
"SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/0.1\r\n" +
"ST: urn:schemas-upnp-org:device:basic:1\r\n" +
"USN: uuid:Socket-1_0-221438K0100073::urn:Belkin:device:**\r\n\r\n";
"USN: uuid:Socket-1_0-221438K0100073::urn:schemas-upnp-org:device:basic:1\r\n\r\n";
protected void sendUpnpResponse(DatagramSocket socket, InetAddress requester, int sourcePort) throws IOException {
String discoveryResponse = String.format(discoveryTemplate, responseAddress, httpServerPort, getRandomUUIDString());
log.debug("sndUpnpResponse: " + discoveryResponse);

View File

@@ -25,7 +25,7 @@ public class UpnpSettingsResource {
+ "<manufacturerURL>http://www.bwssystems.com</manufacturerURL>\n"
+ "<modelDescription>Hue Emulator for HA bridge</modelDescription>\n"
+ "<modelName>Philips hue bridge 2012</modelName>\n" + "<modelNumber>929000226503</modelNumber>\n"
+ "<modelURL>http://www.bwssystems.com/ha-bridge</modelURL>\n"
+ "<modelURL>http://www.bwssystems.com/apps.html</modelURL>\n"
+ "<serialNumber>01189998819991197253</serialNumber>\n"
+ "<UDN>uuid:88f6698f-2c83-4393-bd03-cd54a9f8595</UDN>\n" + "<serviceList>\n" + "<service>\n"
+ "<serviceType>(null)</serviceType>\n" + "<serviceId>(null)</serviceId>\n"
@@ -44,8 +44,8 @@ public class UpnpSettingsResource {
}
private void setupListener (BridgeSettings theSettings) {
// http://ip_address:port/upnp/:id/setup.xml which returns the xml configuration for the location of the hue emulator
get(UPNP_CONTEXT + "/:id/setup.xml", "application/xml", (request, response) -> {
// http://ip_address:port/upnp/:id/description.xml which returns the xml configuration for the location of the hue emulator
get(UPNP_CONTEXT + "/:id/description.xml", "application/xml", (request, response) -> {
log.info("upnp device settings requested: " + request.params(":id") + " from " + request.ip());
String portNumber = Integer.toString(request.port());
String filledTemplate = String.format(hueTemplate, theSettings.getUpnpConfigAddress(), portNumber, theSettings.getUpnpConfigAddress());
@@ -56,7 +56,7 @@ public class UpnpSettingsResource {
} );
// http://ip_address:port/upnp/settings which returns the bridge configuration settings
get(UPNP_CONTEXT + "/settings", "application/xml", (request, response) -> {
get(UPNP_CONTEXT + "/settings", "application/json", (request, response) -> {
log.debug("bridge settings requested from " + request.ip());
response.status(201);

View File

@@ -148,7 +148,7 @@ app.service('bridgeService', function ($http, BridgeSettings) {
return $http.put(putUrl, {
id: id,
name: name,
deviceType: "switch",
deviceType: type,
onUrl: onUrl,
offUrl: offUrl
}).then(
@@ -165,7 +165,7 @@ app.service('bridgeService', function ($http, BridgeSettings) {
} else {
return $http.post(this.state.base, {
name: name,
deviceType: "switch",
deviceType: type,
onUrl: onUrl,
offUrl: offUrl
}).then(
@@ -225,7 +225,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService,
app.controller('AddingController', function ($scope, bridgeService, BridgeSettings) {
$scope.device = {id: "", name: "", type: "switch", onUrl: "", offUrl: ""};
$scope.device = {id: "", name: "", deviceType: "switch", onUrl: "", offUrl: ""};
$scope.vera = {base: "", port: "3480", id: ""};
$scope.vera.base = "http://" + BridgeSettings.veraaddress;
bridgeService.device = $scope.device;
@@ -250,6 +250,7 @@ app.controller('AddingController', function ($scope, bridgeService, BridgeSettin
if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + $scope.vera.base;
}
$scope.device.deviceType = "scene";
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
+ $scope.vera.id;
@@ -275,6 +276,7 @@ app.controller('AddingController', function ($scope, bridgeService, BridgeSettin
if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + $scope.vera.base;
}
$scope.device.deviceType = "scene";
$scope.device.name = verascene.name;
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="

View File

@@ -1,11 +1,9 @@
<h2>Configuration <a class="btn btn-primary pull-right" href="#/editor"><i
class="icon-plis-sign icon-white"></i> Manual Add</a>
<a class="btn btn-primary pull-right" href="#/verascenes"><i
class="icon-plis-sign icon-white"></i> Vera Scenes</a>
<a class="btn btn-primary pull-right" href="#/veradevices"><i
class="icon-plis-sign icon-white"></i> Vera Devices</a>
</h2>
<ul class="nav nav-pills" role="tablist">
<li role="presentation" class="active"><a href="#">Configuration</a></li>
<li role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation"><a href="#/editor">Manual Add</a></li>
</ul>
<div class="panel panel-default bridgeServer">
<div class="panel-heading">

View File

@@ -1,7 +1,10 @@
<h2>
Device Editor <a class="btn btn-primary pull-right" href="/">
Configuration</a>
</h2>
<ul class="nav nav-pills" role="tablist">
<li role="presentation"><a href="#">Configuration</a></li>
<li role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation"><a href="#/editor">Manual Add</a></li>
<li role="presentation" class="active"><a href="#/editdevice">Edit Device</a></li>
</ul>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">

View File

@@ -1,7 +1,9 @@
<h2>
Manual Add <a class="btn btn-primary pull-right" href="/">
Configuration</a>
</h2>
<ul class="nav nav-pills" role="tablist">
<li role="presentation"><a href="#">Configuration</a></li>
<li role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation" class="active"><a href="#/editor">Manual Add</a></li>
</ul>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">

View File

@@ -1,7 +1,9 @@
<h2>
Vera Device <a class="btn btn-primary pull-right" href="/">
Configuration</a>
</h2>
<ul class="nav nav-pills" role="tablist">
<li role="presentation"><a href="#">Configuration</a></li>
<li role="presentation" class="active"><a href="#/veradevices">Vera Devices</a></li>
<li role="presentation"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation"><a href="#/editor">Manual Add</a></li>
</ul>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">

View File

@@ -1,7 +1,9 @@
<h2>
Vera Scene <a class="btn btn-primary pull-right" href="/">
Configuration</a>
</h2>
<ul class="nav nav-pills" role="tablist">
<li role="presentation"><a href="#">Configuration</a></li>
<li role="presentation"><a href="#/veradevices">Vera Devices</a></li>
<li role="presentation" class="active"><a href="#/verascenes">Vera Scenes</a></li>
<li role="presentation"><a href="#/editor">Manual Add</a></li>
</ul>
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
<div class="panel-heading">