mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 00:10:20 +00:00
Update application from amazon-echo-bridge-compact to ha-bridge.
Try to remove most code naming away from amazon. Fix package names being incorrect. Added Vera query functionality, needs some fine tuning.
This commit is contained in:
42
pom.xml
42
pom.xml
@@ -3,13 +3,13 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.bwssytems.HABridge</groupId>
|
||||
<artifactId>amazon-echo-bridge-compact</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Amazon Echo Bridge Compact</name>
|
||||
<description>Emulates a Philips Hue bridge to allow the Amazon Echo to hook up to other HA using lightweight frameworks</description>
|
||||
<name>HA Bridge</name>
|
||||
<description>Emulates a Philips Hue bridge to allow the Amazon Echo to hook up to other HA systems, i.e. Vera, using lightweight frameworks</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
@@ -56,19 +56,6 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>true</createDependencyReducedPom>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -76,10 +63,27 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
<exclude>META-INF/maven/**</exclude>
|
||||
<exclude>META-INF/services/**</exclude>
|
||||
<exclude>META-INF/DEPENDENCIES</exclude>
|
||||
<exclude>about_files/**</exclude>
|
||||
<exclude>*.properties</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>com.bwssytems.HABridge.AmazonEchoBridge</mainClass>
|
||||
<mainClass>com.bwssystems.HABridge.HABridge</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bwssytems.HABridge;
|
||||
package com.bwssystems.HABridge;
|
||||
|
||||
import static spark.Spark.*;
|
||||
|
||||
@@ -8,12 +8,13 @@ import java.net.UnknownHostException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bwssytems.HABridge.devicemanagmeent.*;
|
||||
import com.bwssytems.HABridge.hue.HueMulator;
|
||||
import com.bwssytems.HABridge.upnp.UpnpListener;
|
||||
import com.bwssytems.HABridge.upnp.UpnpSettingsResource;
|
||||
import com.bwssystems.HABridge.devicemanagmeent.*;
|
||||
import com.bwssystems.HABridge.hue.HueMulator;
|
||||
import com.bwssystems.HABridge.upnp.UpnpListener;
|
||||
import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
|
||||
import com.bwssystems.vera.VeraInfo;
|
||||
|
||||
public class AmazonEchoBridge {
|
||||
public class HABridge {
|
||||
|
||||
/*
|
||||
* This program is based on the work of armzilla from this github repository:
|
||||
@@ -31,15 +32,16 @@ public class AmazonEchoBridge {
|
||||
*
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Logger log = LoggerFactory.getLogger(AmazonEchoBridge.class);
|
||||
Logger log = LoggerFactory.getLogger(HABridge.class);
|
||||
DeviceResource theResources;
|
||||
HueMulator theHueMulator;
|
||||
UpnpSettingsResource theSettingResponder;
|
||||
UpnpListener theUpnpListener;
|
||||
VeraInfo theVera;
|
||||
InetAddress address;
|
||||
String addressString;
|
||||
String upnpAddressString;
|
||||
String serverPort;
|
||||
BridgeSettings bridgeSettings;
|
||||
|
||||
//get ip address for upnp requests
|
||||
try {
|
||||
address = InetAddress.getLocalHost();
|
||||
@@ -49,27 +51,33 @@ public class AmazonEchoBridge {
|
||||
return;
|
||||
}
|
||||
|
||||
upnpAddressString = System.getProperty("upnp.config.address", addressString);
|
||||
bridgeSettings = new BridgeSettings();
|
||||
bridgeSettings.setUpnpConfigAddress(System.getProperty("upnp.config.address", addressString));
|
||||
bridgeSettings.setUpnpDeviceDb(System.getProperty("upnp.device.db", "data/device.db"));
|
||||
bridgeSettings.setUpnpResponsePort(System.getProperty("upnp.response.port", "50000"));
|
||||
bridgeSettings.setVeraAddress(System.getProperty("vera.address", "192.168.1.100"));
|
||||
|
||||
// sparkjava config directive to set ip address for the web server to listen on
|
||||
// ipAddress("0.0.0.0"); // not used
|
||||
// sparkjava config directive to set port for the web server to listen on
|
||||
serverPort = System.getProperty("server.port", "8080");
|
||||
port(Integer.valueOf(serverPort));
|
||||
bridgeSettings.setServerPort(System.getProperty("server.port", "8080"));
|
||||
port(Integer.valueOf(bridgeSettings.getServerPort()));
|
||||
// sparkjava config directive to set html static file location for Jetty
|
||||
staticFileLocation("/public");
|
||||
log.info("Starting setup....");
|
||||
theVera = new VeraInfo(bridgeSettings.getVeraAddress());
|
||||
theVera.getSdata();
|
||||
// setup the class to handle the resource setup rest api
|
||||
theResources = new DeviceResource();
|
||||
theResources = new DeviceResource(bridgeSettings);
|
||||
// setup the class to handle the hue emulator rest api
|
||||
theHueMulator = new HueMulator(theResources.getDeviceRepository());
|
||||
// setup the class to handle the upnp response rest api
|
||||
theSettingResponder = new UpnpSettingsResource(upnpAddressString);
|
||||
theSettingResponder = new UpnpSettingsResource(bridgeSettings);
|
||||
// wait for the sparkjava initialization of the rest api classes to be complete
|
||||
awaitInitialization();
|
||||
|
||||
// start the upnp ssdp discovery listener
|
||||
theUpnpListener = new UpnpListener(upnpAddressString, serverPort);
|
||||
theUpnpListener = new UpnpListener(bridgeSettings);
|
||||
log.info("Done setup, application to run....");
|
||||
theUpnpListener.startListening();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bwssytems.HABridge;
|
||||
package com.bwssystems.HABridge;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import spark.ResponseTransformer;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bwssytems.HABridge.api;
|
||||
package com.bwssystems.HABridge.api;
|
||||
|
||||
/**
|
||||
* Created by arm on 4/13/15.
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bwssytems.HABridge.api.hue;
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bwssytems.HABridge.api.hue;
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.bwssytems.HABridge.api.hue;
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.bwssytems.HABridge.api.hue.DeviceResponse;
|
||||
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
||||
|
||||
/**
|
||||
* Created by arm on 4/14/15.
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bwssytems.HABridge.dao;
|
||||
package com.bwssystems.HABridge.dao;
|
||||
/*
|
||||
* Object to handle the device configuration
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bwssytems.HABridge.dao;
|
||||
package com.bwssystems.HABridge.dao;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -14,8 +14,8 @@ import java.util.Random;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bwssytems.HABridge.JsonTransformer;
|
||||
import com.bwssytems.HABridge.dao.DeviceDescriptor;
|
||||
import com.bwssystems.HABridge.JsonTransformer;
|
||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
import java.util.List;
|
||||
@@ -30,9 +30,9 @@ public class DeviceRepository {
|
||||
final Random random = new Random();
|
||||
final Logger log = LoggerFactory.getLogger(DeviceRepository.class);
|
||||
|
||||
public DeviceRepository() {
|
||||
public DeviceRepository(String deviceDb) {
|
||||
super();
|
||||
repositoryPath = Paths.get(System.getProperty("upnp.device.db", "data/device.db"));
|
||||
repositoryPath = Paths.get(deviceDb);
|
||||
String jsonContent = repositoryReader(repositoryPath);
|
||||
devices = new HashMap<String, DeviceDescriptor>();
|
||||
if(jsonContent != null)
|
||||
@@ -1,8 +1,4 @@
|
||||
package com.bwssytems.HABridge.devicemanagmeent;
|
||||
|
||||
import com.bwssytems.HABridge.JsonTransformer;
|
||||
import com.bwssytems.HABridge.dao.DeviceDescriptor;
|
||||
import com.bwssytems.HABridge.dao.DeviceRepository;
|
||||
package com.bwssystems.HABridge.devicemanagmeent;
|
||||
|
||||
import static spark.Spark.get;
|
||||
import static spark.Spark.post;
|
||||
@@ -14,6 +10,12 @@ import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bwssystems.HABridge.BridgeSettings;
|
||||
import com.bwssystems.HABridge.JsonTransformer;
|
||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||
import com.bwssystems.HABridge.dao.DeviceRepository;
|
||||
import com.bwssystems.luupRequests.Sdata;
|
||||
import com.bwssystems.vera.VeraInfo;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
@@ -24,11 +26,13 @@ public class DeviceResource {
|
||||
private static final Logger log = LoggerFactory.getLogger(DeviceResource.class);
|
||||
|
||||
private DeviceRepository deviceRepository;
|
||||
private VeraInfo veraInfo;
|
||||
|
||||
|
||||
public DeviceResource() {
|
||||
public DeviceResource(BridgeSettings theSettings) {
|
||||
super();
|
||||
deviceRepository = new DeviceRepository();
|
||||
deviceRepository = new DeviceRepository(theSettings.getUpnpDeviceDb());
|
||||
veraInfo = new VeraInfo(theSettings.getVeraAddress());
|
||||
setupEndpoints();
|
||||
}
|
||||
|
||||
@@ -102,5 +106,24 @@ public class DeviceResource {
|
||||
deviceRepository.delete(deleted);
|
||||
return null;
|
||||
}, new JsonTransformer());
|
||||
|
||||
get (API_CONTEXT + "/vera/devices", "application/json", (request, response) -> {
|
||||
log.debug("Get vera devices");
|
||||
Sdata sData = veraInfo.getSdata();
|
||||
if(sData == null){
|
||||
return null;
|
||||
}
|
||||
return sData.getDevices();
|
||||
}, new JsonTransformer());
|
||||
|
||||
get (API_CONTEXT + "/vera/scenes", "application/json", (request, response) -> {
|
||||
log.debug("Get vera scenes");
|
||||
Sdata sData = veraInfo.getSdata();
|
||||
if(sData == null){
|
||||
return null;
|
||||
}
|
||||
return sData.getScenes();
|
||||
}, new JsonTransformer());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.bwssytems.HABridge.hue;
|
||||
|
||||
import com.bwssytems.HABridge.api.hue.DeviceResponse;
|
||||
import com.bwssytems.HABridge.api.hue.DeviceState;
|
||||
import com.bwssytems.HABridge.api.hue.HueApiResponse;
|
||||
import com.bwssytems.HABridge.dao.*;
|
||||
import com.bwssytems.HABridge.JsonTransformer;
|
||||
package com.bwssystems.HABridge.hue;
|
||||
|
||||
import com.bwssystems.HABridge.JsonTransformer;
|
||||
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;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.bwssytems.HABridge.upnp;
|
||||
package com.bwssystems.HABridge.upnp;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bwssystems.HABridge.BridgeSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
|
||||
@@ -21,11 +23,11 @@ public class UpnpListener {
|
||||
|
||||
private String responseAddress;
|
||||
|
||||
public UpnpListener(String upnpAddress, String upnpServerPort) {
|
||||
public UpnpListener(BridgeSettings theSettings) {
|
||||
super();
|
||||
upnpResponsePort = Integer.valueOf(System.getProperty("upnp.response.port", "50000"));
|
||||
httpServerPort = Integer.valueOf(upnpServerPort);
|
||||
responseAddress = upnpAddress;
|
||||
upnpResponsePort = Integer.valueOf(theSettings.getUpnpResponsePort());
|
||||
httpServerPort = Integer.valueOf(theSettings.getServerPort());
|
||||
responseAddress = theSettings.getUpnpConfigAddress();
|
||||
}
|
||||
|
||||
public void startListening(){
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.bwssytems.HABridge.upnp;
|
||||
package com.bwssystems.HABridge.upnp;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bwssystems.HABridge.BridgeSettings;
|
||||
import com.bwssystems.HABridge.JsonTransformer;
|
||||
|
||||
import static spark.Spark.get;
|
||||
|
||||
/**
|
||||
@@ -17,12 +20,12 @@ public class UpnpSettingsResource {
|
||||
+ "<specVersion>\n" + "<major>1</major>\n" + "<minor>0</minor>\n" + "</specVersion>\n"
|
||||
+ "<URLBase>http://%s:%s/</URLBase>\n" + // hostname string
|
||||
"<device>\n" + "<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>\n"
|
||||
+ "<friendlyName>Amazon-Echo-HA-Bridge (%s)</friendlyName>\n"
|
||||
+ "<friendlyName>HA-Bridge (%s)</friendlyName>\n"
|
||||
+ "<manufacturer>Royal Philips Electronics</manufacturer>\n"
|
||||
+ "<manufacturerURL>http://www.bwssystems..com</manufacturerURL>\n"
|
||||
+ "<modelDescription>Hue Emulator for Amazon Echo bridge</modelDescription>\n"
|
||||
+ "<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/amazon-echo-bridge-compact</modelURL>\n"
|
||||
+ "<modelURL>http://www.bwssystems.com/ha-bridge</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"
|
||||
@@ -35,29 +38,30 @@ public class UpnpSettingsResource {
|
||||
+ "<depth>24</depth>\n" + "<url>hue_logo_3.png</url>\n" + "</icon>\n" + "</iconList>\n" + "</device>\n"
|
||||
+ "</root>\n";
|
||||
|
||||
public UpnpSettingsResource(String upnpAddress) {
|
||||
public UpnpSettingsResource(BridgeSettings theSettings) {
|
||||
super();
|
||||
setupListener(upnpAddress);
|
||||
setupListener(theSettings);
|
||||
}
|
||||
|
||||
private void setupListener (String hostName) {
|
||||
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) -> {
|
||||
log.info("upnp device settings requested: " + request.params(":id") + " from " + request.ip());
|
||||
String portNumber = Integer.toString(request.port());
|
||||
String filledTemplate = String.format(hueTemplate, hostName, portNumber, hostName);
|
||||
String filledTemplate = String.format(hueTemplate, theSettings.getUpnpConfigAddress(), portNumber, theSettings.getUpnpConfigAddress());
|
||||
log.debug("upnp device settings response: " + filledTemplate);
|
||||
response.status(201);
|
||||
|
||||
return filledTemplate;
|
||||
} );
|
||||
|
||||
get(UPNP_CONTEXT + "/configaddress", "application/xml", (request, response) -> {
|
||||
log.info("upnp config address requested: from " + request.ip());
|
||||
// http://ip_address:port/upnp/settings which returns the bridge configuration settings
|
||||
get(UPNP_CONTEXT + "/settings", "application/xml", (request, response) -> {
|
||||
log.debug("bridge settings requested from " + request.ip());
|
||||
|
||||
response.status(201);
|
||||
|
||||
return hostName;
|
||||
} );
|
||||
return theSettings;
|
||||
}, new JsonTransformer());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
upnp.response.port=50000
|
||||
server.port=8080
|
||||
upnp.config.address=192.168.4.136
|
||||
@@ -4,63 +4,110 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Amazon Echo Bridge Configuration</title>
|
||||
<title>HA Bridge Configuration</title>
|
||||
<style>
|
||||
body {
|
||||
padding-top: 60px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<script type="text/javascript" src="js/html5shiv.min.js"></script>
|
||||
<script type="text/javascript" src="js/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js"></script>
|
||||
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
|
||||
<script type="text/javascript" src="js/angular.min.js"></script>
|
||||
<script type="text/javascript" src="js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="scripts/app.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body ng-app="amazonechobridge">
|
||||
<body ng-app="habridge">
|
||||
|
||||
<nav class="navbar navbar-inverse navbar-fixed-top">
|
||||
<nav class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="#">Amazon Echo Bridge Configuration</a>
|
||||
<button type="button" class="navbar-toggle collapsed"
|
||||
data-toggle="collapse" data-target="#navbar" aria-expanded="false"
|
||||
aria-controls="navbar">
|
||||
<span class="sr-only">Toggle navigation</span> <span
|
||||
class="icon-bar"></span> <span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">HA Bridge</a>
|
||||
</div>
|
||||
<div id="navbar" class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<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"
|
||||
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>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<!--/.nav-collapse -->
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<div class="container">
|
||||
<div ng-controller="ViewingController">
|
||||
|
||||
<div class="page-header">
|
||||
<h1>Configuration</h1>
|
||||
</div>
|
||||
<div class="panel panel-default bridgeServer">
|
||||
<div class="panel-heading"><h1 class="panel-title">Bridge settings</h1></div>
|
||||
<div class="panel-body">
|
||||
|
||||
<form class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-xs-12 col-sm-3 control-label" for="bridge-base">Bridge server</label>
|
||||
<label class="col-xs-12 col-sm-3 control-label" for="bridge-base">Bridge
|
||||
server</label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input id="bridge-base" class="form-control" type="text" ng-model="bridge.base"
|
||||
placeholder="URL to bridge">
|
||||
<input id="bridge-base" class="form-control" type="text"
|
||||
ng-model="bridge.base" placeholder="URL to bridge">
|
||||
</div>
|
||||
<button type="submit" class="col-xs-2 col-sm-1 btn btn-primary"
|
||||
ng-click="setBridgeUrl(bridge.base)">Load
|
||||
</button>
|
||||
<button type="submit" class="col-xs-2 col-sm-1 btn btn-primary" ng-click="testUrl(bridge.base)">Go
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-xs-12 col-sm-3 control-label" for="bridge-base">upnp.config.address</label>
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input id="bridge-base" class="form-control" type="text" ng-model="bridge.upnpconfigaddress"
|
||||
placeholder="upnp config address setting" readonly>
|
||||
</div>
|
||||
ng-click="setBridgeUrl(bridge.base)">Load</button>
|
||||
<button type="submit" class="col-xs-2 col-sm-1 btn btn-primary"
|
||||
ng-click="testUrl(bridge.base)">Go</button>
|
||||
</div>
|
||||
</form>
|
||||
<table class="table table-bordered table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Setting</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr>
|
||||
<td>upnp.config.address</td>
|
||||
<td>{{bridge.upnpconfigaddress}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>server.port</td>
|
||||
<td>{{bridge.serverport}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>upnp.devices.db</td>
|
||||
<td>{{bridge.upnpdevicedb}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>upnp.response.port</td>
|
||||
<td>{{bridge.upnpresponseport}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>vera.address</td>
|
||||
<td>{{bridge.veraaddress}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -95,17 +142,85 @@
|
||||
<td>
|
||||
<button class="btn btn-info" type="submit" ng-click="testUrl(device.onUrl)">Test ON</button>
|
||||
<button class="btn btn-info" type="submit" ng-click="testUrl(device.offUrl)">Test OFF</button>
|
||||
<button class="btn btn-danger" type="submit" ng-click="editDevice(device)">Edit</button>
|
||||
<button class="btn btn-warning" type="submit" ng-click="editDevice(device)">Edit</button>
|
||||
<button class="btn btn-danger" type="submit" ng-click="deleteDevice(device)">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-controller="AddingController">
|
||||
<div class="page-header">
|
||||
<h1>Editor</h1>
|
||||
</div>
|
||||
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
|
||||
<div class="panel-heading"><h2 class="panel-title">Add a new device</h2></div>
|
||||
<div class="panel-heading">
|
||||
<h2 class="panel-title">Vera Device List</h2>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
<table class="table table-bordered table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Id</th>
|
||||
<th>Category</th>
|
||||
<th>Room</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr ng-repeat="veradevice in bridge.veradevices">
|
||||
<td>{{veradevice.name}}</td>
|
||||
<td>{{veradevice.id}}</td>
|
||||
<td>{{veradevice.category}}</td>
|
||||
<td>{{veradevice.room}}</td>
|
||||
<td>
|
||||
<button class="btn btn-success" type="submit"
|
||||
ng-click="buildDeviceUrls(veradevice, bridge.veraaddress)">Generate Device URLs</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
|
||||
<div class="panel-heading">
|
||||
<h2 class="panel-title">Vera Scene List</h2>
|
||||
</div>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<p class="text-muted">You can select a Vera scene and
|
||||
generate the add device box selections automatically.</p>
|
||||
|
||||
<table class="table table-bordered table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Id</th>
|
||||
<th>Room</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr ng-repeat="verascene in bridge.verascenes">
|
||||
<td>{{verascene.name}}</td>
|
||||
<td>{{verascene.id}}</td>
|
||||
<td>{{verascene.room}}</td>
|
||||
<td>
|
||||
<button class="btn btn-success" type="submit"
|
||||
ng-click="buildSceneUrls(verascene, bridge.veraaddress)">Generate Device URLs</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
|
||||
<div class="panel-heading">
|
||||
<h2 class="panel-title">Generate a new device</h2>
|
||||
</div>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<p class="text-muted">You can generate on/off URLs by filling in the Vera server URL, port, and
|
||||
@@ -115,10 +230,14 @@
|
||||
<div class="form-group">
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="vera-base">Vera Server URL </label>
|
||||
|
||||
<div class="col-xs-12 col-sm-10">
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input type="text" class="form-control" id="vera-base" ng-model="vera.base"
|
||||
placeholder="Vera URL (e.g. http://192.168.1.100)">
|
||||
</div>
|
||||
<button type="submit" ng-click="setVeraAddress(bridge.veraaddress)"
|
||||
class="col-xs-4 col-sm-2 btn btn-success">
|
||||
Use vera.address
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-xs-2 col-sm-2 control-label" for="vera-port">Vera Request Port </label>
|
||||
@@ -135,12 +254,19 @@
|
||||
placeholder="ID">
|
||||
</div>
|
||||
<button type="submit" ng-click="buildUrls()"
|
||||
class="col-xs-offset-2 col-sm-offset-1 col-xs-4 col-sm-2 btn btn-success">
|
||||
Generate URLs
|
||||
class="col-xs-4 col-sm-2 btn btn-success">
|
||||
Generate Device URLs
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
|
||||
<div class="panel-heading">
|
||||
<h2 class="panel-title">Add a new device</h2>
|
||||
</div>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<form class="form-horizontal" ng-submit="addDevice()">
|
||||
<div class="form-group">
|
||||
@@ -181,8 +307,8 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,7 @@
|
||||
angular.module('amazonechobridge', [])
|
||||
angular.module('habridge', [])
|
||||
.service('bridgeService', ["$http", function ($http) {
|
||||
var self = this;
|
||||
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/configaddress", devices: [], error: ""};
|
||||
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], error: ""};
|
||||
|
||||
this.viewDevices = function () {
|
||||
this.state.error = "";
|
||||
@@ -21,11 +21,51 @@ angular.module('amazonechobridge', [])
|
||||
);
|
||||
};
|
||||
|
||||
this.viewConfigAddress = function () {
|
||||
this.viewBridgeSettings = function () {
|
||||
this.state.error = "";
|
||||
return $http.get(this.state.upnpbase).then(
|
||||
function (response) {
|
||||
self.state.upnpconfigaddress = response.data;
|
||||
self.state.upnpconfigaddress = response.data.upnpconfigaddress;
|
||||
self.state.serverport = response.data.serverport;
|
||||
self.state.upnpdevicedb = response.data.upnpdevicedb;
|
||||
self.state.upnpresponseport = response.data.upnpresponseport;
|
||||
self.state.veraaddress = response.data.veraaddress;
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.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.";
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.viewVeraDevices = function () {
|
||||
this.state.error = "";
|
||||
return $http.get(this.state.base + "/vera/devices").then(
|
||||
function (response) {
|
||||
self.state.veradevices = response.data;
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.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.";
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.viewVeraScenes = function () {
|
||||
this.state.error = "";
|
||||
return $http.get(this.state.base + "/vera/scenes").then(
|
||||
function (response) {
|
||||
self.state.verascenes = response.data;
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
@@ -105,7 +145,9 @@ angular.module('amazonechobridge', [])
|
||||
|
||||
.controller('ViewingController', ["$scope", "bridgeService", function ($scope, bridgeService) {
|
||||
bridgeService.viewDevices();
|
||||
bridgeService.viewConfigAddress();
|
||||
bridgeService.viewBridgeSettings();
|
||||
bridgeService.viewVeraDevices();
|
||||
bridgeService.viewVeraScenes();
|
||||
$scope.bridge = bridgeService.state;
|
||||
$scope.deleteDevice = function (device) {
|
||||
bridgeService.deleteDevice(device.id);
|
||||
@@ -123,8 +165,6 @@ angular.module('amazonechobridge', [])
|
||||
}])
|
||||
|
||||
.controller('AddingController', ["$scope", "bridgeService", function ($scope, bridgeService) {
|
||||
|
||||
$scope.bridge = bridgeService.state;
|
||||
$scope.device = {id: "", name: "", type: "switch", onUrl: "", offUrl: ""};
|
||||
$scope.vera = {base: "", port: "3480", id: ""};
|
||||
bridgeService.device = $scope.device;
|
||||
@@ -141,6 +181,36 @@ angular.module('amazonechobridge', [])
|
||||
+ $scope.vera.id;
|
||||
};
|
||||
|
||||
$scope.buildDeviceUrls = function (veradevice, veraaddr) {
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + veraaddr;
|
||||
}
|
||||
$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;
|
||||
$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;
|
||||
};
|
||||
|
||||
$scope.buildSceneUrls = function (verascene, veraaddr) {
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + veraaddr;
|
||||
}
|
||||
$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="
|
||||
+ verascene.id;
|
||||
$scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||
+ verascene.id;
|
||||
};
|
||||
|
||||
$scope.setVeraAddress = function (anAddress) {
|
||||
$scope.vera.base = "http://" + anAddress;
|
||||
};
|
||||
|
||||
$scope.testUrl = function (url) {
|
||||
window.open(url, "_blank");
|
||||
};
|
||||
@@ -157,6 +227,7 @@ angular.module('amazonechobridge', [])
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}])
|
||||
|
||||
.controller('ErrorsController', ["$scope", "bridgeService", function ($scope, bridgeService) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package demo;
|
||||
|
||||
import com.bwssytems.HABridge.AmazonEchoBridge;
|
||||
import com.bwssystems.HABridge.HABridge;
|
||||
|
||||
/*
|
||||
* Dummy test holder
|
||||
|
||||
Reference in New Issue
Block a user