From d36769e2a06d63db9be15ee2ec5ed9a7052aee11 Mon Sep 17 00:00:00 2001 From: diamond Date: Thu, 4 May 2017 03:19:03 +0300 Subject: [PATCH 1/4] fibaro HC2 support --- .../bwssystems/HABridge/BridgeSettings.java | 18 ++ .../HABridge/BridgeSettingsDescriptor.java | 25 ++ .../bwssystems/HABridge/DeviceMapTypes.java | 4 + .../com/bwssystems/HABridge/HomeManager.java | 9 +- .../devicemanagmeent/DeviceResource.java | 12 + .../HABridge/plugins/fibaro/Device.java | 75 ++++++ .../HABridge/plugins/fibaro/FibaroHome.java | 103 ++++++++ .../HABridge/plugins/fibaro/FibaroInfo.java | 146 +++++++++++ .../HABridge/plugins/fibaro/Room.java | 19 ++ .../HABridge/plugins/fibaro/Scene.java | 39 +++ src/main/resources/public/scripts/app.js | 248 +++++++++++++++++- .../resources/public/views/configuration.html | 4 + .../public/views/domoticzdevice.html | 4 + .../resources/public/views/editdevice.html | 4 + .../resources/public/views/fibarodevice.html | 145 ++++++++++ .../resources/public/views/fibaroscene.html | 114 ++++++++ .../resources/public/views/haldevice.html | 4 + .../public/views/harmonyactivity.html | 4 + .../resources/public/views/harmonydevice.html | 4 + .../resources/public/views/hassdevice.html | 4 + .../resources/public/views/huedevice.html | 4 + .../resources/public/views/lifxdevice.html | 2 + src/main/resources/public/views/logs.html | 4 + .../resources/public/views/mqttpublish.html | 2 + .../resources/public/views/nestactions.html | 4 + .../resources/public/views/somfydevice.html | 5 +- src/main/resources/public/views/system.html | 33 +++ .../resources/public/views/veradevice.html | 5 +- .../resources/public/views/verascene.html | 5 +- 29 files changed, 1041 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java create mode 100644 src/main/resources/public/views/fibarodevice.html create mode 100644 src/main/resources/public/views/fibaroscene.html diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java index 9365f9d..200f267 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java @@ -65,6 +65,7 @@ public class BridgeSettings extends BackupHandler { public void buildSettings() { String addressString = null; String theVeraAddress = null; + String theFibaroAddress = null; String theSomfyAddress = null; String theHarmonyAddress = null; String configFileProperty = System.getProperty("config.file"); @@ -107,6 +108,22 @@ public class BridgeSettings extends BackupHandler { } } theBridgeSettings.setVeraAddress(theVeraList); + + theFibaroAddress = System.getProperty("fibaro.address"); + IpList theFibaroList = null; + if(theFibaroAddress != null) { + try { + theFibaroList = new Gson().fromJson(theFibaroAddress, IpList.class); + } catch (Exception e) { + try { + theFibaroList = new Gson().fromJson("{devices:[{name:default,ip:" + theFibaroAddress + "}]}", IpList.class); + } catch (Exception et) { + log.error("Cannot parse fibaro.address, not set with message: " + e.getMessage(), e); + theFibaroList = null; + } + } + } + theBridgeSettings.setFibaroAddress(theFibaroList); theHarmonyAddress = System.getProperty("harmony.address"); IpList theHarmonyList = null; @@ -178,6 +195,7 @@ public class BridgeSettings extends BackupHandler { theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP)); theBridgeSettings.setVeraconfigured(theBridgeSettings.isValidVera()); + theBridgeSettings.setFibaroconfigured(theBridgeSettings.isValidFibaro()); theBridgeSettings.setHarmonyconfigured(theBridgeSettings.isValidHarmony()); theBridgeSettings.setNestConfigured(theBridgeSettings.isValidNest()); theBridgeSettings.setHueconfigured(theBridgeSettings.isValidHue()); diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java index 319f5c0..4bec5ed 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java @@ -24,6 +24,9 @@ public class BridgeSettingsDescriptor { @SerializedName("veraaddress") @Expose private IpList veraaddress; + @SerializedName("fibaroaddress") + @Expose + private IpList fibaroaddress; @SerializedName("harmonyaddress") @Expose private IpList harmonyaddress; @@ -91,6 +94,7 @@ public class BridgeSettingsDescriptor { private boolean settingsChanged; private boolean veraconfigured; + private boolean fibaroconfigured; private boolean harmonyconfigured; private boolean hueconfigured; private boolean nestconfigured; @@ -107,6 +111,7 @@ public class BridgeSettingsDescriptor { this.traceupnp = false; this.nestconfigured = false; this.veraconfigured = false; + this.fibaroconfigured = false; this.somfyconfigured = false; this.harmonyconfigured = false; this.hueconfigured = false; @@ -153,12 +158,18 @@ public class BridgeSettingsDescriptor { public IpList getVeraAddress() { return veraaddress; } + public IpList getFibaroAddress() { + return fibaroaddress; + } public IpList getSomfyAddress() { return somfyaddress; } public void setVeraAddress(IpList veraAddress) { this.veraaddress = veraAddress; } + public void setFibaroAddress(IpList fibaroAddress) { + this.fibaroaddress = fibaroAddress; + } public void setSomfyAddress(IpList somfyAddress) { this.somfyaddress = somfyAddress; } @@ -195,12 +206,18 @@ public class BridgeSettingsDescriptor { public boolean isVeraconfigured() { return veraconfigured; } + public boolean isFibaroconfigured() { + return fibaroconfigured; + } public boolean isSomfyconfigured() { return somfyconfigured; } public void setVeraconfigured(boolean veraconfigured) { this.veraconfigured = veraconfigured; } + public void setFibaroconfigured(boolean fibaroconfigured) { + this.fibaroconfigured = fibaroconfigured; + } public void setSomfyconfigured(boolean somfyconfigured) { this.somfyconfigured = somfyconfigured; } @@ -356,6 +373,14 @@ public class BridgeSettingsDescriptor { return false; return true; } + public Boolean isValidFibaro() { + if(this.getFibaroAddress() == null || this.getFibaroAddress().getDevices().size() <= 0) + return false; + List devicesList = this.getFibaroAddress().getDevices(); + if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS)) + return false; + return true; + } public Boolean isValidHarmony() { if(this.getHarmonyAddress() == null || this.getHarmonyAddress().getDevices().size() <= 0) return false; diff --git a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java index f8fae87..9c13d71 100644 --- a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java +++ b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java @@ -7,6 +7,8 @@ public class DeviceMapTypes { 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[] FIBARO_DEVICE = { "fibaroDevice", "Fibaro Device"}; + public final static String[] FIBARO_SCENE = { "fibaroScene", "Fibaro 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"}; @@ -57,6 +59,8 @@ public class DeviceMapTypes { deviceMapTypes.add(UDP_DEVICE); deviceMapTypes.add(VERA_DEVICE); deviceMapTypes.add(VERA_SCENE); + deviceMapTypes.add(FIBARO_DEVICE); + deviceMapTypes.add(FIBARO_SCENE); deviceMapTypes.add(SOMFY_DEVICE); } public static int getTypeIndex() { diff --git a/src/main/java/com/bwssystems/HABridge/HomeManager.java b/src/main/java/com/bwssystems/HABridge/HomeManager.java index 4bc8276..60b3bcc 100644 --- a/src/main/java/com/bwssystems/HABridge/HomeManager.java +++ b/src/main/java/com/bwssystems/HABridge/HomeManager.java @@ -19,6 +19,7 @@ import com.bwssystems.HABridge.plugins.somfy.SomfyHome; import com.bwssystems.HABridge.plugins.tcp.TCPHome; import com.bwssystems.HABridge.plugins.udp.UDPHome; import com.bwssystems.HABridge.plugins.vera.VeraHome; +import com.bwssystems.HABridge.plugins.fibaro.FibaroHome; import com.bwssystems.HABridge.util.UDPDatagramSender; public class HomeManager { @@ -73,6 +74,8 @@ public class HomeManager { homeList.put(DeviceMapTypes.CUSTOM_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome); + homeList.put(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex], aHome); + homeList.put(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex], aHome); //setup the tcp handler Home aHome = new TCPHome(bridgeSettings); homeList.put(DeviceMapTypes.TCP_DEVICE[DeviceMapTypes.typeIndex], aHome); @@ -85,7 +88,11 @@ public class HomeManager { aHome = new VeraHome(bridgeSettings); resourceList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome); resourceList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome); - //setup the Domoticz configuration if available + // Setup Fibaro Home if available + aHome = new FibaroHome(bridgeSettings); + resourceList.put(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex], aHome); + resourceList.put(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex], aHome); + //setup the Domoticz configuration if available aHome = new DomoticzHome(bridgeSettings); homeList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome); resourceList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome); diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index f1bbc7b..16c575a 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -214,6 +214,18 @@ public class DeviceResource { response.status(HttpStatus.SC_OK); return homeManager.findResource(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); + + get (API_CONTEXT + "/fibaro/devices", "application/json", (request, response) -> { + log.debug("Get fibaro devices"); + response.status(HttpStatus.SC_OK); + return homeManager.findResource(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex]); + }, new JsonTransformer()); + + get (API_CONTEXT + "/fibaro/scenes", "application/json", (request, response) -> { + log.debug("Get fibaro scenes"); + response.status(HttpStatus.SC_OK); + return homeManager.findResource(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex]); + }, new JsonTransformer()); get (API_CONTEXT + "/harmony/activities", "application/json", (request, response) -> { log.debug("Get harmony activities"); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java new file mode 100644 index 0000000..0bfa44d --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java @@ -0,0 +1,75 @@ +package com.bwssystems.HABridge.plugins.fibaro; + +public class Device +{ + public int id; + public String name; + public int roomID; + public String type; + public String baseType; + public boolean enabled; + public boolean visible; + public boolean isPlugin; + public int parentId; + public int remoteGatewayId; + public boolean viewXml; + public boolean configXml; + public Object interfaces; + public Properties properties; + public Object actions; + public int created; + public int modified; + public int sortOrder; + + public class Properties { + public String UIMessageSendTime; + public String autoConfig; + public String date; + public String dead; + public String deviceControlType; + public String deviceIcon; + public String disabled; + public String emailNotificationID; + public String emailNotificationType; + public String endPoint; + public String liliOffCommand; + public String liliOnCommand; + public String log; + public String logTemp; + public String manufacturer; + public String markAsDead; + public String model; + public String nodeID; + public String pollingDeadDevice; + public String pollingTime; + public String pollingTimeNext; + public int pollingTimeSec; + public String productInfo; + public String pushNotificationID; + public String pushNotificationType; + public String remoteGatewayId; + public String requestNodeNeighborStat; + public String requestNodeNeighborStatTimeStemp; + public String requestNodeNeighborState; + public String requestNodeNeighborStateTimeStemp; + public String saveLogs; + public String showChildren; + public String smsNotificationID; + public String smsNotificationType; + public String status; + public String sunriseHour; + public String sunsetHour; + public String userDescription; + public String value; + public String zwaveBuildVersion; + public String zwaveCompany; + public String zwaveInfo; + public String zwaveRegion; + public double zwaveVersion; + } + + public String room; + public String category; + public String fibaroaddress; + public String fibaroname; +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java new file mode 100644 index 0000000..f0c8a26 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java @@ -0,0 +1,103 @@ +package com.bwssystems.HABridge.plugins.fibaro; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.bwssystems.HABridge.BridgeSettings; +import com.bwssystems.HABridge.DeviceMapTypes; +import com.bwssystems.HABridge.Home; +import com.bwssystems.HABridge.NamedIP; +import com.bwssystems.HABridge.api.CallItem; +import com.bwssystems.HABridge.dao.DeviceDescriptor; +import com.bwssystems.HABridge.hue.MultiCommandUtil; + +public class FibaroHome implements Home +{ + private static final Logger log = LoggerFactory.getLogger(FibaroHome.class); + private Map fibaros; + private Boolean validFibaro; + + public FibaroHome(BridgeSettings bridgeSettings) + { + super(); + createHome(bridgeSettings); + } + + public List getDevices() + { + log.debug("consolidating devices for fibaros"); + Iterator keys = fibaros.keySet().iterator(); + ArrayList deviceList = new ArrayList<>(); + while(keys.hasNext()) + { + String key = keys.next(); + for(Device device : fibaros.get(key).getDevices()) + deviceList.add(device); + } + return deviceList; + } + + public List getScenes() + { + log.debug("consolidating scenes for fibaros"); + Iterator keys = fibaros.keySet().iterator(); + ArrayList sceneList = new ArrayList<>(); + while(keys.hasNext()) + { + String key = keys.next(); + for(Scene scene : fibaros.get(key).getScenes()) + sceneList.add(scene); + } + return sceneList; + } + + @Override + public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity, Integer targetBri, Integer targetBriInc, DeviceDescriptor device, String body) + { + // Not a device handler + return null; + } + + @Override + public Object getItems(String type) + { + if(validFibaro) + { + if(type.equalsIgnoreCase(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex])) + return getDevices(); + if(type.equalsIgnoreCase(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex])) + return getScenes(); + } + return null; + } + + @Override + public Home createHome(BridgeSettings bridgeSettings) + { + validFibaro = bridgeSettings.getBridgeSettingsDescriptor().isValidFibaro(); + log.info("Fibaro Home created." + (validFibaro ? "" : " No Fibaros configured.")); + if(validFibaro) + { + fibaros = new HashMap(); + Iterator theList = bridgeSettings.getBridgeSettingsDescriptor().getFibaroAddress().getDevices().iterator(); + while(theList.hasNext()) + { + NamedIP aFibaro = theList.next(); + fibaros.put(aFibaro.getName(), new FibaroInfo(aFibaro)); + } + } + return this; + } + + @Override + public void closeHome() + { + fibaros = null; + } +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java new file mode 100644 index 0000000..019ff94 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java @@ -0,0 +1,146 @@ +package com.bwssystems.HABridge.plugins.fibaro; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.bwssystems.HABridge.NamedIP; +import com.bwssystems.HABridge.plugins.http.HTTPHandler; +import com.google.gson.Gson; + +public class FibaroInfo +{ + private static final Logger log = LoggerFactory.getLogger(FibaroInfo.class); + private HTTPHandler httpClient; + private NamedIP fibaroAddress; + + // You can disable it if you want + boolean useSaveLogs = true; // This can be used to exclude some devices from list + boolean useUserDescription = true; + boolean removeDigits = true; + boolean scenesWithLiliCommandOnly = true; + + public FibaroInfo(NamedIP addressName) + { + super(); + httpClient = new HTTPHandler(); + fibaroAddress = addressName; + } + + public Device[] getDevices() + { + Room[] rooms = getRooms(); + + log.debug("Founded: " + rooms.length + ", rooms"); + + Device[] all_devices = getAllDevices(); + int count = 0; + for(Device d : all_devices) + { + if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true) + count++; + } + + Device[] devices = new Device[count]; + int i = 0; + for(Device d : all_devices) + if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true) + { + if(useUserDescription && d.properties.userDescription != null && !d.properties.userDescription.isEmpty()) + d.name = d.properties.userDescription; + if(removeDigits) + d.name = replaceDigits(d.name); + devices[i++] = d; + + for(Room room : rooms) + if(d.roomID == room.id) + { + d.room = room.name.trim(); + d.category = String.valueOf(room.sectionID); // TODO load name of section + } + + d.fibaroaddress = fibaroAddress.getIp(); + d.fibaroname = fibaroAddress.getName(); + } + + log.debug("Founded: " + devices.length + " devices"); + + return devices; + } + + public Scene[] getScenes() + { + Room[] rooms = getRooms(); + int count = 0; + Scene[] scenes = getAllScenes(); + for(Scene s : scenes) + if(!scenesWithLiliCommandOnly || s.liliStartCommand != null && !s.liliStartCommand.isEmpty()) + count++; + Scene[] result = new Scene[count]; + int i = 0; + for(Scene s : scenes) + if(!scenesWithLiliCommandOnly || s.liliStartCommand != null && !s.liliStartCommand.isEmpty()) + { + result[i++] = s; + + for(Room room : rooms) + if(s.roomID == room.id) + { + s.room = room.name.trim(); + s.category = String.valueOf(room.sectionID); // TODO load name of section + } + + s.fibaroaddress = fibaroAddress.getIp(); + s.fibaroname = fibaroAddress.getName(); + } + System.out.println("Founded: " + count + " scenes"); + return result; + } + + private Device[] getAllDevices() + { + String result = request("devices?enabled=true&visible=true"); + if(result == null) + return new Device[0]; + Device[] devices = new Gson().fromJson(result, Device[].class); + return devices; + } + + private Scene[] getAllScenes() + { + String result = request("scenes?enabled=true&visible=true"); + if(result == null) + return new Scene[0]; + Scene[] scenes = new Gson().fromJson(result, Scene[].class); + return scenes; + } + + private Room[] getRooms() + { + String result = request("rooms"); + if(result == null) + return new Room[0]; + return new Gson().fromJson(result, Room[].class); + } + + private String request(String theUrl) + { + theUrl = "http://" + fibaroAddress.getIp() + "/api/" + theUrl; + return httpClient.doHttpRequest(theUrl, null, null, null, null); + } + + private String replaceDigits(String name) + { + name = name.replaceAll("1", ""); + name = name.replaceAll("2", ""); + name = name.replaceAll("3", ""); + name = name.replaceAll("4", ""); + name = name.replaceAll("5", ""); + name = name.replaceAll("6", ""); + name = name.replaceAll("7", ""); + name = name.replaceAll("8", ""); + name = name.replaceAll("9", ""); + name = name.replaceAll("0", ""); + name = name.trim(); + return name; + } +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java new file mode 100644 index 0000000..0f7433e --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java @@ -0,0 +1,19 @@ +package com.bwssystems.HABridge.plugins.fibaro; + +public class Room +{ + public int id; + public String name; + public int sectionID; + public String icon; + public Sensor defaultSensors; + public int defaultThermostat; + public int sortOrder; + + public class Sensor + { + public int temperature; + public int humidity; + public int light; + } +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java new file mode 100644 index 0000000..da4ce01 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java @@ -0,0 +1,39 @@ +package com.bwssystems.HABridge.plugins.fibaro; + +public class Scene +{ + public int id; + public String name; + public String type; + public String properties; + public int roomID; + public int iconID; + public String runConfig; + public boolean autostart; + public boolean protectedByPIN; + public boolean killable; + public int maxRunningInstances; + public int runningInstances; + public boolean visible; + public boolean isLua; + public Triggers triggers; + public String liliStartCommand; + public String liliStopCommand; + public int sortOrder; + + public class Triggers { + public Properties[] properties; + public String[] globals; + public String[] events; + } + + public class Properties { + public String id; + public String name; + } + + public String room; + public String category; + public String fibaroaddress; + public String fibaroname; +} \ No newline at end of file diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index f98bcce..b103d67 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -26,7 +26,15 @@ app.config (function ($locationProvider, $routeProvider) { }).when ('/verascenes', { templateUrl: 'views/verascene.html', controller: 'VeraController', + requiresAuthentication: true + }).when ('/fibarodevices', { + templateUrl: 'views/fibarodevice.html', + controller: 'FibaroController', requiresAuthentication: true + }).when ('/fibaroscenes', { + templateUrl: 'views/fibaroscene.html', + controller: 'FibaroController', + requiresAuthentication: true }).when ('/harmonydevices', { templateUrl: 'views/harmonydevice.html', controller: 'HarmonyController', @@ -133,7 +141,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n 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, + isInControl: false, showVera: false, showFibaro: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, showDomoticz: false, showSomfy: false, showLifx: false, habridgeversion: {}, viewDevId: "", queueDevId: "", securityInfo: {}}; this.displayWarn = function(errorTitle, error) { @@ -455,6 +463,11 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n this.state.showVera = self.state.settings.veraconfigured; return; } + + this.updateShowFibaro = function () { + this.state.showFibaro = self.state.settings.fibaroconfigured; + return; + } this.updateShowNest = function () { this.state.showNest = self.state.settings.nestconfigured; @@ -506,6 +519,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n function (response) { self.state.settings = response.data; self.updateShowVera(); + self.updateShowFibaro(); self.updateShowHarmony(); self.updateShowNest(); self.updateShowHue(); @@ -644,6 +658,38 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n } ); }; + + this.viewFibaroDevices = function () { + if(!this.state.showFibaro) + return; + return $http.get(this.state.base + "/fibaro/devices").then( + function (response) { + self.state.fibarodevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get Fibaro Devices Error: ", error); + } + ); + }; + + this.viewFibaroScenes = function () { + if(!this.state.showFibaro) + return; + return $http.get(this.state.base + "/fibaro/scenes").then( + function (response) { + self.state.fibaroscenes = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get Fibaro Scenes Error: ", error); + } + ); + }; this.viewHarmonyActivities = function () { if (!this.state.showHarmony) @@ -1285,6 +1331,22 @@ app.controller ('SystemController', function ($scope, $location, bridgeService, } } }; + $scope.addFibarotoSettings = function (newfibaroname, newfibaroip) { + if($scope.bridge.settings.fibaroaddress === undefined || $scope.bridge.settings.fibaroaddress === null) { + $scope.bridge.settings.fibaroaddress = { devices: [] }; + } + var newFibaro = {name: newfibaroname, ip: newfibaroip } + $scope.bridge.settings.fibaroaddress.devices.push(newFibaro); + $scope.newfibaroname = null; + $scope.newfibaroip = null; + }; + $scope.removeFibarotoSettings = function (fibaroname, fibaroip) { + for(var i = $scope.bridge.settings.fibaroaddress.devices.length - 1; i >= 0; i--) { + if($scope.bridge.settings.fibaroaddress.devices[i].name === fibaroname && $scope.bridge.settings.fibaroaddress.devices[i].ip === fibaroip) { + $scope.bridge.settings.fibaroaddress.devices.splice(i, 1); + } + } + }; $scope.addHarmonytoSettings = function (newharmonyname, newharmonyip) { if($scope.bridge.settings.harmonyaddress === undefined || $scope.bridge.settings.harmonyaddress === null) { $scope.bridge.settings.harmonyaddress = { devices: [] }; @@ -1898,6 +1960,162 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD }; }); +app.controller('FibaroController', function ($scope, $location, bridgeService, ngDialog) { + $scope.bridge = bridgeService.state; + $scope.device = bridgeService.state.device; + $scope.device_dim_control = ""; + $scope.bulk = { devices: [] }; + $scope.selectAll = false; + $scope.fibaro = {base: "http://", port: "80", id: ""}; + bridgeService.viewFibaroDevices(); + bridgeService.viewFibaroScenes(); + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + $scope.buttonsVisible = false; + $scope.comparatorUniqueId = bridgeService.compareUniqueId; + + $scope.clearDevice = function () { + bridgeService.clearDevice(); + $scope.device = bridgeService.state.device; + }; + + $scope.buildDeviceUrls = function (fibarodevice, dim_control, buildonly) { + if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) { + dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + + "/data_request?id=action&output_format=json&DeviceNum=" + + fibarodevice.id + + "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=" + + dim_control; + } + else + dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + + fibarodevice.id; + onpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + + fibarodevice.id; + offpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=" + + fibarodevice.id; + + bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, fibarodevice.id, fibarodevice.name, fibarodevice.fibaroname, "switch", "fibaroDevice", null, null); + $scope.device = bridgeService.state.device; + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } + }; + + $scope.buildSceneUrls = function (fibaroscene) { + onpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port + + "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=" + + fibaroscene.id; + offpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port + + "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=" + + fibarocene.id; + + bridgeService.buildUrls(onpayload, null, offpayload, false, fibaroscene.id, fibaroscene.name, fibaroscene.fibaroname, "scene", "fibaroScene", null, null); + $scope.device = bridgeService.state.device; + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + }; + + $scope.bulkAddDevices = function(dim_control) { + var devicesList = []; + $scope.clearDevice(); + for(var i = 0; i < $scope.bulk.devices.length; i++) { + for(var x = 0; x < bridgeService.state.fibarodevices.length; x++) { + if(bridgeService.state.fibarodevices[x].id === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.fibarodevices[x],dim_control,true); + 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, + dimUrl: $scope.device.dimUrl, + offUrl: $scope.device.offUrl, + headers: $scope.device.headers, + httpVerb: $scope.device.httpVerb, + contentType: $scope.device.contentType, + contentBody: $scope.device.contentBody, + contentBodyDim: $scope.device.contentBodyDim, + contentBodyOff: $scope.device.contentBodyOff + }; + $scope.clearDevice(); + } + } + } + bridgeService.bulkAddDevice(devicesList).then( + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewfibaroDevices(); + bridgeService.viewfibaroScenes(); + }, + function (error) { + bridgeService.displayWarn("Error adding fibaro devices in bulk.", error) + } + ); + $scope.bulk = { devices: [] }; + $scope.selectAll = false; + }; + + $scope.toggleSelection = function toggleSelection(deviceId) { + var idx = $scope.bulk.devices.indexOf(deviceId); + + // is currently selected + if (idx > -1) { + $scope.bulk.devices.splice(idx, 1); + if($scope.bulk.devices.length === 0 && $scope.selectAll) + $scope.selectAll = false; + } + + // is newly selected + else { + $scope.bulk.devices.push(deviceId); + $scope.selectAll = true; + } + }; + + $scope.toggleSelectAll = function toggleSelectAll() { + if($scope.selectAll) { + $scope.selectAll = false; + $scope.bulk = { devices: [] }; + } + else { + $scope.selectAll = true; + for(var x = 0; x < bridgeService.state.fibarodevices.length; x++) { + if($scope.bulk.devices.indexOf(bridgeService.state.fibarodevices[x]) < 0) + $scope.bulk.devices.push(bridgeService.state.fibarodevices[x].id); + } + } + }; + + $scope.toggleButtons = function () { + $scope.buttonsVisible = !$scope.buttonsVisible; + if($scope.buttonsVisible) + $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; + else + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + }; + + $scope.deleteDevice = function (device) { + $scope.bridge.device = device; + ngDialog.open({ + template: 'deleteDialog', + controller: 'DeleteDialogCtrl', + className: 'ngdialog-theme-default' + }); + }; + + $scope.editDevice = function (device) { + bridgeService.editDevice(device); + $location.path('/editdevice'); + }; +}); + + app.controller('HarmonyController', function ($scope, $location, bridgeService, ngDialog) { $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; @@ -3228,6 +3446,34 @@ app.filter('configuredVeraScenes', function (bridgeService) { } }); +app.filter('configuredFibaroDevices', function (bridgeService) { + return function(input) { + var out = []; + if(input === undefined || input === null || input.length === undefined) + return out; + for (var i = 0; i < input.length; i++) { + if(bridgeService.deviceContainsType(input[i], "fibaroDevice")){ + out.push(input[i]); + } + } + return out; + } +}); + +app.filter('configuredFibaroScenes', function (bridgeService) { + return function(input) { + var out = []; + if(input === undefined || input === null || input.length === undefined) + return out; + for (var i = 0; i < input.length; i++) { + if(bridgeService.deviceContainsType(input[i], "fibaroScene")){ + out.push(input[i]); + } + } + return out; + } +}); + app.filter('configuredNestItems', function (bridgeService) { return function(input) { var out = []; diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index def1839..145a015 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -8,6 +8,10 @@ href="#!/veradevices">Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • +
  • Bridge Devices
  • +
  • Bridge Control
  • +
  • Logs
  • +
  • Vera Devices
  • +
  • Vera Scenes
  • + +
  • Fibaro Scenes
  • +
  • Harmony Activities
  • +
  • Harmony Devices
  • +
  • Nest
  • +
  • Hue Devices
  • +
  • HAL Devices
  • +
  • MQTT Messages
  • +
  • HomeAssistant Devices
  • +
  • Domoticz Devices
  • +
  • Somfy Devices
  • +
  • LIFX Devices
  • +
  • Add/Edit
  • + + +
    +
    +

    Fibaro Device List + ({{bridge.fibarodevices.length}})

    +
    +
    +

    For any Fibaro Device, use the build action buttons + to generate the item addition information into the ha-bridge device + and this will put you into the edit screen. Then + you can modify the name to anything you want that will be the keyword + for the Echo or Google Home. Also, you can go back to any helper tab and click a build + action button to add another item for a multi-command. After you are + done in the edit tab, click the 'Add Bridge Device' to finish that selection + setup. The 'Already Configured Fibaro Devices' list below will show + what is already setup for your Fibaro.

    +

    + Also, use this select menu for which type of dim control you would + like to be generated: +

    +

    Use the check boxes by the names to use the bulk addition + feature. Select your items and dim control type if wanted, then click + bulk add below. Your items will be added with on and off or dim and + off if selected with the name of the device from the Fibaro.

    + + + + + + + + + + + + + + + + + + + + + + +
    Row NameIdCategoryRoomFibaroBuild Actions
    {{$index+1}} + {{fibarodevice.name}}{{fibarodevice.id}}{{fibarodevice.category}}{{fibarodevice.room}}{{fibarodevice.fibaroname}} + +
    +
    + +
    +
    +
    +
    +

    + Already Configured Fibaro Devices +

    +
    +
    + + + + + + + + + + + + + + + + + + +
    RowNameFibaroMap IdActions
    {{$index+1}}{{device.name}}{{device.targetDevice}}{{device.mapId}} +

    + + +

    +
    +
    +
    +
    + \ No newline at end of file diff --git a/src/main/resources/public/views/fibaroscene.html b/src/main/resources/public/views/fibaroscene.html new file mode 100644 index 0000000..7b1ba14 --- /dev/null +++ b/src/main/resources/public/views/fibaroscene.html @@ -0,0 +1,114 @@ + + +
    +
    +

    Fibaro Scene List

    +
    +
    +

    For any Fibaro Scene, use the build action buttons + to generate the item addition information into the ha-bridge device and this will put you into the edit screen. Then + you can modify the name to anything you want that will be the keyword + for the Echo or Google Home. Also, you can go back to any helper tab and click a build + action button to add another item for a multi-command. After you are + done in the edit tab, click the 'Add Bridge Device' to finish that selection + setup. The 'Already Configured Fibaro Scenes' list below will show what + is already setup for your Fibaro.

    + + + + + + + + + + + + + + + + + + + + + +
    RowNameIdRoomFibaroBuild Actions
    {{$index+1}}{{fibaroscene.name}}{{fibaroscene.id}}{{fibaroscene.room}}{{fibaroscene.fibaroname}} + +
    +
    +
    +
    +
    +
    +

    + Already Configured Fibaro Scenes +

    +
    +
    + + + + + + + + + + + + + + + + + + +
    RowNameFibaroMap IdActions
    {{$index+1}}{{device.name}}{{device.targetDevice}}{{device.mapId}} +

    + + +

    +
    +
    +
    +
    + \ No newline at end of file diff --git a/src/main/resources/public/views/haldevice.html b/src/main/resources/public/views/haldevice.html index 7d365e2..0e69323 100644 --- a/src/main/resources/public/views/haldevice.html +++ b/src/main/resources/public/views/haldevice.html @@ -6,6 +6,10 @@ href="#!/veradevices">Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony diff --git a/src/main/resources/public/views/harmonydevice.html b/src/main/resources/public/views/harmonydevice.html index a4f51d2..e20b0fa 100644 --- a/src/main/resources/public/views/harmonydevice.html +++ b/src/main/resources/public/views/harmonydevice.html @@ -6,6 +6,10 @@ href="#!/veradevices">Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Logs
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Harmony Devices
  • Nest
  • diff --git a/src/main/resources/public/views/logs.html b/src/main/resources/public/views/logs.html index c1d853c..fca1aee 100644 --- a/src/main/resources/public/views/logs.html +++ b/src/main/resources/public/views/logs.html @@ -6,6 +6,10 @@ href="#!/veradevices">Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Logs
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Harmony Devices
  • Nest
  • diff --git a/src/main/resources/public/views/nestactions.html b/src/main/resources/public/views/nestactions.html index c91cff6..34875b9 100644 --- a/src/main/resources/public/views/nestactions.html +++ b/src/main/resources/public/views/nestactions.html @@ -6,6 +6,10 @@ href="#!/veradevices">Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Bridge Devices
  • Bridge Control
  • Logs
  • -
  • Vera - Devices
  • +
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Vera Devices
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • + + Fibaro Names and IP Addresses + + + + + + + + + + + + + + + + + + +
    NameIPManage
    {{fibaro.name}}{{fibaro.ip}}
    + Harmony Names and IP Addresses Bridge Devices
  • Bridge Control
  • Logs
  • - +
  • Vera Scenes
  • +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Bridge Control
  • Logs
  • Vera Devices
  • - + +
  • Fibaro Devices
  • +
  • Fibaro Scenes
  • Harmony Activities
  • Date: Thu, 4 May 2017 03:48:24 +0300 Subject: [PATCH 2/4] fix requests --- src/main/resources/public/scripts/app.js | 44 ++++++++---------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index b103d67..1f8f8a2 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -1979,39 +1979,25 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n }; $scope.buildDeviceUrls = function (fibarodevice, dim_control, buildonly) { - if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) { - dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port - + "/data_request?id=action&output_format=json&DeviceNum=" - + fibarodevice.id - + "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=" - + dim_control; - } - else - dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port - + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" - + fibarodevice.id; - onpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port - + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" - + fibarodevice.id; - offpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port - + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=" - + fibarodevice.id; + if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) + dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=setValue&arg1=" + dim_control; + else + dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOn"; + + onpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOn"; + offpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOff"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, fibarodevice.id, fibarodevice.name, fibarodevice.fibaroname, "switch", "fibaroDevice", null, null); - $scope.device = bridgeService.state.device; - if (!buildonly) { - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); - } + bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, fibarodevice.id, fibarodevice.name, fibarodevice.fibaroname, "switch", "fibaroDevice", null, null); + $scope.device = bridgeService.state.device; + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; $scope.buildSceneUrls = function (fibaroscene) { - onpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port - + "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=" - + fibaroscene.id; - offpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port - + "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=" - + fibarocene.id; + onpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port + "/api/sceneControl?id=" + fibaroscene.id + "&action=start"; + offpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port + "/api/sceneControl?id=" + fibaroscene.id + "&action=stop"; bridgeService.buildUrls(onpayload, null, offpayload, false, fibaroscene.id, fibaroscene.name, fibaroscene.fibaroname, "scene", "fibaroScene", null, null); $scope.device = bridgeService.state.device; From 9aaab37a17e829a3c94bf09f92d797385ca87edf Mon Sep 17 00:00:00 2001 From: diamond Date: Thu, 4 May 2017 05:59:04 +0300 Subject: [PATCH 3/4] auth --- .../bwssystems/HABridge/BridgeSettings.java | 2 +- .../HABridge/plugins/fibaro/FibaroInfo.java | 45 +++++++++++++++---- src/main/resources/public/scripts/app.js | 6 ++- .../resources/public/views/fibarodevice.html | 4 +- .../resources/public/views/fibaroscene.html | 4 +- src/main/resources/public/views/system.html | 13 +++++- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java index 200f267..d6d54f7 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java @@ -110,7 +110,7 @@ public class BridgeSettings extends BackupHandler { theBridgeSettings.setVeraAddress(theVeraList); theFibaroAddress = System.getProperty("fibaro.address"); - IpList theFibaroList = null; + IpList theFibaroList = null; if(theFibaroAddress != null) { try { theFibaroList = new Gson().fromJson(theFibaroAddress, IpList.class); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java index 019ff94..bbd6ae2 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java @@ -1,16 +1,20 @@ package com.bwssystems.HABridge.plugins.fibaro; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.bwssystems.HABridge.NamedIP; -import com.bwssystems.HABridge.plugins.http.HTTPHandler; import com.google.gson.Gson; public class FibaroInfo { private static final Logger log = LoggerFactory.getLogger(FibaroInfo.class); - private HTTPHandler httpClient; private NamedIP fibaroAddress; // You can disable it if you want @@ -22,7 +26,6 @@ public class FibaroInfo public FibaroInfo(NamedIP addressName) { super(); - httpClient = new HTTPHandler(); fibaroAddress = addressName; } @@ -35,10 +38,8 @@ public class FibaroInfo Device[] all_devices = getAllDevices(); int count = 0; for(Device d : all_devices) - { if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true) count++; - } Device[] devices = new Device[count]; int i = 0; @@ -62,7 +63,7 @@ public class FibaroInfo d.fibaroname = fibaroAddress.getName(); } - log.debug("Founded: " + devices.length + " devices"); + log.info("Founded: " + devices.length + " devices"); return devices; } @@ -92,7 +93,7 @@ public class FibaroInfo s.fibaroaddress = fibaroAddress.getIp(); s.fibaroname = fibaroAddress.getName(); } - System.out.println("Founded: " + count + " scenes"); + log.info("Founded: " + count + " scenes"); return result; } @@ -125,7 +126,35 @@ public class FibaroInfo private String request(String theUrl) { theUrl = "http://" + fibaroAddress.getIp() + "/api/" + theUrl; - return httpClient.doHttpRequest(theUrl, null, null, null, null); + String auth = new String(Base64.encodeBase64((fibaroAddress.getUsername() + ":" + fibaroAddress.getPassword()).getBytes())); + java.net.URL url; + java.net.HttpURLConnection connection; + String result = null; + try + { + url = new URL(theUrl); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Authorization", "Basic " + auth); + connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); + connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36"); + connection.connect(); + BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); + StringBuilder buffer = new StringBuilder(); + String line; + while((line = br.readLine()) != null) + buffer.append(line).append("\n"); + br.close(); + result = buffer.toString(); + } + catch(Exception e) + { + log.info("Error while get getJson: " + theUrl); + e.printStackTrace(); + return null; + } + return result; } private String replaceDigits(String name) diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 1f8f8a2..3b3e5c2 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -1331,14 +1331,16 @@ app.controller ('SystemController', function ($scope, $location, bridgeService, } } }; - $scope.addFibarotoSettings = function (newfibaroname, newfibaroip) { + $scope.addFibarotoSettings = function (newfibaroname, newfibaroip, newfibarousername, newfibaropassword) { if($scope.bridge.settings.fibaroaddress === undefined || $scope.bridge.settings.fibaroaddress === null) { $scope.bridge.settings.fibaroaddress = { devices: [] }; } - var newFibaro = {name: newfibaroname, ip: newfibaroip } + var newFibaro = {name: newfibaroname, ip: newfibaroip, username: newfibarousername, password: newfibaropassword } $scope.bridge.settings.fibaroaddress.devices.push(newFibaro); $scope.newfibaroname = null; $scope.newfibaroip = null; + $scope.newfibarousername = null; + $scope.newfibaropassword = null; }; $scope.removeFibarotoSettings = function (fibaroname, fibaroip) { for(var i = $scope.bridge.settings.fibaroaddress.devices.length - 1; i >= 0; i--) { diff --git a/src/main/resources/public/views/fibarodevice.html b/src/main/resources/public/views/fibarodevice.html index 25c7145..fe8e513 100644 --- a/src/main/resources/public/views/fibarodevice.html +++ b/src/main/resources/public/views/fibarodevice.html @@ -2,8 +2,8 @@
  • Bridge Devices
  • Bridge Control
  • Logs
  • -
  • Vera Devices
  • -
  • Vera Scenes
  • +
  • Vera Devices
  • +
  • Vera Scenes
  • Fibaro Scenes
  • Bridge Devices
  • Bridge Control
  • Logs
  • -
  • Vera Devices
  • -
  • Vera Scenes
  • +
  • Vera Devices
  • +
  • Vera Scenes
  • Fibaro Devices
  • + + + + + @@ -158,8 +163,14 @@ + + + ng-click="addFibarotoSettings(newfibaroname, newfibaroip, newfibarousername, newfibaropassword)">Add
    Name IPUsernamePassword Manage
    {{fibaro.name}} {{fibaro.ip}}{{fibaro.username}}*******
    From 31fe05fe2b6910d54de0878ca90a9eb5a2b2c7f8 Mon Sep 17 00:00:00 2001 From: Dmitriy Ponomarev Date: Mon, 25 Sep 2017 03:04:01 +0300 Subject: [PATCH 4/4] fix autorization in requests and many changes. All working, except device statuses. Dont know how to do that. --- .../java/com/bwssystems/HABridge/NamedIP.java | 4 +- .../HABridge/plugins/fibaro/Device.java | 75 ------ .../HABridge/plugins/fibaro/FibaroHome.java | 2 + .../HABridge/plugins/fibaro/FibaroInfo.java | 215 +++++++-------- .../HABridge/plugins/fibaro/ModeType.java | 35 +++ .../HABridge/plugins/fibaro/Room.java | 19 -- .../HABridge/plugins/fibaro/Scene.java | 39 --- .../HABridge/plugins/fibaro/json/Device.java | 108 ++++++++ .../plugins/fibaro/json/DeviceProperties.java | 244 ++++++++++++++++++ .../HABridge/plugins/fibaro/json/Room.java | 43 +++ .../HABridge/plugins/fibaro/json/Scene.java | 100 +++++++ .../plugins/fibaro/json/SceneProperties.java | 11 + .../plugins/fibaro/json/SceneTriggers.java | 14 + .../HABridge/plugins/fibaro/json/Sensor.java | 14 + src/main/resources/public/scripts/app.js | 23 +- .../resources/public/views/fibarodevice.html | 6 +- .../resources/public/views/fibaroscene.html | 2 +- src/main/resources/public/views/system.html | 9 +- 18 files changed, 705 insertions(+), 258 deletions(-) delete mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/ModeType.java delete mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java delete mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Device.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/DeviceProperties.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Room.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Scene.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneProperties.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneTriggers.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Sensor.java diff --git a/src/main/java/com/bwssystems/HABridge/NamedIP.java b/src/main/java/com/bwssystems/HABridge/NamedIP.java index b7162a2..fe8552b 100644 --- a/src/main/java/com/bwssystems/HABridge/NamedIP.java +++ b/src/main/java/com/bwssystems/HABridge/NamedIP.java @@ -2,8 +2,8 @@ package com.bwssystems.HABridge; public class NamedIP { private String name; - private String ip; - private String webhook; + private String ip; + private String webhook; private String port; private String username; private String password; diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java deleted file mode 100644 index 0bfa44d..0000000 --- a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Device.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.bwssystems.HABridge.plugins.fibaro; - -public class Device -{ - public int id; - public String name; - public int roomID; - public String type; - public String baseType; - public boolean enabled; - public boolean visible; - public boolean isPlugin; - public int parentId; - public int remoteGatewayId; - public boolean viewXml; - public boolean configXml; - public Object interfaces; - public Properties properties; - public Object actions; - public int created; - public int modified; - public int sortOrder; - - public class Properties { - public String UIMessageSendTime; - public String autoConfig; - public String date; - public String dead; - public String deviceControlType; - public String deviceIcon; - public String disabled; - public String emailNotificationID; - public String emailNotificationType; - public String endPoint; - public String liliOffCommand; - public String liliOnCommand; - public String log; - public String logTemp; - public String manufacturer; - public String markAsDead; - public String model; - public String nodeID; - public String pollingDeadDevice; - public String pollingTime; - public String pollingTimeNext; - public int pollingTimeSec; - public String productInfo; - public String pushNotificationID; - public String pushNotificationType; - public String remoteGatewayId; - public String requestNodeNeighborStat; - public String requestNodeNeighborStatTimeStemp; - public String requestNodeNeighborState; - public String requestNodeNeighborStateTimeStemp; - public String saveLogs; - public String showChildren; - public String smsNotificationID; - public String smsNotificationType; - public String status; - public String sunriseHour; - public String sunsetHour; - public String userDescription; - public String value; - public String zwaveBuildVersion; - public String zwaveCompany; - public String zwaveInfo; - public String zwaveRegion; - public double zwaveVersion; - } - - public String room; - public String category; - public String fibaroaddress; - public String fibaroname; -} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java index f0c8a26..f68442d 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java @@ -16,6 +16,8 @@ import com.bwssystems.HABridge.NamedIP; import com.bwssystems.HABridge.api.CallItem; import com.bwssystems.HABridge.dao.DeviceDescriptor; import com.bwssystems.HABridge.hue.MultiCommandUtil; +import com.bwssystems.HABridge.plugins.fibaro.json.Device; +import com.bwssystems.HABridge.plugins.fibaro.json.Scene; public class FibaroHome implements Home { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java index bbd6ae2..35293c9 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroInfo.java @@ -1,6 +1,7 @@ package com.bwssystems.HABridge.plugins.fibaro; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; @@ -10,60 +11,133 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.bwssystems.HABridge.NamedIP; +import com.bwssystems.HABridge.plugins.fibaro.json.Device; +import com.bwssystems.HABridge.plugins.fibaro.json.Room; +import com.bwssystems.HABridge.plugins.fibaro.json.Scene; import com.google.gson.Gson; public class FibaroInfo { private static final Logger log = LoggerFactory.getLogger(FibaroInfo.class); - private NamedIP fibaroAddress; - // You can disable it if you want + private final NamedIP fibaroAddress; + private final String fibaroAuth; + private final Gson gson; + + // You can disable it if you want TODO config boolean useSaveLogs = true; // This can be used to exclude some devices from list boolean useUserDescription = true; - boolean removeDigits = true; + boolean replaceTrash = true; boolean scenesWithLiliCommandOnly = true; public FibaroInfo(NamedIP addressName) { super(); fibaroAddress = addressName; + fibaroAuth = "Basic " + new String(Base64.encodeBase64((addressName.getUsername() + ":" + addressName.getPassword()).getBytes())); + gson = new Gson(); + } + + private String request(String request) + { + String result = null; + try + { + URL url = new URL("http://" + fibaroAddress.getIp() + ":" + fibaroAddress.getPort() + request); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Authorization", fibaroAuth); + connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + connection.connect(); + BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); + StringBuilder buffer = new StringBuilder(); + String line; + while((line = br.readLine()) != null) + { + buffer.append(line).append("\n"); + } + br.close(); + result = buffer.toString(); + } + catch(IOException e) + { + log.warn("Error while get getJson: {} ", request, e); + } + return result; + } + + private boolean sendCommand(String request) + { + try + { + URL url = new URL("http://" + fibaroAddress.getIp() + ":" + fibaroAddress.getPort() + request); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Authorization", fibaroAuth); + connection.getResponseMessage(); + } + catch(IOException e) + { + log.warn("Error while get getJson: {} ", request, e); + return false; + } + return true; + } + + private String replaceTrash(String name) + { + String sanitizedName = name.replaceAll("[0-9:/-]", ""); + sanitizedName = name.replaceAll("\\s+", " "); + return sanitizedName.trim(); + } + + private Room[] getRooms() + { + String result = request("/api/rooms"); + Room[] rooms = result == null ? new Room[0] : gson.fromJson(result, Room[].class); + if(replaceTrash) + for(Room r : rooms) + r.setName(replaceTrash(r.getName())); + return rooms; } public Device[] getDevices() { Room[] rooms = getRooms(); - log.debug("Founded: " + rooms.length + ", rooms"); + log.info("Found: " + rooms.length + " rooms"); + + String result = request("/api/devices?enabled=true&visible=true"); + Device[] all_devices = result == null ? new Device[0] : gson.fromJson(result, Device[].class); - Device[] all_devices = getAllDevices(); int count = 0; for(Device d : all_devices) - if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true) + if(d.getRoomID() > 0 && (useSaveLogs ? "true".equals(d.getProperties().getSaveLogs()) : true)) count++; Device[] devices = new Device[count]; int i = 0; for(Device d : all_devices) - if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true) + if(d.getRoomID() > 0 && (useSaveLogs ? "true".equals(d.getProperties().getSaveLogs()) : true)) { - if(useUserDescription && d.properties.userDescription != null && !d.properties.userDescription.isEmpty()) - d.name = d.properties.userDescription; - if(removeDigits) - d.name = replaceDigits(d.name); + if(useUserDescription && d.getProperties().getUserDescription() != null && !d.getProperties().getUserDescription().isEmpty()) + d.setName(d.getProperties().getUserDescription()); + if(replaceTrash) + d.setName(replaceTrash(d.getName())); + devices[i++] = d; for(Room room : rooms) - if(d.roomID == room.id) - { - d.room = room.name.trim(); - d.category = String.valueOf(room.sectionID); // TODO load name of section - } + if(d.getRoomID() == room.getId()) + d.setRoomName(room.getName()); d.fibaroaddress = fibaroAddress.getIp(); + d.fibaroport = fibaroAddress.getPort(); + d.fibaroAuth = fibaroAuth; d.fibaroname = fibaroAddress.getName(); } - log.info("Founded: " + devices.length + " devices"); + log.info("Found: " + devices.length + " devices"); return devices; } @@ -71,105 +145,34 @@ public class FibaroInfo public Scene[] getScenes() { Room[] rooms = getRooms(); + + String result = request("/api/scenes?enabled=true&visible=true"); + Scene[] all_scenes = result == null ? new Scene[0] : gson.fromJson(result, Scene[].class); + int count = 0; - Scene[] scenes = getAllScenes(); - for(Scene s : scenes) - if(!scenesWithLiliCommandOnly || s.liliStartCommand != null && !s.liliStartCommand.isEmpty()) + for(Scene s : all_scenes) + if(!scenesWithLiliCommandOnly || s.getLiliStartCommand() != null && !s.getLiliStartCommand().isEmpty()) count++; - Scene[] result = new Scene[count]; + Scene[] scenes = new Scene[count]; int i = 0; - for(Scene s : scenes) - if(!scenesWithLiliCommandOnly || s.liliStartCommand != null && !s.liliStartCommand.isEmpty()) + for(Scene s : all_scenes) + if(!scenesWithLiliCommandOnly || s.getLiliStartCommand() != null && !s.getLiliStartCommand().isEmpty()) { - result[i++] = s; + if(replaceTrash) + s.setName(replaceTrash(s.getName())); + + scenes[i++] = s; for(Room room : rooms) - if(s.roomID == room.id) - { - s.room = room.name.trim(); - s.category = String.valueOf(room.sectionID); // TODO load name of section - } + if(s.getRoomID() == room.getId()) + s.setRoomName(room.getName()); s.fibaroaddress = fibaroAddress.getIp(); + s.fibaroport = fibaroAddress.getPort(); + s.fibaroAuth = fibaroAuth; s.fibaroname = fibaroAddress.getName(); } - log.info("Founded: " + count + " scenes"); - return result; - } - - private Device[] getAllDevices() - { - String result = request("devices?enabled=true&visible=true"); - if(result == null) - return new Device[0]; - Device[] devices = new Gson().fromJson(result, Device[].class); - return devices; - } - - private Scene[] getAllScenes() - { - String result = request("scenes?enabled=true&visible=true"); - if(result == null) - return new Scene[0]; - Scene[] scenes = new Gson().fromJson(result, Scene[].class); + log.info("Found: " + count + " scenes"); return scenes; } - - private Room[] getRooms() - { - String result = request("rooms"); - if(result == null) - return new Room[0]; - return new Gson().fromJson(result, Room[].class); - } - - private String request(String theUrl) - { - theUrl = "http://" + fibaroAddress.getIp() + "/api/" + theUrl; - String auth = new String(Base64.encodeBase64((fibaroAddress.getUsername() + ":" + fibaroAddress.getPassword()).getBytes())); - java.net.URL url; - java.net.HttpURLConnection connection; - String result = null; - try - { - url = new URL(theUrl); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setRequestProperty("Authorization", "Basic " + auth); - connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); - connection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); - connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36"); - connection.connect(); - BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - StringBuilder buffer = new StringBuilder(); - String line; - while((line = br.readLine()) != null) - buffer.append(line).append("\n"); - br.close(); - result = buffer.toString(); - } - catch(Exception e) - { - log.info("Error while get getJson: " + theUrl); - e.printStackTrace(); - return null; - } - return result; - } - - private String replaceDigits(String name) - { - name = name.replaceAll("1", ""); - name = name.replaceAll("2", ""); - name = name.replaceAll("3", ""); - name = name.replaceAll("4", ""); - name = name.replaceAll("5", ""); - name = name.replaceAll("6", ""); - name = name.replaceAll("7", ""); - name = name.replaceAll("8", ""); - name = name.replaceAll("9", ""); - name = name.replaceAll("0", ""); - name = name.trim(); - return name; - } } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/ModeType.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/ModeType.java new file mode 100644 index 0000000..6732724 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/ModeType.java @@ -0,0 +1,35 @@ +package com.bwssystems.HABridge.plugins.fibaro; + +public enum ModeType { + OFF(0, "Off"), + HEAT(1, "Heat"), + COOL(2, "Cool"), + AUTO(3, "Auto"), + AUX_HEAT(4, "Aux Heat"), + RESUME(5, "Resume"), + FAN_ONLY(6, "Fan Only"), + FURNANCE(7, "Furnace"), + DRY_AIR(8, "Dry Air"), + MOIST_AIR(9, "Moist Air"), + AUTO_CHANGEOVER(10, "Auto Changeover"), + HEAT_ECON(11, "Heat Econ"), + COOL_ECON(12, "Cool Econ"), + AWAY(13, "Away"), + MANUAL(31, "Manual"); + + private int key; + private String label; + + private ModeType(int key, String label) { + this.key = key; + this.label = label; + } + + public int getKey() { + return key; + } + + public String getLabel() { + return label; + } +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java deleted file mode 100644 index 0f7433e..0000000 --- a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Room.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.bwssystems.HABridge.plugins.fibaro; - -public class Room -{ - public int id; - public String name; - public int sectionID; - public String icon; - public Sensor defaultSensors; - public int defaultThermostat; - public int sortOrder; - - public class Sensor - { - public int temperature; - public int humidity; - public int light; - } -} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java deleted file mode 100644 index da4ce01..0000000 --- a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/Scene.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.bwssystems.HABridge.plugins.fibaro; - -public class Scene -{ - public int id; - public String name; - public String type; - public String properties; - public int roomID; - public int iconID; - public String runConfig; - public boolean autostart; - public boolean protectedByPIN; - public boolean killable; - public int maxRunningInstances; - public int runningInstances; - public boolean visible; - public boolean isLua; - public Triggers triggers; - public String liliStartCommand; - public String liliStopCommand; - public int sortOrder; - - public class Triggers { - public Properties[] properties; - public String[] globals; - public String[] events; - } - - public class Properties { - public String id; - public String name; - } - - public String room; - public String category; - public String fibaroaddress; - public String fibaroname; -} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Device.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Device.java new file mode 100644 index 0000000..cd12201 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Device.java @@ -0,0 +1,108 @@ +package com.bwssystems.HABridge.plugins.fibaro.json; + +import com.google.gson.annotations.SerializedName; + +public class Device { + private String roomName; + + @SerializedName("id") + private String id; + + @SerializedName("name") + private String name; + + @SerializedName("roomID") + private int roomID; + + @SerializedName("type") + private String type; + + @SerializedName("baseType") + private String baseType; + + @SerializedName("enabled") + private boolean enabled; + + @SerializedName("visible") + private boolean visible; + + @SerializedName("isPlugin") + private boolean isPlugin; + + @SerializedName("parentId") + private int parentId; + + @SerializedName("remoteGatewayId") + private int remoteGatewayId; + + @SerializedName("viewXml") + private boolean viewXml; + + @SerializedName("configXml") + private boolean configXml; + + @SerializedName("interfaces") + private Object interfaces; + + @SerializedName("properties") + private DeviceProperties properties; + + @SerializedName("actions") + private Object actions; + + @SerializedName("created") + private int created; + + @SerializedName("modified") + private int modified; + + @SerializedName("sortOrder") + private int sortOrder; + + public String getRoomName() { + return roomName; + } + + public void setRoomName(String roomName) { + this.roomName = roomName; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getRoomID() { + return roomID; + } + + public String getType() { + return type; + } + + public DeviceProperties getProperties() { + return properties; + } + + public boolean isThermostat() { + return type.equals("com.fibaro.setPoint") || type.equals("com.fibaro.thermostatDanfoss") + || type.equals("com.fibaro.thermostatHorstmann"); + } + + @Override + public String toString() { + return "{" + id + ", " + name + "}"; + } + + public String fibaroaddress; + public String fibaroport; + public String fibaroAuth; + public String fibaroname; +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/DeviceProperties.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/DeviceProperties.java new file mode 100644 index 0000000..9e68c48 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/DeviceProperties.java @@ -0,0 +1,244 @@ +package com.bwssystems.HABridge.plugins.fibaro.json; + +import com.google.gson.annotations.SerializedName; + +public class DeviceProperties { + @SerializedName("batteryLevel") + private String batteryLevel; + + @SerializedName("UIMessageSendTime") + private String UIMessageSendTime; + + @SerializedName("autoConfig") + private String autoConfig; + + @SerializedName("color") + private String color; + + @SerializedName("date") + private String date; + + @SerializedName("dead") + private String dead; + + @SerializedName("deviceControlType") + private String deviceControlType; + + @SerializedName("deviceIcon") + private String deviceIcon; + + @SerializedName("disabled") + private String disabled; + + @SerializedName("emailNotificationID") + private String emailNotificationID; + + @SerializedName("emailNotificationType") + private String emailNotificationType; + + @SerializedName("endPoint") + private String endPoint; + + @SerializedName("energy") + private String energy; + + @SerializedName("liliOffCommand") + private String liliOffCommand; + + @SerializedName("liliOnCommand") + private String liliOnCommand; + + @SerializedName("log") + private String log; + + @SerializedName("logTemp") + private String logTemp; + + @SerializedName("manufacturer") + private String manufacturer; + + @SerializedName("markAsDead") + private String markAsDead; + + @SerializedName("mode") + private String mode; + + @SerializedName("model") + private String model; + + @SerializedName("nodeID") + private String nodeID; + + @SerializedName("pollingDeadDevice") + private String pollingDeadDevice; + + @SerializedName("pollingTime") + private String pollingTime; + + @SerializedName("pollingTimeNext") + private String pollingTimeNext; + + @SerializedName("pollingTimeSec") + private int pollingTimeSec; + + @SerializedName("power") + private String power; + + @SerializedName("productInfo") + private String productInfo; + + @SerializedName("pushNotificationID") + private String pushNotificationID; + + @SerializedName("pushNotificationType") + private String pushNotificationType; + + @SerializedName("remoteGatewayId") + private String remoteGatewayId; + + @SerializedName("requestNodeNeighborStat") + private String requestNodeNeighborStat; + + @SerializedName("requestNodeNeighborStatTimeStemp") + private String requestNodeNeighborStatTimeStemp; + + @SerializedName("requestNodeNeighborState") + private String requestNodeNeighborState; + + @SerializedName("requestNodeNeighborStateTimeStemp") + private String requestNodeNeighborStateTimeStemp; + + @SerializedName("saveLogs") + private String saveLogs; + + @SerializedName("showChildren") + private String showChildren; + + @SerializedName("smsNotificationID") + private String smsNotificationID; + + @SerializedName("smsNotificationType") + private String smsNotificationType; + + @SerializedName("supportedModes") + private String supportedModes; + + @SerializedName("targetLevel") + private String targetLevel; + + @SerializedName("unit") + private String unit; + + @SerializedName("useTemplate") + private String useTemplate; + + @SerializedName("status") + private String status; + + @SerializedName("sunriseHour") + private String sunriseHour; + + @SerializedName("sunsetHour") + private String sunsetHour; + + @SerializedName("userDescription") + private String userDescription; + + @SerializedName("value") + private String value; + + @SerializedName("zwaveBuildVersion") + private String zwaveBuildVersion; + + @SerializedName("zwaveCompany") + private String zwaveCompany; + + @SerializedName("zwaveInfo") + private String zwaveInfo; + + @SerializedName("zwaveRegion") + private String zwaveRegion; + + @SerializedName("zwaveVersion") + private double zwaveVersion; + + public String getBatteryLevel() { + return batteryLevel; + } + + public String getColor() { + return color; + } + + public String getDeviceControlType() { + return deviceControlType; + } + + public String getEnergy() { + return energy; + } + + public String getPower() { + return power; + } + + public String getTargetLevel() { + return targetLevel; + } + + public String getValue() { + return value; + } + + // --- begin yrWeather plugin --- + @SerializedName("Humidity") + private String Humidity; + + @SerializedName("Pressure") + private String Pressure; + + @SerializedName("Temperature") + private String Temperature; + + @SerializedName("WeatherCondition") + private String WeatherCondition; + + @SerializedName("Wind") + private String Wind; + + public String getHumidity() { + return Humidity; + } + + public String getPressure() { + return Pressure; + } + + public String getSaveLogs() + { + return saveLogs; + } + + public String getTemperature() { + return Temperature; + } + + public String getWeatherCondition() { + return WeatherCondition; + } + + public String getWind() { + return Wind; + } + // --- end yrWeather plugin --- + + public String getUserDescription() + { + return userDescription; + } + + public void setUserDescription(String userDescription) + { + this.userDescription = userDescription; + } +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Room.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Room.java new file mode 100644 index 0000000..5aed4d3 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Room.java @@ -0,0 +1,43 @@ +package com.bwssystems.HABridge.plugins.fibaro.json; + +import com.google.gson.annotations.SerializedName; + +public class Room { + @SerializedName("id") + private int id; + + @SerializedName("name") + private String name; + + @SerializedName("sectionID") + private int sectionID; + + @SerializedName("icon") + private String icon; + + @SerializedName("defaultSensors") + private Sensor defaultSensors; + + @SerializedName("defaultThermostat") + private int defaultThermostat; + + @SerializedName("sortOrder") + private int sortOrder; + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSectionID() + { + return sectionID; + } +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Scene.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Scene.java new file mode 100644 index 0000000..bf8c430 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Scene.java @@ -0,0 +1,100 @@ +package com.bwssystems.HABridge.plugins.fibaro.json; + +import com.google.gson.annotations.SerializedName; + +public class Scene { + private String roomName; + + @SerializedName("id") + private String id; + + @SerializedName("name") + private String name; + + @SerializedName("type") + private String type; + + @SerializedName("properties") + private String properties; + + @SerializedName("roomID") + private int roomID; + + @SerializedName("iconID") + private int iconID; + + @SerializedName("runConfig") + private String runConfig; + + @SerializedName("autostart") + private boolean autostart; + + @SerializedName("protectedByPIN") + private boolean protectedByPIN; + + @SerializedName("killable") + private boolean killable; + + @SerializedName("maxRunningInstances") + private int maxRunningInstances; + + @SerializedName("runningInstances") + private int runningInstances; + + @SerializedName("visible") + private boolean visible; + + @SerializedName("isLua") + private boolean isLua; + + @SerializedName("triggers") + private SceneTriggers triggers; + + @SerializedName("liliStartCommand") + private String liliStartCommand; + + @SerializedName("liliStopCommand") + private String liliStopCommand; + + @SerializedName("sortOrder") + private int sortOrder; + + public String getRoomName() { + return roomName; + } + + public void setRoomName(String roomName) { + this.roomName = roomName; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getRoomID() { + return roomID; + } + + public String getLiliStartCommand() + { + return liliStartCommand; + } + + @Override + public String toString() { + return "{" + id + ", " + name + "}"; + } + + public String fibaroaddress; + public String fibaroport; + public String fibaroAuth; + public String fibaroname; +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneProperties.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneProperties.java new file mode 100644 index 0000000..99ece4e --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneProperties.java @@ -0,0 +1,11 @@ +package com.bwssystems.HABridge.plugins.fibaro.json; + +import com.google.gson.annotations.SerializedName; + +public class SceneProperties { + @SerializedName("id") + private String id; + + @SerializedName("name") + private String name; +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneTriggers.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneTriggers.java new file mode 100644 index 0000000..9b0f761 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/SceneTriggers.java @@ -0,0 +1,14 @@ +package com.bwssystems.HABridge.plugins.fibaro.json; + +import com.google.gson.annotations.SerializedName; + +public class SceneTriggers { + @SerializedName("properties") + private SceneProperties[] properties; + + @SerializedName("globals") + private String[] globals; + + @SerializedName("events") + private String[] events; +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Sensor.java b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Sensor.java new file mode 100644 index 0000000..8875995 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/fibaro/json/Sensor.java @@ -0,0 +1,14 @@ +package com.bwssystems.HABridge.plugins.fibaro.json; + +import com.google.gson.annotations.SerializedName; + +public class Sensor { + @SerializedName("temperature") + private int temperature; + + @SerializedName("humidity") + private int humidity; + + @SerializedName("light") + private int light; +} diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 0b20f4f..05be93b 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -1337,20 +1337,21 @@ app.controller ('SystemController', function ($scope, $location, bridgeService, } } }; - $scope.addFibarotoSettings = function (newfibaroname, newfibaroip, newfibarousername, newfibaropassword) { + $scope.addFibarotoSettings = function (newfibaroname, newfibaroip, newfibaroport, newfibarousername, newfibaropassword) { if($scope.bridge.settings.fibaroaddress === undefined || $scope.bridge.settings.fibaroaddress === null) { $scope.bridge.settings.fibaroaddress = { devices: [] }; } - var newFibaro = {name: newfibaroname, ip: newfibaroip, username: newfibarousername, password: newfibaropassword } + var newFibaro = {name: newfibaroname, ip: newfibaroip, port: newfibaroport, username: newfibarousername, password: newfibaropassword } $scope.bridge.settings.fibaroaddress.devices.push(newFibaro); $scope.newfibaroname = null; $scope.newfibaroip = null; + $scope.newfibaroport = null; $scope.newfibarousername = null; $scope.newfibaropassword = null; }; - $scope.removeFibarotoSettings = function (fibaroname, fibaroip) { + $scope.removeFibarotoSettings = function (fibaroname, fibaroip, fibaroport) { for(var i = $scope.bridge.settings.fibaroaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.fibaroaddress.devices[i].name === fibaroname && $scope.bridge.settings.fibaroaddress.devices[i].ip === fibaroip) { + if($scope.bridge.settings.fibaroaddress.devices[i].name === fibaroname && $scope.bridge.settings.fibaroaddress.devices[i].ip === fibaroip && $scope.bridge.settings.fibaroaddress.devices[i].port === fibaroport) { $scope.bridge.settings.fibaroaddress.devices.splice(i, 1); } } @@ -1988,14 +1989,13 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n $scope.buildDeviceUrls = function (fibarodevice, dim_control, buildonly) { if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) - dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=setValue&arg1=" + dim_control; - else - dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOn"; + dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + fibarodevice.fibaroport + "/api/callAction?deviceID=" + fibarodevice.id + "&name=setValue&arg1=" + dim_control; - onpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOn"; - offpayload = "http://" + fibarodevice.fibaroaddress + ":" + $scope.fibaro.port + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOff"; + onpayload = "http://" + fibarodevice.fibaroaddress + ":" + fibarodevice.fibaroport + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOn"; + offpayload = "http://" + fibarodevice.fibaroaddress + ":" + fibarodevice.fibaroport + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOff"; bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, fibarodevice.id, fibarodevice.name, fibarodevice.fibaroname, "switch", "fibaroDevice", null, null); + bridgeService.state.device.headers = "[{\"name\":\"Authorization\",\"value\":\"" + fibarodevice.fibaroAuth + "\"}]"; $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2004,10 +2004,11 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n }; $scope.buildSceneUrls = function (fibaroscene) { - onpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port + "/api/sceneControl?id=" + fibaroscene.id + "&action=start"; - offpayload = "http://" + fibaroscene.fibaroaddress + ":" + $scope.fibaro.port + "/api/sceneControl?id=" + fibaroscene.id + "&action=stop"; + onpayload = "http://" + fibaroscene.fibaroaddress + ":" + fibaroscene.fibaroport + "/api/sceneControl?id=" + fibaroscene.id + "&action=start"; + offpayload = "http://" + fibaroscene.fibaroaddress + ":" + fibaroscene.fibaroport + "/api/sceneControl?id=" + fibaroscene.id + "&action=stop"; bridgeService.buildUrls(onpayload, null, offpayload, false, fibaroscene.id, fibaroscene.name, fibaroscene.fibaroname, "scene", "fibaroScene", null, null); + bridgeService.state.device.headers = "[{\"name\":\"Authorization\",\"value\":\"" + fibaroscene.fibaroAuth + "\"}]"; $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); diff --git a/src/main/resources/public/views/fibarodevice.html b/src/main/resources/public/views/fibarodevice.html index fe8e513..95e428c 100644 --- a/src/main/resources/public/views/fibarodevice.html +++ b/src/main/resources/public/views/fibarodevice.html @@ -63,9 +63,9 @@ ng-checked="selectAll" ng-click="toggleSelectAll()"> Name Id - Category Room Fibaro + Value Build Actions @@ -78,9 +78,9 @@ ng-click="toggleSelection(fibarodevice.id)"> {{fibarodevice.name}} {{fibarodevice.id}} - {{fibarodevice.category}} - {{fibarodevice.room}} + {{fibarodevice.roomName}} {{fibarodevice.fibaroname}} + {{fibarodevice.properties.value}} diff --git a/src/main/resources/public/views/fibaroscene.html b/src/main/resources/public/views/fibaroscene.html index f8d0dda..c5c35fa 100644 --- a/src/main/resources/public/views/fibaroscene.html +++ b/src/main/resources/public/views/fibaroscene.html @@ -53,7 +53,7 @@ {{$index+1}} {{fibaroscene.name}} {{fibaroscene.id}} - {{fibaroscene.room}} + {{fibaroscene.roomName}} {{fibaroscene.fibaroname}} + ng-click="removeFibarotoSettings(fibaro.name, fibaro.ip, fibaro.port)">Del + @@ -180,7 +185,7 @@ class="form-control" type="password" ng-model="newfibaropassword" placeholder="Fibaro password"> + ng-click="addFibarotoSettings(newfibaroname, newfibaroip, newfibaroport, newfibarousername, newfibaropassword)">Add