From ce79fb4b825c17d12a0cb880afbaf99e70f60535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20F=C3=B6rderreuther?= Date: Wed, 2 Aug 2017 07:34:06 +0200 Subject: [PATCH] Light type detection and filter for device list "Extended color light" isn't used anymore for all devices without thinking about it. It will now automatically differentiate between Color and Dimmable light by the following logic: 1. If it's Philips Hue passthru look at the state: if it contains the attribute "colormode" it's a Extended color light, otherwise it's a Dimmable light. 2. If it's no passthru it's a dimmable light if the colorUrl has no content. I didn't use On/Off light because i disovered that a) the hue app treats these exactly the same as dimmable light, you can still "change the brightness" and b) the amazon echo doesn't find these lights without the skill I also enhanced the filter options in the web ui. You have a textbox "Show devices visible to". You can fill in an ip-address and there will only be devices displayed that a) have the ip address in the requesterFilter or b) don't filter by requester. If you tick the checkbox "Must contain filter" option b isn't used. This means also if you check the box with no ip address in the textbox only devices without request filter will be shown. Also there is a filter by device type. All these 3 filter options will be remembered as long as the browser tab is closed. --- .../HABridge/api/hue/DeviceResponse.java | 23 ++++------- .../HABridge/api/hue/DeviceState.java | 41 +++++++++++-------- .../HABridge/api/hue/GroupResponse.java | 2 +- .../HABridge/dao/DeviceDescriptor.java | 14 ++++++- .../HABridge/dao/GroupDescriptor.java | 2 +- .../bwssystems/HABridge/hue/HueMulator.java | 8 ++-- src/main/resources/public/scripts/app.js | 33 +++++++++++++-- .../resources/public/views/configuration.html | 21 +++++++++- 8 files changed, 100 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java index 99c61bd..2366276 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java @@ -105,26 +105,19 @@ public class DeviceResponse { response.setName(device.getName()); response.setUniqueid(device.getUniqueid()); - //if (device.getColorUrl() == null || device.getColorUrl().trim().equals("")) { - // if (device.getDimUrl() == null || device.getDimUrl().trim().equals("")) { - // response.setType("On/Off light"); - // response.setModelid("Plug - LIGHTIFY"); - // response.setManufacturername("OSRAM"); - // response.setSwversion("V1.04.12"); - // } else { - // response.setManufacturername("Philips"); - // response.setType("Dimmable light"); - // response.setModelid("LWB007"); - // response.setSwversion("66012040"); - // } - //} else { - response.setManufacturername("Philips"); + response.setManufacturername("Philips"); + + if (device.isColorDevice()) { response.setType("Extended color light"); response.setModelid("LCT010"); response.setSwversion("1.15.2_r19181"); response.setSwconfigid("F921C859"); response.setProductid("Philips-LCT010-1-A19ECLv4"); - //} + } else { + response.setType("Dimmable light"); + response.setModelid("LWB007"); + response.setSwversion("66012040"); + } response.setLuminaireuniqueid(null); diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java index c3bcbac..4ff008b 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/DeviceState.java @@ -9,11 +9,11 @@ import java.util.List; public class DeviceState { private boolean on; private int bri; - private int hue; - private int sat; + private Integer hue; + private Integer sat; private String effect; private List xy; - private int ct; + private Integer ct; private String alert; private String colormode; private boolean reachable; @@ -37,7 +37,7 @@ public class DeviceState { } public int getHue() { - return hue; + return hue != null ? hue.intValue() : 0; } public void setHue(int hue) { @@ -46,7 +46,7 @@ public class DeviceState { } public int getSat() { - return sat; + return sat != null ? sat.intValue() : 0; } public void setSat(int sat) { @@ -63,7 +63,7 @@ public class DeviceState { } public int getCt() { - return ct; + return ct != null ? ct.intValue() : 0; } public void setCt(int ct) { @@ -111,23 +111,28 @@ public class DeviceState { // this.transitiontime = transitiontime; // } - public static DeviceState createDeviceState() { + public static DeviceState createDeviceState(boolean color) { DeviceState newDeviceState = new DeviceState(); - newDeviceState.fillIn(); - newDeviceState.setColormode("ct"); - newDeviceState.setCt(200); - ArrayList doubleArray = new ArrayList(); - doubleArray.add(new Double(0)); - doubleArray.add(new Double(0)); - newDeviceState.setXy(doubleArray); - + newDeviceState.fillIn(color); + if (color) { + newDeviceState.setColormode("xy"); + newDeviceState.setHue(0); + newDeviceState.setSat(0); + newDeviceState.setCt(153); + ArrayList doubleArray = new ArrayList(); + doubleArray.add(0.3146); + doubleArray.add(0.3303); + newDeviceState.setXy(doubleArray); + } return newDeviceState; } - public void fillIn() { + public void fillIn(boolean color) { if(this.getAlert() == null) this.setAlert("none"); - if(this.getEffect() == null) - this.setEffect("none"); + if (color) { + if(this.getEffect() == null) + this.setEffect("none"); + } this.setReachable(true); } @Override diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/GroupResponse.java b/src/main/java/com/bwssystems/HABridge/api/hue/GroupResponse.java index 573f517..c44b0b0 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/GroupResponse.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/GroupResponse.java @@ -82,7 +82,7 @@ public class GroupResponse { i++; } GroupResponse theResponse = new GroupResponse(); - theResponse.setAction(DeviceState.createDeviceState()); + theResponse.setAction(DeviceState.createDeviceState(true)); theResponse.setState(new GroupState(all_on, any_on)); theResponse.setName("Group 0"); theResponse.setLights(theList); diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java index 26bfdec..1d2b4ee 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java @@ -219,7 +219,7 @@ public class DeviceDescriptor{ public DeviceState getDeviceState() { if(deviceState == null) - deviceState = DeviceState.createDeviceState(); + deviceState = DeviceState.createDeviceState(this.isColorDevice()); return deviceState; } @@ -299,4 +299,16 @@ public class DeviceDescriptor{ return false; } + + public boolean isColorDevice() { + boolean color = true; + if ((deviceType == null || !deviceType.trim().equals("passthru")) && (colorUrl == null || colorUrl.trim().equals(""))) { + color = false; + } else if (deviceType != null && deviceType.trim().equals("passthru")) { + if (deviceState != null && (deviceState.getColormode() == null || deviceState.getColormode().equals(""))) { + color = false; + } + } + return color; + } } \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/dao/GroupDescriptor.java b/src/main/java/com/bwssystems/HABridge/dao/GroupDescriptor.java index 2c134e5..013b89d 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/GroupDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/dao/GroupDescriptor.java @@ -90,7 +90,7 @@ public class GroupDescriptor{ public DeviceState getAction() { if(action == null) - action = DeviceState.createDeviceState(); + action = DeviceState.createDeviceState(true); return action; } diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 1633fc0..c5c7c75 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -1073,7 +1073,7 @@ public class HueMulator { state = device.getDeviceState(); if (state == null) - state = DeviceState.createDeviceState(); + state = DeviceState.createDeviceState(device.isColorDevice()); responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc, device.isOffState()); device.setDeviceState(state); @@ -1127,7 +1127,7 @@ public class HueMulator { state = device.getDeviceState(); if (state == null) { - state = DeviceState.createDeviceState(); + state = DeviceState.createDeviceState(device.isColorDevice()); device.setDeviceState(state); } @@ -1248,7 +1248,7 @@ public class HueMulator { responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc, device.isOffState()); device.setDeviceState(state); } else { - DeviceState dummyState = DeviceState.createDeviceState(); + DeviceState dummyState = DeviceState.createDeviceState(device.isColorDevice()); responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, dummyState, targetBri, targetBriInc, device.isOffState()); } } @@ -1309,7 +1309,7 @@ public class HueMulator { state = group.getAction(); if (state == null) { - state = DeviceState.createDeviceState(); + state = DeviceState.createDeviceState(true); group.setAction(state); } } diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 6c4de53..e1a8839 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -134,7 +134,8 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n 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: "", securityInfo: {}, filterDevicesByIpAddress: null}; + showDomoticz: false, showSomfy: false, showLifx: false, habridgeversion: {}, viewDevId: "", queueDevId: "", securityInfo: {}, filterDevicesByIpAddress: null, + filterDevicesOnlyFiltered: false, filterDeviceType: null}; this.displayWarn = function(errorTitle, error) { var toastContent = errorTitle; @@ -3463,13 +3464,39 @@ app.filter('configuredSomfyDevices', function (bridgeService) { }); app.filter('filterDevicesByRequester', function () { - return function(input,search) { + return function(input,search,mustContain,deviceType) { var out = []; if(input === undefined || input === null || input.length === undefined) return out; var pattern = new RegExp(search); + var patternType = new RegExp(deviceType); for (var i = 0; i < input.length; i++) { - if(pattern.test(input[i].requesterAddress) || !input[i].requesterAddress || input[i].requesterAddress.length === 0){ + var pushRequester = false; + var pushType = false; + + // Check filter by requester + if (!search || search.trim().length === 0) { // if search is empty and mustContain == true push only unfiltered devices + if (mustContain) { + if (!input[i].requesterAddress || input[i].requesterAddress.length === 0) { + pushRequester = true; + } + } else { + pushRequester = true; + } + } else { + if(pattern.test(input[i].requesterAddress) || !mustContain && (!input[i].requesterAddress || input[i].requesterAddress.length === 0)){ + pushRequester = true; + } + } + + // Check filter by deviceType + if (deviceType) { + pushType = patternType.test(input[i].deviceType); + } else { + pushType = true; + } + + if (pushRequester && pushType) { out.push(input[i]); } } diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index 0060600..0f1705f 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -37,6 +37,25 @@ + Must contain filter + + @@ -55,7 +74,7 @@ Actions - + {{$index+1}} {{device.id}} {{device.name}}