continuation of requester filter code.

This commit is contained in:
Admin
2016-11-30 15:05:54 -06:00
parent 5746d271b1
commit 460931f6e0
8 changed files with 180 additions and 104 deletions

View File

@@ -1,18 +1,158 @@
package com.bwssystems.HABridge;
public class DeviceMapTypes {
public final static String CUSTOM_DEVICE = "custom";
public final static String VERA_DEVICE = "veraDevice";
public final static String VERA_SCENE = "veraScene";
public final static String HARMONY_ACTIVITY = "harmonyActivity";
public final static String HARMONY_BUTTON = "harmonyButton";
public final static String NEST_HOMEAWAY = "nestHomeAway";
public final static String NEST_THERMO_SET = "nestThermoSet";
public final static String HUE_DEVICE = "hueDevice";
public final static String HAL_DEVICE = "halDevice";
public final static String HAL_BUTTON = "halButton";
public final static String HAL_HOME = "halHome";
public final static String HAL_THERMO_SET = "halThermoSet";
public final static String MQTT_MESSAGE = "mqttMessage";
public final static String EXEC_DEVICE = "execDevice";
}
public final static String[] CUSTOM_DEVICE = { "custom", "Custom"};
public final static String[] VERA_DEVICE = { "veraDevice", "Vera Device"};
public final static String[] VERA_SCENE = { "veraScene", "Vera Scene"};
public final static String[] HARMONY_ACTIVITY = { "harmonyActivity", "Harmony Activity"};
public final static String[] HARMONY_BUTTON = { "harmonyButton", "Harmony Button"};
public final static String[] NEST_HOMEAWAY = { "nestHomeAway", "Nest Home Status"};
public final static String[] NEST_THERMO_SET = { "nestThermoSet", "Nest Thermostat"};
public final static String[] HUE_DEVICE = { "hueDevice", "Hue Device"};
public final static String[] HAL_DEVICE = { "halDevice", "HAL Device"};
public final static String[] HAL_BUTTON = { "halButton", "HAL Button"};
public final static String[] HAL_HOME = { "halHome", "HAL Home Status"};
public final static String[] HAL_THERMO_SET = { "halThermoSet", "HAL Thermostat"};
public final static String[] MQTT_MESSAGE = { "mqttMessage", "MQTT Message"};
public final static String[] EXEC_DEVICE = { "execDevice", "Execute Script/Program"};
public final static int typeIndex = 0;
public final static int displayIndex = 1;
public String[] customDevice;
public String[] veraDevice;
public String[] veraScene;
public String[] harmonyActivity;
public String[] harmonyButton;
public String[] nestHomeAway;
public String[] nestThermoSet;
public String[] hueDevice;
public String[] halDevice;
public String[] halButton;
public String[] halHome;
public String[] halThermoSet;
public String[] mqttMessage;
public String[] execDevice;
public int typeindex;
public int displayindex;
public DeviceMapTypes() {
super();
this.setCustomDevice(CUSTOM_DEVICE);
this.setDisplayindex(displayIndex);
this.setExecDevice(EXEC_DEVICE);
this.setHalButton(HAL_BUTTON);
this.setHalDevice(HAL_DEVICE);
this.setHalHome(HAL_HOME);
this.setHalThermoSet(HAL_THERMO_SET);
this.setHarmonyActivity(HARMONY_ACTIVITY);
this.setHarmonyButton(HARMONY_BUTTON);
this.setHueDevice(HUE_DEVICE);
this.setMqttMessage(MQTT_MESSAGE);
this.setNestHomeAway(NEST_HOMEAWAY);
this.setNestThermoSet(NEST_THERMO_SET);
this.setTypeindex(typeIndex);
this.setVeraDevice(VERA_DEVICE);
this.setVeraScene(VERA_SCENE);
}
public String[] getCustomDevice() {
return customDevice;
}
public void setCustomDevice(String[] customDevice) {
this.customDevice = customDevice;
}
public String[] getVeraDevice() {
return veraDevice;
}
public void setVeraDevice(String[] veraDevice) {
this.veraDevice = veraDevice;
}
public String[] getVeraScene() {
return veraScene;
}
public void setVeraScene(String[] veraScene) {
this.veraScene = veraScene;
}
public String[] getHarmonyActivity() {
return harmonyActivity;
}
public void setHarmonyActivity(String[] harmonyActivity) {
this.harmonyActivity = harmonyActivity;
}
public String[] getHarmonyButton() {
return harmonyButton;
}
public void setHarmonyButton(String[] harmonyButton) {
this.harmonyButton = harmonyButton;
}
public String[] getNestHomeAway() {
return nestHomeAway;
}
public void setNestHomeAway(String[] nestHomeAway) {
this.nestHomeAway = nestHomeAway;
}
public String[] getNestThermoSet() {
return nestThermoSet;
}
public void setNestThermoSet(String[] nestThermoSet) {
this.nestThermoSet = nestThermoSet;
}
public String[] getHueDevice() {
return hueDevice;
}
public void setHueDevice(String[] hueDevice) {
this.hueDevice = hueDevice;
}
public String[] getHalDevice() {
return halDevice;
}
public void setHalDevice(String[] halDevice) {
this.halDevice = halDevice;
}
public String[] getHalButton() {
return halButton;
}
public void setHalButton(String[] halButton) {
this.halButton = halButton;
}
public String[] getHalHome() {
return halHome;
}
public void setHalHome(String[] halHome) {
this.halHome = halHome;
}
public String[] getHalThermoSet() {
return halThermoSet;
}
public void setHalThermoSet(String[] halThermoSet) {
this.halThermoSet = halThermoSet;
}
public String[] getMqttMessage() {
return mqttMessage;
}
public void setMqttMessage(String[] mqttMessage) {
this.mqttMessage = mqttMessage;
}
public String[] getExecDevice() {
return execDevice;
}
public void setExecDevice(String[] execDevice) {
this.execDevice = execDevice;
}
public int getTypeindex() {
return typeindex;
}
public void setTypeindex(int typeindex) {
this.typeindex = typeindex;
}
public int getDisplayindex() {
return displayindex;
}
public void setDisplayindex(int displayindex) {
this.displayindex = displayindex;
}
}

View File

@@ -5,7 +5,7 @@ public class CallItem {
private Integer count;
private Integer delay;
private String type;
private String requesterAddress;
private String filterIPs;
public String getType() {
return type;
@@ -15,12 +15,12 @@ public class CallItem {
this.type = type;
}
public String getRequesterAddress() {
return requesterAddress;
public String getFilterIPs() {
return filterIPs;
}
public void setRequesterAddress(String requesterAddress) {
this.requesterAddress = requesterAddress;
public void setFilterIPs(String filterIPs) {
this.filterIPs = filterIPs;
}
public String getItem() {

View File

@@ -56,9 +56,6 @@ public class DeviceDescriptor{
@SerializedName("contentBodyDim")
@Expose
private String contentBodyDim;
@SerializedName("requesterAddress")
@Expose
private String requesterAddress;
private DeviceState deviceState;
@@ -190,14 +187,6 @@ public class DeviceDescriptor{
this.contentBodyDim = contentBodyDim;
}
public String getRequesterAddress() {
return requesterAddress;
}
public void setRequesterAddress(String requesterAddress) {
this.requesterAddress = requesterAddress;
}
public DeviceState getDeviceState() {
if(deviceState == null)
deviceState = DeviceState.createDeviceState();

View File

@@ -73,48 +73,7 @@ public class DeviceRepository extends BackupHandler {
List<DeviceDescriptor> list = new ArrayList<DeviceDescriptor>(devices.values());
return list;
}
/*
public List<DeviceDescriptor> findAllByRequester(String anAddress) {
List<DeviceDescriptor> list = new ArrayList<DeviceDescriptor>(devices.values());
List<DeviceDescriptor> theReturnList = new ArrayList<DeviceDescriptor>();
Iterator<DeviceDescriptor> anIterator = list.iterator();
DeviceDescriptor theDevice;
String theRequesterAddress;
while(anIterator.hasNext()) {
theDevice = anIterator.next();
theRequesterAddress = theDevice.getRequesterAddress();
if(theRequesterAddress == null || theRequesterAddress.length() == 0 || theRequesterAddress.contains(anAddress))
theReturnList.add(theDevice);
}
return theReturnList;
}
*/
public List<DeviceDescriptor> findAllByRequester(String anAddress) {
List<DeviceDescriptor> list = new ArrayList<DeviceDescriptor>(devices.values());
List<DeviceDescriptor> theReturnList = new ArrayList<DeviceDescriptor>();
Iterator<DeviceDescriptor> anIterator = list.iterator();
DeviceDescriptor theDevice;
String theRequesterAddress;
HashMap<String,String > addressMap;
while (anIterator.hasNext()) {
theDevice = anIterator.next();
theRequesterAddress = theDevice.getRequesterAddress();
addressMap = new HashMap<String, String>();
if(theRequesterAddress != null) {
if (theRequesterAddress.contains(",")) {
String[] theArray = theRequesterAddress.split(",");
for (String v : theArray) {
addressMap.put(v.trim(), v.trim());
}
} else
addressMap.put(theRequesterAddress, theRequesterAddress);
}
if (theRequesterAddress == null || theRequesterAddress.length() == 0 || addressMap.containsKey(anAddress))
theReturnList.add(theDevice);
}
return theReturnList;
}
public DeviceDescriptor findOne(String id) {
return devices.get(id);
}

View File

@@ -16,6 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
import com.bwssystems.HABridge.DeviceMapTypes;
import com.bwssystems.HABridge.dao.BackupFilename;
import com.bwssystems.HABridge.dao.DeviceDescriptor;
import com.bwssystems.HABridge.dao.DeviceRepository;
@@ -297,6 +298,11 @@ public class DeviceResource {
return mqttHome.getBrokers();
}, new JsonTransformer());
get (API_CONTEXT + "/map/types", "application/json", (request, response) -> {
log.debug("Get map types");
return new DeviceMapTypes();
}, new JsonTransformer());
// http://ip_address:port/api/devices/exec/renumber CORS request
options(API_CONTEXT + "/exec/renumber", "application/json", (request, response) -> {
response.status(HttpStatus.SC_OK);

View File

@@ -191,7 +191,7 @@ public class HueMulator implements HueErrorStringSet {
if (groupId.equalsIgnoreCase("0")) {
GroupResponse theResponse = GroupResponse
.createGroupResponse(repository.findAllByRequester(request.ip()));
.createGroupResponse(repository.findAll());
return new Gson().toJson(theResponse, GroupResponse.class);
}
@@ -301,7 +301,7 @@ public class HueMulator implements HueErrorStringSet {
return theErrorResp.getTheErrors();
}
List<DeviceDescriptor> deviceList = repository.findAllByRequester(request.ip());
List<DeviceDescriptor> deviceList = repository.findAll();
Map<String, DeviceResponse> deviceResponseMap = new HashMap<>();
for (DeviceDescriptor device : deviceList) {
DeviceResponse deviceResponse = null;
@@ -480,7 +480,7 @@ public class HueMulator implements HueErrorStringSet {
return theErrorResp.getTheErrors();
}
List<DeviceDescriptor> descriptorList = repository.findAllByRequester(request.ip());
List<DeviceDescriptor> descriptorList = repository.findAll();
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(),
bridgeSettings.getWhitelist());
Map<String, DeviceResponse> deviceList = new HashMap<>();
@@ -752,7 +752,7 @@ public class HueMulator implements HueErrorStringSet {
}
// code for backwards compatibility
if(!(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE))) {
if(!(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) {
if(url == null)
url = device.getOnUrl();
}
@@ -777,8 +777,8 @@ public class HueMulator implements HueErrorStringSet {
}
Integer setCount = 1;
for (int i = 0; callItems != null && i < callItems.length; i++) {
if(!filterByRequester(callItems[i].getRequesterAddress(), request.ip())) {
log.debug("filter for requester address not present in list: " + callItems[i].getRequesterAddress() + " with request ip of: " + request.ip());
if(!filterByRequester(callItems[i].getFilterIPs(), request.ip())) {
log.debug("filter for requester address not present in list: " + callItems[i].getFilterIPs() + " with request ip of: " + request.ip());
continue;
}
if (callItems[i].getCount() != null && callItems[i].getCount() > 0)
@@ -792,10 +792,10 @@ public class HueMulator implements HueErrorStringSet {
else if(device.getDeviceType() != null || device.getDeviceType().length() > 0)
callItems[i].setType(device.getDeviceType());
else
callItems[i].setType(DeviceMapTypes.CUSTOM_DEVICE);
callItems[i].setType(DeviceMapTypes.CUSTOM_DEVICE[DeviceMapTypes.typeIndex]);
}
if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE)) {
if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
if (myHueHome != null) {
HueDeviceIdentifier deviceId = new Gson().fromJson(callItems[i].getItem(), HueDeviceIdentifier.class);
@@ -848,7 +848,7 @@ public class HueMulator implements HueErrorStringSet {
+ "\",\"description\": \"No HUE configured\", \"parameter\": \"/lights/" + lightId
+ "state\"}}]";
}
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_ACTIVITY)) {
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex])) {
log.debug("executing HUE api request to change activity to Harmony: " + url);
if (myHarmonyHome != null) {
RunActivity anActivity = new Gson().fromJson(url, RunActivity.class);
@@ -876,7 +876,7 @@ public class HueMulator implements HueErrorStringSet {
+ "\",\"description\": \"Should not get here, no harmony configured\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
}
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON)) {
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) {
log.debug("executing HUE api request to button press(es) to Harmony: " + url);
if (myHarmonyHome != null) {
if (url.substring(0, 1).equalsIgnoreCase("{")) {
@@ -934,7 +934,7 @@ public class HueMulator implements HueErrorStringSet {
+ lightId + "state\"}}]";
}
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_HOMEAWAY)) {
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex])) {
log.debug("executing HUE api request to set away for nest home: " + url);
if (theNest == null) {
log.warn("Should not get here, no Nest available");
@@ -945,7 +945,7 @@ public class HueMulator implements HueErrorStringSet {
NestInstruction homeAway = new Gson().fromJson(url, NestInstruction.class);
theNest.getHome(homeAway.getName()).setAway(homeAway.getAway());
}
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_THERMO_SET)) {
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_THERMO_SET[DeviceMapTypes.typeIndex])) {
log.debug("executing HUE api request to set thermostat for nest: " + url);
if (theNest == null) {
log.warn("Should not get here, no Nest available");
@@ -996,7 +996,7 @@ public class HueMulator implements HueErrorStringSet {
+ lightId + "state\"}}]";
}
}
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.MQTT_MESSAGE)) {
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.typeIndex])) {
log.debug("executing HUE api request to send message to MQTT broker: " + url);
if (mqttHome != null) {
MQTTMessage[] mqttMessages = new Gson().fromJson(url, MQTTMessage[].class);
@@ -1027,7 +1027,7 @@ public class HueMulator implements HueErrorStringSet {
+ lightId + "state\"}}]";
}
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.EXEC_DEVICE)) {
} else if (callItems[i].getType() != null && callItems[i].getType().trim().equalsIgnoreCase(DeviceMapTypes.EXEC_DEVICE[DeviceMapTypes.typeIndex])) {
log.debug("Exec Request called with url: " + url);
String intermediate;
if (callItems[i].getItem().contains("exec://"))

View File

@@ -116,14 +116,6 @@
ng-model="device.uniqueid" placeholder="AA:BB:CC:DD:EE:FF-XX" readonly>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-requester-addr">Requester Address (comma separated list) </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="evice-requester-addr"
ng-model="device.requesterAddress" placeholder="Only use if you want to restrict this device to a specific caller(s)">
</div>
</div>
<div ng-if="device.mapType" class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-map-id">Map
ID </label>

View File

@@ -130,16 +130,6 @@
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-requester-addr">Requester Address (comma separated list) </label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="evice-requester-addr"
ng-model="device.requesterAddress" placeholder="Only use if you want to restrict this device to a specific caller(s)">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On