From bb0ffeb570ec72963d27920e923e5d57d50e6c8d Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 17 Mar 2017 16:53:21 -0500 Subject: [PATCH] Added device data value passing, off state change for brigthness, hex intensity values, updatd ui to cgo back to device touched after edit/add. --- README.md | 10 +- pom.xml | 2 +- .../HABridge/dao/DeviceDescriptor.java | 33 +++++ .../HABridge/hue/BrightnessDecode.java | 125 ++++++++++++------ .../bwssystems/HABridge/hue/ColorDecode.java | 21 +++ .../HABridge/hue/DeviceDataDecode.java | 66 +++++++++ .../bwssystems/HABridge/hue/HueMulator.java | 10 +- .../bwssystems/HABridge/hue/TimeDecode.java | 26 ++-- .../HABridge/plugins/exec/CommandHome.java | 2 + .../HABridge/plugins/harmony/HarmonyHome.java | 3 + .../HABridge/plugins/http/HTTPHome.java | 5 +- .../HABridge/plugins/mqtt/MQTTHome.java | 2 + .../HABridge/plugins/tcp/TCPHome.java | 3 + .../HABridge/plugins/udp/UDPHome.java | 3 + src/main/resources/public/scripts/app.js | 35 ++++- .../resources/public/views/configuration.html | 6 +- .../resources/public/views/editdevice.html | 18 +++ .../color/test/ConvertCIEColorTestCase.java | 21 +++ 18 files changed, 326 insertions(+), 65 deletions(-) create mode 100644 src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java create mode 100644 src/main/java/com/bwssystems/HABridge/hue/DeviceDataDecode.java create mode 100644 src/test/java/com/bwssystems/color/test/ConvertCIEColorTestCase.java diff --git a/README.md b/README.md index 676f54b..f30b89a 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,7 @@ There is a new format for the on/dim/off URL areas. The new editor handles the i Here are the fields that can be put into the call item: Json Type | field name | What | Use ----------|------------|------|----- -String or JsonElement | item| This is the payload that will be called for devices | Required +String or JsonElement | item | This is the payload that will be called for devices | Required Integer | count | This is how many times this items will be executed | Optional Integer | delay | This is how long we will wait until the next call after | Optional String | type | This is the type of device we are executing | Required @@ -332,7 +332,7 @@ Headers can be added as well using a Json construct [{"name":"header type name", Another option that is detected by the bridge is to use UDP or TCP direct calls such as `udp://:/` to send a UDP request. TCP calls are handled the same way as `tcp://:/`. If your data for the UDP or TCP request is formatted as "0x00F009B9" lexical hex format, the bridge will convert the data into a binary stream to send. -You can also use the value replacement constructs within these statements. Such as using the expressions "${time.format(Java time format string)}" for inserting a date/time stamp, ${intensity.percent} for 0-100 or ${intensity.decimal_percent} for 0.00-1.00 or ${intensity.byte} for 0-255 for straight pass through of the value or items that require special calculated values using ${intensity.math()} i.e. "${intensity.math(X/4)}". See Value Passing Controls Below. +You can also use the value replacement constructs within these statements. Such as using the expressions "${time.format(Java time format string)}" for inserting a date/time stamp, ${intensity.percent} or ${intensity.percent.hex} for 0-100 or ${intensity.decimal_percent} for 0.00-1.00 or ${intensity.byte} or ${intensity.byte.hex} for 0-255 for straight pass through of the value or items that require special calculated values using ${intensity.math()} i.e. "${intensity.math(X/4)}" or "${intensity.math(X/4).hex}". See Value Passing Controls Below. Examples: ``` @@ -382,9 +382,13 @@ In the URL areas, the format of the execution is just providing what command lin [{"item":"/home/pi/scripts/dothisscript.sh","type":"cmdDevice"}] ``` #### Value Passing Controls -There are multiple replacement constructs available to be put into any of the calls except Harmony items, Net Items and HAL items. These constructs are: "${time.format(Java time format string)}", "${intensity.percent}", "${intensity.decimal_percent}", "${intensity.byte}" and "${intensity.math(using X in your calc)}". +There are multiple replacement constructs available to be put into any of the calls except Harmony items, Net Items and HAL items. These constructs are: "${time.format(Java time format string)}", "${intensity.percent}", "${intensity.percent.hex}", "${intensity.decimal_percent}", "${intensity.byte}", "${intensity.byte.hex}", "${intensity.math(using X in your calc)}" and "${intensity.math(using X in your calc).hex}". + You can control items that require special calculated values using ${intensity.math()} i.e. "${intensity.math(X/4)}". + For the items that want to have a date time put into the message, utilize ${time.format(yyyy-MM-ddTHH:mm:ssXXX)} where "yyyy-MM-ddTHH:mm:ssXXX" can be any format from the Java SimpleDateFormat documented here: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html + +Also, device data can be inserted into your payloads by the use of "${device.name}", "${device.id}", "${device.uniqueid}", "${device.targetDevice}", "${device.mapId}", "${device.mapType}" and "${device.deviceType}". These work just like the dimming value replacements. e.g. ``` [{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=10&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.math(X/4)}","type":"httpDevice"}] diff --git a/pom.xml b/pom.xml index ec33dd0..c147bbf 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 4.2.1d + 4.3.0 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java index 547b04e..c31b0d0 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java @@ -62,9 +62,18 @@ public class DeviceDescriptor{ @SerializedName("noState") @Expose private boolean noState; + @SerializedName("offState") + @Expose + private boolean offState; @SerializedName("requesterAddress") @Expose private String requesterAddress; + @SerializedName("description") + @Expose + private String description; + @SerializedName("comments") + @Expose + private String comments; private DeviceState deviceState; @@ -222,6 +231,14 @@ public class DeviceDescriptor{ this.noState = noState; } + public boolean isOffState() { + return offState; + } + + public void setOffState(boolean offState) { + this.offState = offState; + } + public String getRequesterAddress() { return requesterAddress; } @@ -230,6 +247,22 @@ public class DeviceDescriptor{ this.requesterAddress = requesterAddress; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getComments() { + return comments; + } + + public void setComments(String comments) { + this.comments = comments; + } + public boolean containsType(String aType) { if(aType == null) return false; diff --git a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java index ff6c186..f715ef8 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java @@ -17,6 +17,9 @@ public class BrightnessDecode { private static final String INTENSITY_MATH = "${intensity.math("; private static final String INTENSITY_MATH_VALUE = "X"; private static final String INTENSITY_MATH_CLOSE = ")}"; + private static final String INTENSITY_MATH_CLOSE_HEX = ").hex}"; + private static final String INTENSITY_PERCENT_HEX = "${intensity.percent.hex}"; + private static final String INTENSITY_BYTE_HEX = "${intensity.byte.hex}"; public static int calculateIntensity(int setIntensity, Integer targetBri, Integer targetBriInc) { if (targetBri != null) { @@ -45,50 +48,79 @@ public class BrightnessDecode { if (request == null) { return null; } - if (request.contains(INTENSITY_BYTE)) { - if (isHex) { - String hexValue = convertToHex(intensity); - request = request.replace(INTENSITY_BYTE, hexValue); - } else { - String intensityByte = String.valueOf(intensity); - request = request.replace(INTENSITY_BYTE, intensityByte); - } - } else if (request.contains(INTENSITY_PERCENT)) { - int percentBrightness = (int) Math.round(intensity / 255.0 * 100); - if (isHex) { - String hexValue = convertToHex(percentBrightness); - request = request.replace(INTENSITY_PERCENT, hexValue); - } else { - String intensityPercent = String.valueOf(percentBrightness); - request = request.replace(INTENSITY_PERCENT, intensityPercent); - } - } else if (request.contains(INTENSITY_DECIMAL_PERCENT)) { - float decimalBrightness = (float) (intensity / 255.0); - - String intensityPercent = String.format("%1.2f", decimalBrightness); - request = request.replace(INTENSITY_DECIMAL_PERCENT, intensityPercent); - } else if (request.contains(INTENSITY_MATH)) { - Map variables = new HashMap(); - String mathDescriptor = request.substring(request.indexOf(INTENSITY_MATH) + INTENSITY_MATH.length(), - request.indexOf(INTENSITY_MATH_CLOSE)); - variables.put(INTENSITY_MATH_VALUE, new BigDecimal(intensity)); - - try { + boolean notDone = true; + String replaceValue = null; + String replaceTarget = null; + int percentBrightness = (int) Math.round(intensity / 255.0 * 100); + float decimalBrightness = (float) (intensity / 255.0); + Map variables = new HashMap(); + String mathDescriptor = null; + + while(notDone) { + notDone = false; + if (request.contains(INTENSITY_BYTE)) { + if (isHex) { + replaceValue = convertToHex(intensity); + } else { + replaceValue = String.valueOf(intensity); + } + replaceTarget = INTENSITY_BYTE; + notDone = true; + } else if (request.contains(INTENSITY_BYTE_HEX)) { + replaceValue = convertToHex(intensity); + replaceTarget = INTENSITY_BYTE_HEX; + notDone = true; + } else if (request.contains(INTENSITY_PERCENT)) { + if (isHex) { + replaceValue = convertToHex(percentBrightness); + } else { + replaceValue = String.valueOf(percentBrightness); + } + replaceTarget = INTENSITY_PERCENT; + notDone = true; + } else if (request.contains(INTENSITY_PERCENT_HEX)) { + replaceValue = convertToHex(percentBrightness); + replaceTarget = INTENSITY_PERCENT_HEX; + notDone = true; + } else if (request.contains(INTENSITY_DECIMAL_PERCENT)) { + replaceValue = String.format("%1.2f", decimalBrightness); + replaceTarget = INTENSITY_DECIMAL_PERCENT; + notDone = true; + } else if (request.contains(INTENSITY_MATH_CLOSE)) { + mathDescriptor = request.substring(request.indexOf(INTENSITY_MATH) + INTENSITY_MATH.length(), + request.indexOf(INTENSITY_MATH_CLOSE)); + variables.put(INTENSITY_MATH_VALUE, new BigDecimal(intensity)); + log.debug("Math eval is: " + mathDescriptor + ", Where " + INTENSITY_MATH_VALUE + " is: " + String.valueOf(intensity)); - Expression exp = new Expression(mathDescriptor); - BigDecimal result = exp.eval(variables); - Integer endResult = Math.round(result.floatValue()); - if (isHex) { - String hexValue = convertToHex(endResult); - request = request.replace(INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE, hexValue); - } else { - request = request.replace(INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE, - endResult.toString()); + Integer endResult = calculateMath(variables, mathDescriptor); + if(endResult != null) { + if (isHex) { + replaceValue = convertToHex(endResult); + } else { + replaceValue = endResult.toString(); + } + replaceTarget = INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE; + notDone = true; + } + } else if (request.contains(INTENSITY_MATH_CLOSE_HEX)) { + mathDescriptor = request.substring(request.indexOf(INTENSITY_MATH) + INTENSITY_MATH.length(), + request.indexOf(INTENSITY_MATH_CLOSE_HEX)); + variables.put(INTENSITY_MATH_VALUE, new BigDecimal(intensity)); + + Integer endResult = calculateMath(variables, mathDescriptor); + if(endResult != null) { + if (isHex) { + replaceValue = convertToHex(endResult); + } else { + replaceValue = endResult.toString(); + } + replaceTarget = INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE_HEX; + notDone = true; } - } catch (Exception e) { - log.warn("Could not execute Math: " + mathDescriptor, e); } + if(notDone) + request = request.replace(replaceTarget, replaceValue); } return request; } @@ -108,4 +140,17 @@ public class BrightnessDecode { newBytes[1] = theBytes[0]; return new String(newBytes); } + + private static Integer calculateMath(Map variables, String mathDescriptor) { + Integer endResult = null; + try { + Expression exp = new Expression(mathDescriptor); + BigDecimal result = exp.eval(variables); + endResult = Math.round(result.floatValue()); + } catch (Exception e) { + log.warn("Could not execute Math: " + mathDescriptor, e); + endResult = null; + } + return endResult; + } } \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java new file mode 100644 index 0000000..1585d45 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java @@ -0,0 +1,21 @@ +package com.bwssystems.HABridge.hue; + +import java.util.List; + +public class ColorDecode { + + public static String convertCIEtoRGB(List xy) { + double x; + double y; + double Y; + + x = xy.get(0) * 100; + y = xy.get(1) * 100; + Y= y; + double R = 3.240479*((x*Y)/y) + -1.537150*Y + -0.498535*(((1-x-y)*Y)/y); + double G = -0.969256*((x*Y)/y) + 1.875992*Y + 0.041556*(((1-x-y)*Y)/y); + double B = 0.055648*((x*Y)/y) + -0.204043*Y + 1.057311*(((1-x-y)*Y)/y); + + return null; + } +} diff --git a/src/main/java/com/bwssystems/HABridge/hue/DeviceDataDecode.java b/src/main/java/com/bwssystems/HABridge/hue/DeviceDataDecode.java new file mode 100644 index 0000000..7997d15 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/hue/DeviceDataDecode.java @@ -0,0 +1,66 @@ +package com.bwssystems.HABridge.hue; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.bwssystems.HABridge.dao.DeviceDescriptor; + +public class DeviceDataDecode { + private static final Logger log = LoggerFactory.getLogger(DeviceDataDecode.class); + private static final String DEVICE_ID = "${device.id}"; + private static final String DEVICE_UNIQUEID = "${device.uniqueid}"; + private static final String DEVICE_NAME = "${device.name}"; + private static final String DEVICE_MAPID = "${device.mapId}"; + private static final String DEVICE_MAPTYPE = "${device.mapType}"; + private static final String DEVICE_DEVICETYPE = "${device.deviceType}"; + private static final String DEVICE_TARGETDEVICE = "${device.targetDevice}"; + + public static String replaceDeviceData(String request, DeviceDescriptor device) { + if (request == null) { + return null; + } + boolean notDone = true; + + while(notDone) { + notDone = false; + if (request.contains(DEVICE_ID)) { + request = request.replace(DEVICE_ID, device.getId()); + notDone = true; + } + + if (request.contains(DEVICE_UNIQUEID)) { + request = request.replace(DEVICE_UNIQUEID, device.getUniqueid()); + notDone = true; + } + + if (request.contains(DEVICE_NAME)) { + request = request.replace(DEVICE_NAME, device.getName()); + notDone = true; + } + + if (request.contains(DEVICE_MAPID)) { + request = request.replace(DEVICE_MAPID, device.getMapId()); + notDone = true; + } + + if (request.contains(DEVICE_MAPTYPE)) { + request = request.replace(DEVICE_MAPTYPE, device.getMapType()); + notDone = true; + } + + if (request.contains(DEVICE_DEVICETYPE)) { + request = request.replace(DEVICE_DEVICETYPE, device.getDeviceType()); + notDone = true; + } + + if (request.contains(DEVICE_TARGETDEVICE)) { + request = request.replace(DEVICE_TARGETDEVICE, device.getTargetDevice()); + notDone = true; + } + + log.debug("Request <<" + request + ">>, not done: " + notDone); + } + return request; + } + +} diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index fa1b439..bab604f 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -391,7 +391,7 @@ public class HueMulator { } private String formatSuccessHueResponse(StateChangeBody stateChanges, String body, String lightId, - DeviceState deviceState, Integer targetBri, Integer targetBriInc) { + DeviceState deviceState, Integer targetBri, Integer targetBriInc, boolean offState) { String responseString = "["; boolean notFirstChange = false; @@ -406,6 +406,8 @@ public class HueMulator { deviceState.setOn(stateChanges.isOn()); if(!deviceState.isOn() && deviceState.getBri() == 254) deviceState.setBri(0); + if(!deviceState.isOn() && offState) + deviceState.setBri(0); } notFirstChange = true; } @@ -824,7 +826,7 @@ public class HueMulator { if (state == null) state = DeviceState.createDeviceState(); - responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc); + responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc, device.isOffState()); device.setDeviceState(state); return responseString; @@ -964,11 +966,11 @@ public class HueMulator { if (responseString == null || !responseString.contains("[{\"error\":")) { if(!device.isNoState()) { - responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc); + responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc, device.isOffState()); device.setDeviceState(state); } else { DeviceState dummyState = DeviceState.createDeviceState(); - responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, dummyState, targetBri, targetBriInc); + responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, dummyState, targetBri, targetBriInc, device.isOffState()); } } return responseString; diff --git a/src/main/java/com/bwssystems/HABridge/hue/TimeDecode.java b/src/main/java/com/bwssystems/HABridge/hue/TimeDecode.java index 6d1c835..62343f7 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/TimeDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/TimeDecode.java @@ -21,16 +21,22 @@ public class TimeDecode { if (request == null) { return null; } - if (request.contains(TIME_FORMAT)) { - String timeFormatDescriptor = request.substring(request.indexOf(TIME_FORMAT) + TIME_FORMAT.length(), - request.indexOf(TIME_FORMAT_CLOSE)); - - try { - log.debug("Time eval is: " + timeFormatDescriptor); - SimpleDateFormat dateFormat = new SimpleDateFormat(timeFormatDescriptor); - request = request.replace(TIME_FORMAT + timeFormatDescriptor + TIME_FORMAT_CLOSE, dateFormat.format(new Date())); - } catch (Exception e) { - log.warn("Could not format current time: " + timeFormatDescriptor, e); + boolean notDone = true; + + while(notDone) { + notDone = false; + if (request.contains(TIME_FORMAT)) { + String timeFormatDescriptor = request.substring(request.indexOf(TIME_FORMAT) + TIME_FORMAT.length(), + request.indexOf(TIME_FORMAT_CLOSE)); + + try { + log.debug("Time eval is: " + timeFormatDescriptor); + SimpleDateFormat dateFormat = new SimpleDateFormat(timeFormatDescriptor); + request = request.replace(TIME_FORMAT + timeFormatDescriptor + TIME_FORMAT_CLOSE, dateFormat.format(new Date())); + notDone = true; + } catch (Exception e) { + log.warn("Could not format current time: " + timeFormatDescriptor, e); + } } } return request; diff --git a/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java b/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java index 0879188..2ddaf35 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java @@ -10,6 +10,7 @@ import com.bwssystems.HABridge.Home; import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.HABridge.hue.BrightnessDecode; +import com.bwssystems.HABridge.hue.DeviceDataDecode; import com.bwssystems.HABridge.hue.MultiCommandUtil; import com.bwssystems.HABridge.hue.TimeDecode; @@ -31,6 +32,7 @@ public class CommandHome implements Home { else intermediate = anItem.getItem().getAsString(); intermediate = BrightnessDecode.calculateReplaceIntensityValue(intermediate, itensity, targetBri, targetBriInc, false); + intermediate = DeviceDataDecode.replaceDeviceData(intermediate, device); intermediate = TimeDecode.replaceTimeValue(intermediate); String anError = doExecRequest(intermediate, lightId); if (anError != null) { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java b/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java index 5857f08..11d2c97 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java @@ -17,6 +17,7 @@ import com.bwssystems.HABridge.IpList; import com.bwssystems.HABridge.NamedIP; import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.dao.DeviceDescriptor; +import com.bwssystems.HABridge.hue.BrightnessDecode; import com.bwssystems.HABridge.hue.MultiCommandUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -161,6 +162,8 @@ public class HarmonyHome implements Home { if (url.substring(0, 1).equalsIgnoreCase("{")) { url = "[" + url + "]"; } + + url = BrightnessDecode.calculateReplaceIntensityValue(url, intensity, targetBri, targetBriInc, false); ButtonPress[] deviceButtons = aGsonHandler.fromJson(url, ButtonPress[].class); Integer theCount = 1; for(int z = 0; z < deviceButtons.length; z++) { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java index 985fd7e..6e52459 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java @@ -11,6 +11,7 @@ import com.bwssystems.HABridge.api.hue.HueError; import com.bwssystems.HABridge.api.hue.HueErrorResponse; import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.HABridge.hue.BrightnessDecode; +import com.bwssystems.HABridge.hue.DeviceDataDecode; import com.bwssystems.HABridge.hue.MultiCommandUtil; import com.bwssystems.HABridge.hue.TimeDecode; import com.google.gson.Gson; @@ -49,12 +50,14 @@ public class HTTPHome implements Home { String anUrl = BrightnessDecode.calculateReplaceIntensityValue(theUrl, intensity, targetBri, targetBriInc, false); - + anUrl = DeviceDataDecode.replaceDeviceData(anUrl, device); anUrl = TimeDecode.replaceTimeValue(anUrl); + String aBody = null; if(anItem.getHttpBody()!= null && !anItem.getHttpBody().isEmpty()) { aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(), intensity, targetBri, targetBriInc, false); + aBody = DeviceDataDecode.replaceDeviceData(aBody, device); aBody = TimeDecode.replaceTimeValue(aBody); } // make call diff --git a/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java b/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java index 79212c1..0b490aa 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java @@ -14,6 +14,7 @@ import com.bwssystems.HABridge.NamedIP; import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.HABridge.hue.BrightnessDecode; +import com.bwssystems.HABridge.hue.DeviceDataDecode; import com.bwssystems.HABridge.hue.MultiCommandUtil; import com.bwssystems.HABridge.hue.TimeDecode; import com.google.gson.Gson; @@ -89,6 +90,7 @@ public class MQTTHome implements Home { mqttObject =anItem.getItem().getAsString(); mqttObject = BrightnessDecode.calculateReplaceIntensityValue(mqttObject, intensity, targetBri, targetBriInc, false); + mqttObject = DeviceDataDecode.replaceDeviceData(mqttObject, device); mqttObject = TimeDecode.replaceTimeValue(mqttObject); if (mqttObject.substring(0, 1).equalsIgnoreCase("{")) mqttObject = "[" + mqttObject + "]"; diff --git a/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java index 53cb664..d359e96 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java @@ -20,6 +20,7 @@ import com.bwssystems.HABridge.Home; import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.HABridge.hue.BrightnessDecode; +import com.bwssystems.HABridge.hue.DeviceDataDecode; import com.bwssystems.HABridge.hue.MultiCommandUtil; import com.bwssystems.HABridge.hue.TimeDecode; @@ -71,9 +72,11 @@ public class TCPHome implements Home { theUrlBody = TimeDecode.replaceTimeValue(theUrlBody); if (theUrlBody.startsWith("0x")) { theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, true); + theUrlBody = DeviceDataDecode.replaceDeviceData(theUrlBody, device); sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); } else { theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, false); + theUrlBody = DeviceDataDecode.replaceDeviceData(theUrlBody, device); theUrlBody = StringEscapeUtils.unescapeJava(theUrlBody); sendData = theUrlBody.getBytes(); } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java index 1244bff..3d49881 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java @@ -15,6 +15,7 @@ import com.bwssystems.HABridge.Home; import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.HABridge.hue.BrightnessDecode; +import com.bwssystems.HABridge.hue.DeviceDataDecode; import com.bwssystems.HABridge.hue.MultiCommandUtil; import com.bwssystems.HABridge.hue.TimeDecode; import com.bwssystems.HABridge.util.UDPDatagramSender; @@ -57,9 +58,11 @@ public class UDPHome implements Home { theUrlBody = TimeDecode.replaceTimeValue(theUrlBody); if (theUrlBody.startsWith("0x")) { theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, true); + theUrlBody = DeviceDataDecode.replaceDeviceData(theUrlBody, device); sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2)); } else { theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, false); + theUrlBody = DeviceDataDecode.replaceDeviceData(theUrlBody, device); theUrlBody = StringEscapeUtils.unescapeJava(theUrlBody); sendData = theUrlBody.getBytes(); } diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 7817014..f01e6ee 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -80,7 +80,7 @@ String.prototype.replaceAll = function (search, replace) app.service ('bridgeService', function ($http, $window, ngToast) { var self = this; - this.state = {base: "./api/devices", bridgelocation: ".", systemsbase: "./system", huebase: "./api", configs: [], backups: [], devices: [], device: {}, mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], mapTypes: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, showDomoticz: false, showSomfy: false, showLifx: false, habridgeversion: "", viewDevId: ""}; + this.state = {base: "./api/devices", bridgelocation: ".", systemsbase: "./system", huebase: "./api", configs: [], backups: [], devices: [], device: {}, mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], mapTypes: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, showDomoticz: false, showSomfy: false, showLifx: false, habridgeversion: "", viewDevId: "", queueDevId: ""}; this.displayWarn = function(errorTitle, error) { var toastContent = errorTitle; @@ -1166,6 +1166,26 @@ app.controller('LogsController', function ($scope, $location, $http, $window, br }; }); +app.directive('postrenderAction', postrenderAction); +/* @ngInject */ +function postrenderAction($timeout) { + // ### Directive Interface + // Defines base properties for the directive. + var directive = { + restrict: 'A', + priority: 101, + link: link + }; + return directive; + + // ### Link Function + // Provides functionality for the directive during the DOM building/data binding stage. + function link(scope, element, attrs) { + $timeout(function() { + scope.$evalAsync(attrs.postrenderAction); + }, 0); + } +} app.controller('ViewingController', function ($scope, $location, $http, $window, bridgeService, ngDialog) { bridgeService.viewDevices(); @@ -1232,9 +1252,14 @@ app.controller('ViewingController', function ($scope, $location, $http, $window, $scope.imgBkUrl = "glyphicon glyphicon-plus"; }; - $scope.$watch('bridge.devices', function(devId) { - $scope.$broadcast("rowSelected", bridgeService.state.viewDevId); - }); + $scope.goToRow = function() { + if (bridgeService.state.queueDevId !== null && bridgeService.state.queueDevId !== "") { + bridgeService.state.viewDevId = bridgeService.state.queueDevId; + $scope.$broadcast("rowSelected", bridgeService.state.viewDevId); + console.log("Go to Row selected Id <<" + bridgeService.state.viewDevId + ">>") + bridgeService.state.queueDevId = null; + } + }; }); app.controller('ValueDialogCtrl', function ($scope, bridgeService, ngDialog) { @@ -2669,6 +2694,8 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi bridgeService.addDevice($scope.device).then( function () { + bridgeService.state.queueDevId = $scope.device.id; + console.log("Device updated for Q Id <<" + bridgeService.state.queueDevId + ">>") $scope.clearDevice(); $location.path('/'); }, diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index 9ebf4df..3cb3123 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -24,7 +24,7 @@
  • LIFX Devices
  • Add/Edit
  • - +

    Current devices ({{bridge.devices.length}})

    @@ -34,7 +34,6 @@

    - @@ -42,6 +41,7 @@ + @@ -53,6 +53,7 @@ + @@ -76,6 +77,7 @@ +

    diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 759b10b..ae1439d 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -65,6 +65,18 @@

    + + + + + + + + + + + + + +
    Row ID NameDescription Type Target Inactive{{$index+1}} {{device.id}} {{device.name}}{{device.description}} {{device.deviceType}} {{device.targetDevice}} {{device.inactive}}
    {{device.noState}}
    {{device.offState}}
    xy = new ArrayList(Arrays.asList(new Double(0.3972), new Double(0.4564))); + + String colorDecode = ColorDecode.convertCIEtoRGB(xy); + Assert.assertEquals(colorDecode, null); + } + +}