Fixed bulk add race conditions. added save capability into UI. UI

settings layout update.
This commit is contained in:
Admin
2016-02-12 15:51:38 -06:00
parent 7b45ca9438
commit c97ab2cd38
13 changed files with 268 additions and 249 deletions

View File

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

View File

@@ -29,6 +29,8 @@ public abstract class BackupHandler {
fileExtension = "." + anExtension;
defaultName = adefaultName;
log.debug("setupParams has defaultName: " + defaultName + " and file extension as: " + fileExtension);
}
public String backup(String aFilename) {
@@ -78,7 +80,7 @@ public abstract class BackupHandler {
List<String> theFilenames = new ArrayList<String>();
Path dir = repositoryPath.getParent();
try (DirectoryStream<Path> stream =
Files.newDirectoryStream(dir, "*.{"+ fileExtension + "}")) {
Files.newDirectoryStream(dir, "*.{"+ fileExtension.substring(1) + "}")) {
for (Path entry: stream) {
theFilenames.add(entry.getFileName().toString());
}

View File

@@ -0,0 +1,25 @@
package com.bwssystems.HABridge;
public class BridgeControlDescriptor {
private boolean reinit;
private boolean stop;
public BridgeControlDescriptor() {
super();
this.reinit = false;
this.stop = false;
}
public boolean isReinit() {
return reinit;
}
public void setReinit(boolean reinit) {
this.reinit = reinit;
}
public boolean isStop() {
return stop;
}
public void setStop(boolean stop) {
this.stop = stop;
}
}

View File

@@ -19,144 +19,19 @@ import com.google.gson.Gson;
public class BridgeSettings extends BackupHandler {
private BridgeSettingsDescriptor theBridgeSettings;
private boolean reinit;
private boolean stop;
private BridgeControlDescriptor bridgeControl;
public BridgeSettings() {
super();
this.reinit = false;
this.stop = false;
bridgeControl = new BridgeControlDescriptor();
theBridgeSettings = new BridgeSettingsDescriptor();
theBridgeSettings.setUpnpStrict(true);
theBridgeSettings.setDevMode(false);
theBridgeSettings.setTraceupnp(false);
theBridgeSettings.setNestConfigured(false);
theBridgeSettings.setVeraconfigured(false);
theBridgeSettings.setHarmonyconfigured(false);
}
public BridgeControlDescriptor getBridgeControl() {
return bridgeControl;
}
public BridgeSettingsDescriptor getBridgeSettingsDescriptor() {
return theBridgeSettings;
}
public String getUpnpConfigAddress() {
return theBridgeSettings.getUpnpConfigAddress();
}
public void setUpnpConfigAddress(String upnpConfigAddress) {
theBridgeSettings.setUpnpConfigAddress(upnpConfigAddress);
}
public String getServerPort() {
return theBridgeSettings.getServerPort();
}
public void setServerPort(String serverPort) {
theBridgeSettings.setServerPort(serverPort);
}
public String getUpnpResponsePort() {
return theBridgeSettings.getUpnpResponsePort();
}
public void setUpnpResponsePort(String upnpResponsePort) {
theBridgeSettings.setUpnpResponsePort(upnpResponsePort);
}
public String getUpnpDeviceDb() {
return theBridgeSettings.getUpnpDeviceDb();
}
public void setUpnpDeviceDb(String upnpDeviceDb) {
theBridgeSettings.setUpnpDeviceDb(upnpDeviceDb);
}
public IpList getVeraAddress() {
return theBridgeSettings.getVeraAddress();
}
public void setVeraAddress(IpList veraAddress) {
theBridgeSettings.setVeraAddress(veraAddress);
}
public IpList getHarmonyAddress() {
return theBridgeSettings.getHarmonyAddress();
}
public void setHarmonyAddress(IpList harmonyaddress) {
theBridgeSettings.setHarmonyAddress(harmonyaddress);
}
public String getHarmonyUser() {
return theBridgeSettings.getHarmonyUser();
}
public void setHarmonyUser(String harmonyuser) {
theBridgeSettings.setHarmonyUser(harmonyuser);
}
public String getHarmonyPwd() {
return theBridgeSettings.getHarmonyPwd();
}
public void setHarmonyPwd(String harmonypwd) {
theBridgeSettings.setHarmonyPwd(harmonypwd);
}
public boolean isUpnpStrict() {
return theBridgeSettings.isUpnpStrict();
}
public void setUpnpStrict(boolean upnpStrict) {
theBridgeSettings.setUpnpStrict(upnpStrict);
}
public boolean isTraceupnp() {
return theBridgeSettings.isTraceupnp();
}
public void setTraceupnp(boolean traceupnp) {
theBridgeSettings.setTraceupnp(traceupnp);
}
public boolean isDevMode() {
return theBridgeSettings.isDevMode();
}
public void setDevMode(boolean devmode) {
theBridgeSettings.setDevMode(devmode);
}
public String getNestuser() {
return theBridgeSettings.getNestuser();
}
public void setNestuser(String nestuser) {
theBridgeSettings.setNestuser(nestuser);
}
public String getNestpwd() {
return theBridgeSettings.getNestpwd();
}
public void setNestpwd(String nestpwd) {
theBridgeSettings.setNestpwd(nestpwd);
}
public boolean isVeraconfigured() {
return theBridgeSettings.isVeraconfigured();
}
public void setVeraconfigured(boolean veraconfigured) {
theBridgeSettings.setVeraconfigured(veraconfigured);
}
public boolean isHarmonyconfigured() {
return theBridgeSettings.isHarmonyconfigured();
}
public void setHarmonyconfigured(boolean harmonyconfigured) {
theBridgeSettings.setHarmonyconfigured(harmonyconfigured);
}
public boolean isNestConfigured() {
return theBridgeSettings.isNestConfigured();
}
public void setNestConfigured(boolean isNestConfigured) {
theBridgeSettings.setNestConfigured(isNestConfigured);
}
public Integer getButtonsleep() {
return theBridgeSettings.getButtonsleep();
}
public void setButtonsleep(Integer buttonsleep) {
theBridgeSettings.setButtonsleep(buttonsleep);
}
public String getConfigfile() {
return theBridgeSettings.getConfigfile();
}
public void setConfigfile(String configfile) {
theBridgeSettings.setConfigfile(configfile);
}
public boolean isReinit() {
return reinit;
}
public void setReinit(boolean reinit) {
this.reinit = reinit;
}
public boolean isStop() {
return stop;
}
public void setStop(boolean stop) {
this.stop = stop;
}
public void buildSettings() {
Logger log = LoggerFactory.getLogger(BridgeSettings.class);
InetAddress address = null;
@@ -172,17 +47,17 @@ public class BridgeSettings extends BackupHandler {
if(configFileProperty != null)
{
log.info("reading from config file: " + configFileProperty);
setConfigfile(configFileProperty);
theBridgeSettings.setConfigfile(configFileProperty);
_loadConfig();
}
else
{
log.info("reading from system properties");
setConfigfile(Configuration.CONFIG_FILE);
setServerPort(System.getProperty("server.port"));
setUpnpConfigAddress(System.getProperty("upnp.config.address"));
setUpnpDeviceDb(System.getProperty("upnp.device.db"));
setUpnpResponsePort(System.getProperty("upnp.response.port"));
theBridgeSettings.setConfigfile(Configuration.CONFIG_FILE);
theBridgeSettings.setServerPort(System.getProperty("server.port"));
theBridgeSettings.setUpnpConfigAddress(System.getProperty("upnp.config.address"));
theBridgeSettings.setUpnpDeviceDb(System.getProperty("upnp.device.db"));
theBridgeSettings.setUpnpResponsePort(System.getProperty("upnp.response.port"));
theVeraAddress = System.getProperty("vera.address");
IpList theVeraList = null;
@@ -198,7 +73,7 @@ public class BridgeSettings extends BackupHandler {
}
}
}
setVeraAddress(theVeraList);
theBridgeSettings.setVeraAddress(theVeraList);
theHarmonyAddress = System.getProperty("harmony.address");
IpList theHarmonyList = null;
@@ -214,18 +89,18 @@ public class BridgeSettings extends BackupHandler {
}
}
}
setHarmonyAddress(theHarmonyList);
setHarmonyUser(System.getProperty("harmony.user"));
setHarmonyPwd(System.getProperty("harmony.pwd"));
setUpnpStrict(Boolean.parseBoolean(System.getProperty("upnp.strict", "true")));
setTraceupnp(Boolean.parseBoolean(System.getProperty("trace.upnp", "false")));
setDevMode(Boolean.parseBoolean(System.getProperty("dev.mode", "false")));
setButtonsleep(Integer.parseInt(System.getProperty("button.sleep", Configuration.DFAULT_BUTTON_SLEEP)));
setNestuser(System.getProperty("nest.user"));
setNestpwd(System.getProperty("nest.pwd"));
theBridgeSettings.setHarmonyAddress(theHarmonyList);
theBridgeSettings.setHarmonyUser(System.getProperty("harmony.user"));
theBridgeSettings.setHarmonyPwd(System.getProperty("harmony.pwd"));
theBridgeSettings.setUpnpStrict(Boolean.parseBoolean(System.getProperty("upnp.strict", "true")));
theBridgeSettings.setTraceupnp(Boolean.parseBoolean(System.getProperty("trace.upnp", "false")));
theBridgeSettings.setDevMode(Boolean.parseBoolean(System.getProperty("dev.mode", "false")));
theBridgeSettings.setButtonsleep(Integer.parseInt(System.getProperty("button.sleep", Configuration.DFAULT_BUTTON_SLEEP)));
theBridgeSettings.setNestuser(System.getProperty("nest.user"));
theBridgeSettings.setNestpwd(System.getProperty("nest.pwd"));
}
if(getUpnpConfigAddress() == null) {
if(theBridgeSettings.getUpnpConfigAddress() == null) {
try {
log.info("Getting an IP address for this host....");
Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();
@@ -253,62 +128,62 @@ public class BridgeSettings extends BackupHandler {
return;
}
setUpnpConfigAddress(addressString);
theBridgeSettings.setUpnpConfigAddress(addressString);
}
if(this.getUpnpResponsePort() == null)
this.setUpnpResponsePort(Configuration.UPNP_RESPONSE_PORT);
if(theBridgeSettings.getUpnpResponsePort() == null)
theBridgeSettings.setUpnpResponsePort(Configuration.UPNP_RESPONSE_PORT);
if(this.getServerPort() == null)
this.setServerPort(Configuration.DFAULT_WEB_PORT);
if(theBridgeSettings.getServerPort() == null)
theBridgeSettings.setServerPort(Configuration.DFAULT_WEB_PORT);
if(this.getUpnpDeviceDb() == null)
this.setUpnpDeviceDb(Configuration.DEVICE_DB_DIRECTORY);
if(theBridgeSettings.getUpnpDeviceDb() == null)
theBridgeSettings.setUpnpDeviceDb(Configuration.DEVICE_DB_DIRECTORY);
if(this.getButtonsleep() <= 0)
this.setButtonsleep(Integer.parseInt(Configuration.DFAULT_BUTTON_SLEEP));
if(theBridgeSettings.getButtonsleep() <= 0)
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DFAULT_BUTTON_SLEEP));
this.setVeraconfigured(theBridgeSettings.isValidVera());
this.setHarmonyconfigured(theBridgeSettings.isValidHarmony());
this.setNestConfigured(theBridgeSettings.isValidNest());
setupParams(Paths.get(getConfigfile()), ".cfgbk", "habridge.config-");
theBridgeSettings.setVeraconfigured(theBridgeSettings.isValidVera());
theBridgeSettings.setHarmonyconfigured(theBridgeSettings.isValidHarmony());
theBridgeSettings.setNestConfigured(theBridgeSettings.isValidNest());
setupParams(Paths.get(theBridgeSettings.getConfigfile()), ".cfgbk", "habridge.config-");
}
public void loadConfig() {
if(getConfigfile() != null)
if(theBridgeSettings.getConfigfile() != null)
_loadConfig();
}
private void _loadConfig() {
Path configPath = Paths.get(getConfigfile());
Path configPath = Paths.get(theBridgeSettings.getConfigfile());
_loadConfig(configPath);
}
private void _loadConfig(Path aPath) {
String jsonContent = configReader(aPath);
BridgeSettingsDescriptor aBridgeSettings = new Gson().fromJson(jsonContent, BridgeSettingsDescriptor.class);
this.setButtonsleep(aBridgeSettings.getButtonsleep());
this.setUpnpConfigAddress(aBridgeSettings.getUpnpConfigAddress());
this.setServerPort(aBridgeSettings.getServerPort());
this.setUpnpResponsePort(aBridgeSettings.getUpnpResponsePort());
this.setUpnpDeviceDb(aBridgeSettings.getUpnpDeviceDb());
this.setVeraAddress(aBridgeSettings.getVeraAddress());
this.setHarmonyAddress(aBridgeSettings.getHarmonyAddress());
this.setHarmonyUser(aBridgeSettings.getHarmonyUser());
this.setHarmonyPwd(aBridgeSettings.getHarmonyPwd());
this.setUpnpStrict(aBridgeSettings.isUpnpStrict());
this.setTraceupnp(aBridgeSettings.isTraceupnp());
this.setDevMode(aBridgeSettings.isDevMode());
this.setNestuser(aBridgeSettings.getNestuser());
this.setNestpwd(aBridgeSettings.getNestpwd());
this.setVeraconfigured(aBridgeSettings.isValidVera());
this.setHarmonyconfigured(aBridgeSettings.isValidHarmony());
this.setNestConfigured(aBridgeSettings.isValidNest());
theBridgeSettings.setButtonsleep(aBridgeSettings.getButtonsleep());
theBridgeSettings.setUpnpConfigAddress(aBridgeSettings.getUpnpConfigAddress());
theBridgeSettings.setServerPort(aBridgeSettings.getServerPort());
theBridgeSettings.setUpnpResponsePort(aBridgeSettings.getUpnpResponsePort());
theBridgeSettings.setUpnpDeviceDb(aBridgeSettings.getUpnpDeviceDb());
theBridgeSettings.setVeraAddress(aBridgeSettings.getVeraAddress());
theBridgeSettings.setHarmonyAddress(aBridgeSettings.getHarmonyAddress());
theBridgeSettings.setHarmonyUser(aBridgeSettings.getHarmonyUser());
theBridgeSettings.setHarmonyPwd(aBridgeSettings.getHarmonyPwd());
theBridgeSettings.setUpnpStrict(aBridgeSettings.isUpnpStrict());
theBridgeSettings.setTraceupnp(aBridgeSettings.isTraceupnp());
theBridgeSettings.setDevMode(aBridgeSettings.isDevMode());
theBridgeSettings.setNestuser(aBridgeSettings.getNestuser());
theBridgeSettings.setNestpwd(aBridgeSettings.getNestpwd());
theBridgeSettings.setVeraconfigured(aBridgeSettings.isValidVera());
theBridgeSettings.setHarmonyconfigured(aBridgeSettings.isValidHarmony());
theBridgeSettings.setNestConfigured(aBridgeSettings.isValidNest());
}
public void save(BridgeSettings newBridgeSettings) {
public void save(BridgeSettingsDescriptor newBridgeSettings) {
Logger log = LoggerFactory.getLogger(BridgeSettings.class);
log.debug("Save HA Bridge settings.");
Path configPath = Paths.get(getConfigfile());
Path configPath = Paths.get(theBridgeSettings.getConfigfile());
JsonTransformer aRenderer = new JsonTransformer();
String jsonValue = aRenderer.render(newBridgeSettings);
configWriter(jsonValue, configPath);

View File

@@ -46,15 +46,13 @@ public class HABridge {
log.info("HA Bridge (v" + theVersion.getVersion() + ") starting....");
bridgeSettings = new BridgeSettings();
bridgeSettings.setReinit(false);
bridgeSettings.setStop(false);
while(!bridgeSettings.isStop()) {
while(!bridgeSettings.getBridgeControl().isStop()) {
bridgeSettings.buildSettings();
log.info("HA Bridge (v" + theVersion.getVersion() + ") initializing....");
// 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
port(Integer.valueOf(bridgeSettings.getServerPort()));
port(Integer.valueOf(bridgeSettings.getBridgeSettingsDescriptor().getServerPort()));
// sparkjava config directive to set html static file location for Jetty
staticFileLocation("/public");
// setup system control api first
@@ -76,11 +74,11 @@ public class HABridge {
awaitInitialization();
// start the upnp ssdp discovery listener
theUpnpListener = new UpnpListener(bridgeSettings);
theUpnpListener = new UpnpListener(bridgeSettings.getBridgeSettingsDescriptor(), bridgeSettings.getBridgeControl());
if(theUpnpListener.startListening())
log.info("HA Bridge (v" + theVersion.getVersion() + ") reinitialization requessted....");
bridgeSettings.setReinit(false);
bridgeSettings.getBridgeControl().setReinit(false);
stop();
}
log.info("HA Bridge (v" + theVersion.getVersion() + ") exiting....");

View File

@@ -44,7 +44,26 @@ public class SystemControl {
response.status(200);
return bridgeSettings;
return bridgeSettings.getBridgeSettingsDescriptor();
}, new JsonTransformer());
// http://ip_address:port/system/settings CORS request
options(SYSTEM_CONTEXT + "/settings", "application/json", (request, response) -> {
response.status(HttpStatus.SC_OK);
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.header("Access-Control-Allow-Methods", "GET, POST, PUT");
response.header("Access-Control-Allow-Headers", request.headers("Access-Control-Request-Headers"));
response.header("Content-Type", "text/html; charset=utf-8");
return "";
});
// http://ip_address:port/system/settings which returns the bridge configuration settings
put(SYSTEM_CONTEXT + "/settings", "application/json", (request, response) -> {
log.info("save bridge settings requested from " + request.ip() + " with body: " + request.body());
BridgeSettingsDescriptor newBridgeSettings = new Gson().fromJson(request.body(), BridgeSettingsDescriptor.class);
bridgeSettings.save(newBridgeSettings);
response.status(200);
return bridgeSettings.getBridgeSettingsDescriptor();
}, new JsonTransformer());
// http://ip_address:port/system/control/reinit CORS request
@@ -160,13 +179,13 @@ public class SystemControl {
}
public String reinit() {
bridgeSettings.setReinit(true);
bridgeSettings.getBridgeControl().setReinit(true);
pingListener();
return "{\"control\":\"reiniting\"}";
}
public String stop() {
bridgeSettings.setStop(true);
bridgeSettings.getBridgeControl().setStop(true);
pingListener();
return "{\"control\":\"stopping\"}";
}

View File

@@ -79,16 +79,20 @@ public class DeviceRepository extends BackupHandler {
devices.put(id, aDescriptor);
}
public void save(DeviceDescriptor aDescriptor) {
if(aDescriptor.getId() != null)
devices.remove(aDescriptor.getId());
else
aDescriptor.setId(String.valueOf(random.nextInt(Integer.MAX_VALUE)));
put(aDescriptor.getId(), aDescriptor);
public void save(DeviceDescriptor[] descriptors) {
String theNames = "";
for(int i = 0; i < descriptors.length; i++) {
if(descriptors[i].getId() != null)
devices.remove(descriptors[i].getId());
else
descriptors[i].setId(String.valueOf(random.nextInt(Integer.MAX_VALUE)));
put(descriptors[i].getId(), descriptors[i]);
theNames = theNames + " " + descriptors[i].getName() + ", ";
}
JsonTransformer aRenderer = new JsonTransformer();
String jsonValue = aRenderer.render(findAll());
repositoryWriter(jsonValue, repositoryPath);
log.debug("Save device: " + aDescriptor.getName());
log.debug("Save device(s): " + theNames);
}
public String delete(DeviceDescriptor aDescriptor) {

View File

@@ -15,7 +15,6 @@ import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
import com.bwssystems.HABridge.JsonTransformer;
import com.bwssystems.HABridge.dao.BackupFilename;
@@ -76,24 +75,31 @@ public class DeviceResource {
return "";
});
post(API_CONTEXT, "application/json", (request, response) -> {
log.debug("Create a Device - request body: " + request.body());
DeviceDescriptor device = new Gson().fromJson(request.body(), DeviceDescriptor.class);
if(device.getContentBody() != null ) {
if (device.getContentType() == null || device.getHttpVerb() == null || !supportedVerbs.contains(device.getHttpVerb().toLowerCase())) {
device = null;
response.status(HttpStatus.SC_BAD_REQUEST);
log.debug("Bad http verb in create a Device: " + request.body());
return device;
}
}
log.info("Create a Device(s) - request body: " + request.body());
DeviceDescriptor devices[];
if(request.body().substring(0,1).equalsIgnoreCase("[") == true) {
devices = new Gson().fromJson(request.body(), DeviceDescriptor[].class);
}
else {
devices = new Gson().fromJson("[" + request.body() + "]", DeviceDescriptor[].class);
}
for(int i = 0; i < devices.length; i++) {
if(devices[i].getContentBody() != null ) {
if (devices[i].getContentType() == null || devices[i].getHttpVerb() == null || !supportedVerbs.contains(devices[i].getHttpVerb().toLowerCase())) {
response.status(HttpStatus.SC_BAD_REQUEST);
log.debug("Bad http verb in create a Device(s): " + request.body());
return devices;
}
}
}
deviceRepository.save(device);
log.debug("Created a Device: " + request.body());
deviceRepository.save(devices);
log.debug("Created a Device(s): " + request.body());
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.status(HttpStatus.SC_CREATED);
return device;
return devices;
}, new JsonTransformer());
// http://ip_address:port/api/devices/:id CORS request
@@ -130,7 +136,9 @@ public class DeviceResource {
deviceEntry.setContentBody(device.getContentBody());
deviceEntry.setContentBodyOff(device.getContentBodyOff());
deviceRepository.save(deviceEntry);
DeviceDescriptor[] theDevices = new DeviceDescriptor[1];
theDevices[0] = deviceEntry;
deviceRepository.save(theDevices);
response.status(HttpStatus.SC_OK);
}
return deviceEntry;

View File

@@ -3,7 +3,8 @@ package com.bwssystems.HABridge.upnp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.BridgeControlDescriptor;
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
import com.bwssystems.HABridge.Configuration;
import java.io.IOException;
@@ -15,26 +16,21 @@ import org.apache.http.conn.util.*;
public class UpnpListener {
private Logger log = LoggerFactory.getLogger(UpnpListener.class);
private int upnpResponsePort;
private int httpServerPort;
private String responseAddress;
private boolean strict;
private boolean traceupnp;
private BridgeSettings bridgeSettings;
private BridgeControlDescriptor bridgeControl;
public UpnpListener(BridgeSettings theSettings) {
public UpnpListener(BridgeSettingsDescriptor theSettings, BridgeControlDescriptor theControl) {
super();
upnpResponsePort = Integer.valueOf(theSettings.getUpnpResponsePort());
httpServerPort = Integer.valueOf(theSettings.getServerPort());
responseAddress = theSettings.getUpnpConfigAddress();
strict = theSettings.isUpnpStrict();
traceupnp = theSettings.isTraceupnp();
bridgeSettings = theSettings;
bridgeControl = theControl;
}
public boolean startListening(){
@@ -80,7 +76,7 @@ public class UpnpListener {
if(isSSDPDiscovery(packet)){
sendUpnpResponse(responseSocket, packet.getAddress(), packet.getPort());
}
if(bridgeSettings.isReinit() || bridgeSettings.isStop()) {
if(bridgeControl.isReinit() || bridgeControl.isStop()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@@ -94,13 +90,13 @@ public class UpnpListener {
} catch (IOException e) {
log.error("UpnpListener encountered an error opening sockets. Shutting down", e);
}
if(bridgeSettings.isReinit())
if(bridgeControl.isReinit())
log.info("UPNP Discovery Listener - ended, restart found");
if(bridgeSettings.isStop())
if(bridgeControl.isStop())
log.info("UPNP Discovery Listener - ended, stop found");
if(!bridgeSettings.isStop()&& !bridgeSettings.isReinit())
if(!bridgeControl.isStop()&& !bridgeControl.isReinit())
log.info("UPNP Discovery Listener - ended, error found");
return bridgeSettings.isReinit();
return bridgeControl.isReinit();
}
/**

View File

@@ -29,7 +29,7 @@ public class NestHome {
nestItems = null;
if(!bridgeSettings.isValidNest()) {
log.info("not a valid nest");
log.debug("not a valid nest");
return;
}

View File

@@ -255,6 +255,20 @@ app.service('bridgeService', function ($http, $window, ngToast) {
return false;
};
this.bulkAddDevice = function (devices) {
this.state.error = "";
return $http.post(this.state.base, devices).then(
function (response) {
},
function (error) {
if (error.data) {
$window.alert("Bulk Add new Device Error: " + error.data.message);
}
self.state.error = "Bulk Add new Device Error: unknown";
}
);
};
this.addDevice = function (device) {
this.state.error = "";
if(device.httpVerb != null && device.httpVerb != "")
@@ -278,7 +292,6 @@ app.service('bridgeService', function ($http, $window, ngToast) {
contentBodyOff: device.contentBodyOff
}).then(
function (response) {
self.viewDevices();
},
function (error) {
if (error.data) {
@@ -304,7 +317,6 @@ app.service('bridgeService', function ($http, $window, ngToast) {
contentBodyOff: device.contentBodyOff
}).then(
function (response) {
self.viewDevices();
},
function (error) {
if (error.data) {
@@ -368,6 +380,22 @@ app.service('bridgeService', function ($http, $window, ngToast) {
);
};
this.saveSettings = function () {
this.state.error = "";
return $http.put(this.state.systemsbase + "/settings", this.state.settings).then(
function (response) {
self.viewConfigs();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Save Settings Error: unknown";
}
);
};
this.backupSettings = function (afilename) {
this.state.error = "";
return $http.put(this.state.systemsbase + "/backup/create", {
@@ -489,6 +517,9 @@ app.controller('SystemController', function ($scope, $location, $http, $window,
$scope.imgUrl = "glyphicon glyphicon-plus";
$scope.visibleBk = false;
$scope.imgBkUrl = "glyphicon glyphicon-plus";
$scope.saveSettings = function() {
bridgeService.saveSettings();
};
$scope.setBridgeUrl = function (url) {
bridgeService.state.base = url;
bridgeService.viewDevices();
@@ -578,7 +609,10 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
$scope.device_dim_control = "";
$scope.bulk = { devices: [] };
var veraList = angular.fromJson($scope.bridge.settings.veraaddress);
$scope.vera = {base: "http://" + veraList.devices[0].ip, port: "3480", id: ""};
if(veraList != null)
$scope.vera = {base: "http://" + veraList.devices[0].ip, port: "3480", id: ""};
else
$scope.vera = {base: "http://", port: "3480", id: ""};
bridgeService.viewVeraDevices();
bridgeService.viewVeraScenes();
bridgeService.viewHarmonyActivities();
@@ -823,14 +857,29 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
};
$scope.bulkAddDevices = function(dim_control) {
var devicesList = [];
for(var i = 0; i < $scope.bulk.devices.length; i++) {
for(var x = 0; x < bridgeService.state.veradevices.length; x++) {
if(bridgeService.state.veradevices[x].id == $scope.bulk.devices[i]) {
$scope.buildDeviceUrls(bridgeService.state.veradevices[x],dim_control);
$scope.addDevice();
devicesList[i] = {
name: $scope.device.name,
mapId: $scope.device.mapId,
mapType: $scope.device.mapType,
deviceType: $scope.device.deviceType,
targetDevice: $scope.device.targetDevice,
onUrl: $scope.device.onUrl,
offUrl: $scope.device.offUrl,
httpVerb: $scope.device.httpVerb,
contentType: $scope.device.contentType,
contentBody: $scope.device.contentBody,
contentBodyOff: $scope.device.contentBodyOff
};
}
}
}
bridgeService.bulkAddDevice(devicesList);
$scope.clearDevice();
$scope.bulk = { devices: [] };
};

View File

@@ -100,5 +100,4 @@
</tr>
</table>
</div>
</div>
</div>

View File

@@ -51,6 +51,14 @@
<th>Value</th>
</tr>
</thead>
<tr>
<td>config.file</td>
<td>{{bridge.settings.configfile}}</td>
</tr>
<tr>
<td>upnp.devices.db</td>
<td>{{bridge.settings.upnpdevicedb}}</td>
</tr>
<tr>
<td>upnp.config.address</td>
<td>{{bridge.settings.upnpconfigaddress}}</td>
@@ -59,21 +67,61 @@
<td>server.port</td>
<td>{{bridge.settings.serverport}}</td>
</tr>
<tr>
<td>upnp.devices.db</td>
<td>{{bridge.settings.upnpdevicedb}}</td>
</tr>
<tr>
<td>upnp.response.port</td>
<td>{{bridge.settings.upnpresponseport}}</td>
</tr>
<tr>
<td>vera.address</td>
<td>{{bridge.settings.veraaddress}}</td>
<td><table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>IP</th>
</tr>
</thead>
<tr ng-repeat="vera in bridge.settings.veraaddress.devices">
<td>{{vera.name}}</td>
<td>{{vera.ip}}</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>harmony.address</td>
<td>{{bridge.settings.harmonyaddress}}</td>
<td><table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>IP</th>
</tr>
</thead>
<tr ng-repeat="harmony in bridge.settings.harmonyaddress.devices">
<td>{{harmony.name}}</td>
<td>{{harmony.ip}}</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>harmony.user</td>
<td>{{bridge.settings.harmonyuser}}</td>
</tr>
<tr>
<td>harmony.pwd</td>
<td>{{bridge.settings.harmonypwd}}</td>
</tr>
<tr>
<td>button.sleep</td>
<td>{{bridge.settings.buttonsleep}} ms</td>
</tr>
<tr>
<td>nest.user</td>
<td>{{bridge.settings.nestuser}}</td>
</tr>
<tr>
<td>nest.pwd</td>
<td>{{bridge.settings.nestpwd}}</td>
</tr>
<tr>
<td>upnp.strict</td>
@@ -87,15 +135,11 @@
<td>dev.mode</td>
<td>{{bridge.settings.devmode}}</td>
</tr>
<tr>
<td>nest.configured</td>
<td>{{bridge.settings.nestconfigured}}</td>
</tr>
<tr>
<td>button.sleep</td>
<td>{{bridge.settings.buttonsleep}} ms</td>
</tr>
</table>
<p>
<button class="btn btn-success" type="submit"
ng-click="saveSettings()">Save</button>
</p>
</div>
</div>
<div class="panel panel-default backup">