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:
Admin
2015-08-12 16:44:48 -05:00
parent 3911f802ee
commit f8bebe38c0
17 changed files with 398 additions and 164 deletions

View File

@@ -0,0 +1,84 @@
package com.bwssystems.HABridge;
import static spark.Spark.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 HABridge {
/*
* This program is based on the work of armzilla from this github repository:
* https://github.com/armzilla/amazon-echo-ha-bridge
*
* This is the main entry point to start the amazon echo bridge.
*
* This program is using sparkjava rest server to build all the http calls.
* Sparkjava is a microframework that uses Jetty webserver module to host
* its' calls. This is a very compact system than using the spring frameworks
* that was previously used.
*
* There is a custom upnp listener that is started to handle discovery.
*
*
*/
public static void main(String[] args) {
Logger log = LoggerFactory.getLogger(HABridge.class);
DeviceResource theResources;
HueMulator theHueMulator;
UpnpSettingsResource theSettingResponder;
UpnpListener theUpnpListener;
VeraInfo theVera;
InetAddress address;
String addressString;
BridgeSettings bridgeSettings;
//get ip address for upnp requests
try {
address = InetAddress.getLocalHost();
addressString = address.getHostAddress();
} catch (UnknownHostException e) {
log.error("Cannot get ip address of this host, Exiting with message: " + e.getMessage(), e);
return;
}
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
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(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(bridgeSettings);
// wait for the sparkjava initialization of the rest api classes to be complete
awaitInitialization();
// start the upnp ssdp discovery listener
theUpnpListener = new UpnpListener(bridgeSettings);
log.info("Done setup, application to run....");
theUpnpListener.startListening();
}
}