Implement devimal percent for no locale, add HAL https and debugging for

link buttton usage.
This commit is contained in:
Admin
2017-05-19 15:45:56 -05:00
parent 19256e4eaa
commit 62b896ee07
10 changed files with 83 additions and 37 deletions

View File

@@ -212,26 +212,26 @@ public class BridgeSecurity {
Iterator<String> userIterator = theUserIds.iterator();
while (userIterator.hasNext()) {
validUser = userIterator.next();
if (validUser.equals(aUser))
if (validUser.equals(aUser)) {
found = true;
log.debug("validateWhitelistUser: found a user <" + aUser + ">");
}
}
}
}
if(!found && !strict) {
log.debug("validateWhitelistUser: a user was not found and it is not strict rules <" + aUser + "> being created");
newWhitelistUser(aUser, userDescription);
found = true;
}
if (!found) {
return HueErrorResponse.createResponse("1", "/api/" + aUser, "unauthorized user", null, null, null).getTheErrors();
log.debug("validateWhitelistUser: a user was not found and it is strict rules <" + aUser + ">");
return HueErrorResponse.createResponse("1", "/api/" + aUser == null ? "" : aUser, "unauthorized user", null, null, null).getTheErrors();
}
Object anUser = securityDescriptor.getWhitelist().remove(DEPRACATED_INTERNAL_USER);
if(anUser != null)
setSettingsChanged(true);
return null;
}

View File

@@ -49,6 +49,7 @@ public class HABridge {
staticFileLocation("/public");
while(!bridgeSettings.getBridgeControl().isStop()) {
bridgeSettings.buildSettings();
bridgeSettings.getBridgeSecurity().removeTestUsers();
log.info("HA Bridge initializing....");
// sparkjava config directive to set ip address for the web server to listen on
ipAddress(bridgeSettings.getBridgeSettingsDescriptor().getWebaddress());

View File

@@ -2,6 +2,7 @@ package com.bwssystems.HABridge.hue;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang3.Conversion;
@@ -83,7 +84,7 @@ public class BrightnessDecode {
replaceTarget = INTENSITY_PERCENT_HEX;
notDone = true;
} else if (request.contains(INTENSITY_DECIMAL_PERCENT)) {
replaceValue = String.format("%1.2f", decimalBrightness);
replaceValue = String.format(Locale.ROOT, "%1.2f", decimalBrightness);
replaceTarget = INTENSITY_DECIMAL_PERCENT;
notDone = true;
} else if (request.contains(INTENSITY_MATH_CLOSE)) {

View File

@@ -69,6 +69,7 @@ public class HueMulator {
public void setupServer() {
log.info("Hue emulator service started....");
before(HUE_CONTEXT + "/*", (request, response) -> {
log.debug("HueMulator GET called on api/* with request <" + request.pathInfo() + ">");
if(bridgeSettingMaster.getBridgeSecurity().isSecure()) {
String pathInfo = request.pathInfo();
if(pathInfo != null && pathInfo.contains(HUE_CONTEXT + "/devices")) {

View File

@@ -5,6 +5,7 @@ public class HalDevice {
private String haldevicename;
private String haladdress;
private String halname;
private Boolean secure;
private DeviceElements buttons;
public String getHaldevicetype() {
return haldevicetype;
@@ -30,6 +31,12 @@ public class HalDevice {
public void setHalname(String halname) {
this.halname = halname;
}
public Boolean getSecure() {
return secure;
}
public void setSecure(Boolean secure) {
this.secure = secure;
}
public DeviceElements getButtons() {
return buttons;
}

View File

@@ -13,7 +13,6 @@ import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.Home;
import com.bwssystems.HABridge.NamedIP;
import com.bwssystems.HABridge.api.CallItem;
import com.bwssystems.HABridge.api.NameValue;
import com.bwssystems.HABridge.api.hue.HueError;
import com.bwssystems.HABridge.api.hue.HueErrorResponse;
import com.bwssystems.HABridge.dao.DeviceDescriptor;

View File

@@ -8,8 +8,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.NamedIP;
import com.bwssystems.HABridge.api.hue.HueError;
import com.bwssystems.HABridge.api.hue.HueErrorResponse;
import com.bwssystems.HABridge.plugins.http.HTTPHandler;
import com.bwssystems.HABridge.util.TextStringFormatter;
import com.google.gson.Gson;
@@ -100,7 +98,11 @@ public class HalInfo {
String theUrl = null;
String theData;
theUrl = "http://" + halAddress.getIp() + apiType + theToken;
if(halAddress.getSecure())
theUrl = "https://";
else
theUrl = "http://";
theUrl = theUrl + halAddress.getIp() + apiType + theToken;
theData = httpClient.doHttpRequest(theUrl, null, null, null, null);
if(theData != null) {
log.debug("GET " + deviceType + " HalApiResponse - data: " + theData);
@@ -125,6 +127,7 @@ public class HalInfo {
aNewHalDevice.setHaldevicename(theDevice.getDeviceName());
aNewHalDevice.setHaladdress(halAddress.getIp());
aNewHalDevice.setHalname(halAddress.getName());
aNewHalDevice.setSecure(halAddress.getSecure());
deviceList.add(aNewHalDevice);
}
@@ -147,7 +150,11 @@ public class HalInfo {
deviceList = new ArrayList<HalDevice>();
while (theHalDevices.hasNext()) {
HalDevice theHalDevice = theHalDevices.next();
theUrl = "http://" + halAddress.getIp() + IRBUTTON_REQUEST + TextStringFormatter.forQuerySpaceUrl(theHalDevice.getHaldevicename()) + TOKEN_REQUEST + theToken;
if(halAddress.getSecure())
theUrl = "https://";
else
theUrl = "http://";
theUrl = theUrl + halAddress.getIp() + IRBUTTON_REQUEST + TextStringFormatter.forQuerySpaceUrl(theHalDevice.getHaldevicename()) + TOKEN_REQUEST + theToken;
theData = httpClient.doHttpRequest(theUrl, null, null, null, null);
if (theData != null) {
log.debug("GET IrData for IR Device " + theHalDevice.getHaldevicename() + " HalApiResponse - data: " + theData);