diff --git a/pom.xml b/pom.xml index c25a20e..e34ba1f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 4beta1.1 + 4beta2 jar HA Bridge @@ -15,6 +15,7 @@ 1.8 1.8 1.8 + UTF-8 diff --git a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java index ae456cd..79edfc3 100644 --- a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java +++ b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java @@ -4,32 +4,30 @@ import java.util.ArrayList; public class DeviceMapTypes { - public final static String[] CUSTOM_DEVICE = { "custom", "Custom", "none"}; - public final static String[] VERA_DEVICE = { "veraDevice", "Vera Device", "vera"}; - public final static String[] VERA_SCENE = { "veraScene", "Vera Scene", "vera"}; - public final static String[] HARMONY_ACTIVITY = { "harmonyActivity", "Harmony Activity", "harmony"}; - public final static String[] HARMONY_BUTTON = { "harmonyButton", "Harmony Button", "harmony"}; - public final static String[] NEST_HOMEAWAY = { "nestHomeAway", "Nest Home Status", "nest"}; - public final static String[] NEST_THERMO_SET = { "nestThermoSet", "Nest Thermostat", "nest"}; - public final static String[] HUE_DEVICE = { "hueDevice", "Hue Device", "hue"}; - public final static String[] HAL_DEVICE = { "halDevice", "HAL Device", "hal"}; - public final static String[] HAL_BUTTON = { "halButton", "HAL Button", "hal"}; - public final static String[] HAL_HOME = { "halHome", "HAL Home Status", "hal"}; - public final static String[] HAL_THERMO_SET = { "halThermoSet", "HAL Thermostat", "hal"}; - public final static String[] MQTT_MESSAGE = { "mqttMessage", "MQTT Message", "mqtt"}; - public final static String[] EXEC_DEVICE = { "exec", "Execute Script/Program", "command"}; - public final static String[] CMD_DEVICE = { "cmdDevice", "Execute Command/Script/Program", "command"}; - public final static String[] HASS_DEVICE = { "hassDevice", "HomeAssistant Device", "hass"}; - public final static String[] TCP_DEVICE = { "tcpDevice", "TCP Device", "none"}; - public final static String[] TCP_DEVICE_COMPAT = { "TCP", "TCP Device", "none"}; - public final static String[] UDP_DEVICE = { "udpDevice", "UDP Device", "none"}; - public final static String[] UDP_DEVICE_COMPAT = { "UDP", "UDP Device", "none"}; - public final static String[] HTTP_DEVICE = { "httpDevice", "HTTP Device", "none"}; - public final static String[] DEFAULT_DEVICE = { "udpDevice", "Default Device", "none"}; + public final static String[] CUSTOM_DEVICE = { "custom", "Custom"}; + public final static String[] VERA_DEVICE = { "veraDevice", "Vera Device"}; + public final static String[] VERA_SCENE = { "veraScene", "Vera Scene"}; + public final static String[] HARMONY_ACTIVITY = { "harmonyActivity", "Harmony Activity"}; + public final static String[] HARMONY_BUTTON = { "harmonyButton", "Harmony Button"}; + public final static String[] NEST_HOMEAWAY = { "nestHomeAway", "Nest Home Status"}; + public final static String[] NEST_THERMO_SET = { "nestThermoSet", "Nest Thermostat"}; + public final static String[] HUE_DEVICE = { "hueDevice", "Hue Device"}; + public final static String[] HAL_DEVICE = { "halDevice", "HAL Device"}; + public final static String[] HAL_BUTTON = { "halButton", "HAL Button"}; + public final static String[] HAL_HOME = { "halHome", "HAL Home Status"}; + public final static String[] HAL_THERMO_SET = { "halThermoSet", "HAL Thermostat"}; + public final static String[] MQTT_MESSAGE = { "mqttMessage", "MQTT Message"}; + public final static String[] EXEC_DEVICE_COMPAT = { "exec", "Execute Script/Program"}; + public final static String[] CMD_DEVICE = { "cmdDevice", "Execute Command/Script/Program"}; + public final static String[] HASS_DEVICE = { "hassDevice", "HomeAssistant Device"}; + public final static String[] TCP_DEVICE = { "tcpDevice", "TCP Device"}; + public final static String[] TCP_DEVICE_COMPAT = { "TCP", "TCP Device"}; + public final static String[] UDP_DEVICE = { "udpDevice", "UDP Device"}; + public final static String[] UDP_DEVICE_COMPAT = { "UDP", "UDP Device"}; + public final static String[] HTTP_DEVICE = { "httpDevice", "HTTP Device"}; public final static int typeIndex = 0; public final static int displayIndex = 1; - public final static int resourceIndex = 1; ArrayList deviceMapTypes; @@ -37,7 +35,6 @@ public class DeviceMapTypes { super(); deviceMapTypes = new ArrayList(); deviceMapTypes.add(CMD_DEVICE); - deviceMapTypes.add(DEFAULT_DEVICE); deviceMapTypes.add(HAL_DEVICE); deviceMapTypes.add(HAL_HOME); deviceMapTypes.add(HAL_THERMO_SET); @@ -61,10 +58,23 @@ public class DeviceMapTypes { public static int getDisplayIndex() { return displayIndex; } - public static int getResourceindex() { - return resourceIndex; - } public ArrayList getDeviceMapTypes() { return deviceMapTypes; } + + public Boolean validateType(String type) { + if(type == null || type.trim().isEmpty()) + return false; + for(String[] mapType : deviceMapTypes) { + if(type.trim().contentEquals(mapType[typeIndex])) + return true; + } + if(type.trim().contentEquals(EXEC_DEVICE_COMPAT[typeIndex])) + return true; + if(type.trim().contentEquals(TCP_DEVICE_COMPAT[typeIndex])) + return true; + if(type.trim().contentEquals(UDP_DEVICE_COMPAT[typeIndex])) + return true; + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/HomeManager.java b/src/main/java/com/bwssystems/HABridge/HomeManager.java index f2a1cb0..84a0ee1 100644 --- a/src/main/java/com/bwssystems/HABridge/HomeManager.java +++ b/src/main/java/com/bwssystems/HABridge/HomeManager.java @@ -31,37 +31,37 @@ public class HomeManager { Home aHome = null; //setup the harmony connection if available aHome = new HarmonyHome(bridgeSettings); - resourceList.put(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex], aHome); - resourceList.put(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex], aHome); //setup the nest connection if available aHome = new NestHome(bridgeSettings); - resourceList.put(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.NEST_THERMO_SET[DeviceMapTypes.typeIndex], aHome); //setup the hue passtrhu configuration if available aHome = new HueHome(bridgeSettings); - resourceList.put(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex], aHome); //setup the hal configuration if available aHome = new HalHome(bridgeSettings); - resourceList.put(DeviceMapTypes.HAL_DEVICE[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.HAL_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HAL_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HAL_BUTTON[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HAL_HOME[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HAL_THERMO_SET[DeviceMapTypes.typeIndex], aHome); //setup the mqtt handlers if available aHome = new MQTTHome(bridgeSettings); - resourceList.put(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.typeIndex], aHome); //setup the HomeAssistant configuration if available aHome = new HassHome(bridgeSettings); - resourceList.put(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.typeIndex], aHome); //setup the command execution Home aHome = new CommandHome(bridgeSettings); - homeList.put(DeviceMapTypes.EXEC_DEVICE[DeviceMapTypes.typeIndex], aHome); + homeList.put(DeviceMapTypes.EXEC_DEVICE_COMPAT[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.CMD_DEVICE[DeviceMapTypes.typeIndex], aHome); //setup the http handler Home aHome = new HTTPHome(bridgeSettings); @@ -69,7 +69,6 @@ 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.DEFAULT_DEVICE[DeviceMapTypes.typeIndex], aHome); //setup the tcp handler Home aHome = new TCPHome(bridgeSettings); homeList.put(DeviceMapTypes.TCP_DEVICE[DeviceMapTypes.typeIndex], aHome); @@ -80,7 +79,8 @@ public class HomeManager { homeList.put(DeviceMapTypes.UDP_DEVICE_COMPAT[DeviceMapTypes.typeIndex], aHome); aHome = new VeraHome(bridgeSettings); - resourceList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.resourceIndex], aHome); + resourceList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome); + resourceList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome); } public Home findHome(String type) { diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index cf71775..4a90163 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -157,60 +157,60 @@ public class DeviceResource { get (API_CONTEXT + "/vera/devices", "application/json", (request, response) -> { log.debug("Get vera devices"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/vera/scenes", "application/json", (request, response) -> { log.debug("Get vera scenes"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/harmony/activities", "application/json", (request, response) -> { log.debug("Get harmony activities"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/harmony/show", "application/json", (request, response) -> { log.debug("Get harmony current activity"); - return homeManager.findResource(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.resourceIndex]).getItems("current_activity"); + return homeManager.findResource(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex]).getItems("current_activity"); }, new JsonTransformer()); get (API_CONTEXT + "/harmony/devices", "application/json", (request, response) -> { log.debug("Get harmony devices"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/nest/items", "application/json", (request, response) -> { log.debug("Get nest items"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/hue/devices", "application/json", (request, response) -> { log.debug("Get hue items"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/hal/devices", "application/json", (request, response) -> { log.debug("Get hal items"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.HAL_DEVICE[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.HAL_DEVICE[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.HAL_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.HAL_DEVICE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/mqtt/devices", "application/json", (request, response) -> { log.debug("Get MQTT brokers"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.MQTT_MESSAGE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/hass/devices", "application/json", (request, response) -> { log.debug("Get HomeAssistant Clients"); response.status(HttpStatus.SC_OK); - return homeManager.findResource(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.resourceIndex]).getItems(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.typeIndex]); + return homeManager.findResource(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); get (API_CONTEXT + "/map/types", "application/json", (request, response) -> { diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 7485350..76e616f 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -52,9 +52,11 @@ public class HueMulator { private HueHome myHueHome; private BridgeSettingsDescriptor bridgeSettings; private Gson aGsonHandler; + private DeviceMapTypes validMapTypes; public HueMulator(BridgeSettingsDescriptor theBridgeSettings, DeviceRepository aDeviceRepository, HomeManager aHomeManager) { repository = aDeviceRepository; + validMapTypes = new DeviceMapTypes(); bridgeSettings = theBridgeSettings; homeManager= aHomeManager; myHueHome = (HueHome) homeManager.findHome(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]); @@ -780,11 +782,11 @@ public class HueMulator { else aMultiUtil.setSetCount(1); // code for backwards compatibility - if((callItems[i].getType() == null || callItems[i].getType().trim().length() == 0)) { - if(device.getMapType() != null && device.getMapType().length() > 0) - callItems[i].setType(device.getMapType()); - else if(device.getDeviceType() != null && device.getDeviceType().length() > 0) - callItems[i].setType(device.getDeviceType()); + if((callItems[i].getType() == null || callItems[i].getType().trim().isEmpty())) { + if(validMapTypes.validateType(device.getMapType())) + callItems[i].setType(device.getMapType().trim()); + else if(validMapTypes.validateType(device.getDeviceType())) + callItems[i].setType(device.getDeviceType().trim()); else callItems[i].setType(DeviceMapTypes.CUSTOM_DEVICE[DeviceMapTypes.typeIndex]); } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java b/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java index a35ea5e..df08034 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java @@ -154,7 +154,6 @@ public class NestHome implements com.bwssystems.HABridge.Home { + lightId + "state\"}}]"; } } - log.info("device handler not implemented"); return responseString; } @@ -165,10 +164,9 @@ public class NestHome implements com.bwssystems.HABridge.Home { nestItems = null; validNest = bridgeSettings.isValidNest(); aGsonHandler = null; + log.info("Nest Home created." + (validNest ? "" : " No Nest configured.")); - if(!validNest) { - log.debug("not a valid nest"); - } else { + if(validNest) { aGsonHandler = new GsonBuilder().create(); isFarenheit = bridgeSettings.isFarenheit(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java b/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java index ba2e621..85b6508 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java @@ -79,7 +79,7 @@ public class CommandHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { - // noop + log.info("Command Home for system program execution created."); return this; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java index ba70c5e..4b23433 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hal/HalHome.java @@ -21,6 +21,7 @@ import com.bwssystems.HABridge.hue.MultiCommandUtil; public class HalHome implements Home { private static final Logger log = LoggerFactory.getLogger(HalHome.class); private Map hals; + private Boolean validHal; public HalHome(BridgeSettingsDescriptor bridgeSettings) { super(); @@ -29,6 +30,8 @@ public class HalHome implements Home { @Override public Object getItems(String type) { + if(!validHal) + return null; log.debug("consolidating devices for hues"); List theResponse = null; Iterator keys = hals.keySet().iterator(); @@ -92,6 +95,8 @@ public class HalHome implements Home { } private Boolean addHalDevices(List theDeviceList, List theSourceList, String theKey) { + if(!validHal) + return null; Iterator devices = theSourceList.iterator(); while(devices.hasNext()) { HalDevice theDevice = devices.next(); @@ -115,9 +120,11 @@ public class HalHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { - hals = new HashMap(); - if(!bridgeSettings.isValidHal()) + validHal = bridgeSettings.isValidHal(); + log.info("HAL Home created." + (validHal ? "" : " No HAL devices configured.")); + if(!validHal) return null; + hals = new HashMap(); Iterator theList = bridgeSettings.getHaladdress().getDevices().iterator(); while(theList.hasNext()) { NamedIP aHal = theList.next(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java b/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java index f4afc37..366f9ec 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/harmony/HarmonyHome.java @@ -40,6 +40,8 @@ public class HarmonyHome implements Home { @Override public void closeHome() { + if(!validHarmony) + return; if(isDevMode || hubs == null) return; Iterator keys = hubs.keySet().iterator(); @@ -52,6 +54,8 @@ public class HarmonyHome implements Home { } public HarmonyHandler getHarmonyHandler(String aName) { + if(!validHarmony) + return null; HarmonyHandler aHandler = null; if(aName == null || aName.equals("")) { aName = "default"; @@ -73,6 +77,8 @@ public class HarmonyHome implements Home { public List getActivities() { Iterator keys = hubs.keySet().iterator(); ArrayList activityList = new ArrayList(); + if(!validHarmony) + return null; while(keys.hasNext()) { String key = keys.next(); Iterator activities = hubs.get(key).getMyHarmony().getActivities().iterator(); @@ -88,6 +94,8 @@ public class HarmonyHome implements Home { public List getCurrentActivities() { Iterator keys = hubs.keySet().iterator(); ArrayList activityList = new ArrayList(); + if(!validHarmony) + return null; while(keys.hasNext()) { String key = keys.next(); Activity theActivity = hubs.get(key).getMyHarmony().getCurrentActivity(); @@ -101,6 +109,8 @@ public class HarmonyHome implements Home { public List getDevices() { Iterator keys = hubs.keySet().iterator(); ArrayList deviceList = new ArrayList(); + if(!validHarmony) + return null; while(keys.hasNext()) { String key = keys.next(); Iterator devices = hubs.get(key).getMyHarmony().getDevices().iterator(); @@ -195,9 +205,8 @@ public class HarmonyHome implements Home { public Home createHome(BridgeSettingsDescriptor bridgeSettings) { isDevMode = Boolean.parseBoolean(System.getProperty("dev.mode", "false")); validHarmony = bridgeSettings.isValidHarmony(); - if(!validHarmony && !isDevMode) { - log.debug("No valid Harmony config"); - } else { + log.info("Harmony Home created." + (validHarmony ? "" : " No Harmony devices configured.") + (isDevMode ? " DevMode is set." : "")); + if(validHarmony || isDevMode) { hubs = new HashMap(); aGsonHandler = new GsonBuilder() diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java index eacf1e9..8f24df2 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java @@ -37,9 +37,8 @@ public class HassHome implements Home { hassMap = null; aGsonHandler = null; validHass = bridgeSettings.isValidHass(); - if(!validHass){ - log.debug("not a valid hass"); - } else { + log.info("HomeAssistant Home created." + (validHass ? "" : " No HomeAssistants configured.")); + if(validHass) { hassMap = new HashMap(); aGsonHandler = new GsonBuilder() @@ -95,6 +94,8 @@ public class HassHome implements Home { } private Boolean addHassDevices(List theDeviceList, List theSourceList, String theKey) { + if(!validHass) + return null; Iterator devices = theSourceList.iterator(); while(devices.hasNext()) { State theDevice = devices.next(); @@ -155,6 +156,8 @@ public class HassHome implements Home { @Override public void closeHome() { + if(!validHass) + return; Iterator keys = hassMap.keySet().iterator(); while(keys.hasNext()) { String key = keys.next(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java index ecc1ed9..abde510 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHome.java @@ -80,6 +80,7 @@ public class HTTPHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { anHttpHandler = new HTTPHandler(); + log.info("Http Home created."); return this; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java index 79a1307..8ce9721 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java @@ -35,6 +35,8 @@ public class HueHome implements Home { @Override public Object getItems(String type) { log.debug("consolidating devices for hues"); + if(!validHue) + return null; Iterator keys = hues.keySet().iterator(); ArrayList deviceList = new ArrayList(); while(keys.hasNext()) { @@ -66,6 +68,8 @@ public class HueHome implements Home { } public DeviceResponse getHueDeviceInfo(HueDeviceIdentifier deviceId, DeviceDescriptor device) { + if(!validHue) + return null; DeviceResponse deviceResponse = null; HueInfo aHueInfo = hues.get(device.getTargetDevice()); deviceResponse = aHueInfo.getHueDeviceInfo(deviceId.getDeviceId(), device); @@ -75,6 +79,8 @@ public class HueHome implements Home { @Override public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount, DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) { + if(!validHue) + return null; String responseString = null; HueDeviceIdentifier deviceId = aGsonHandler.fromJson(anItem.getItem(), HueDeviceIdentifier.class); if(deviceId.getHueName() == null || deviceId.getHueName().isEmpty()) @@ -106,9 +112,8 @@ public class HueHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { validHue = bridgeSettings.isValidHue(); - if(!validHue) { - log.debug("No Hue Configuration"); - } else { + log.info("Hue passthru Home created." + (validHue ? "" : " No Hue passtrhu systems configured.")); + if(validHue) { hues = new HashMap(); Iterator theList = bridgeSettings.getHueaddress().getDevices().iterator(); while(theList.hasNext()) { @@ -122,6 +127,8 @@ public class HueHome implements Home { @Override public void closeHome() { + if(!validHue) + return; Iterator keys = hues.keySet().iterator(); while(keys.hasNext()) { String key = keys.next(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hue/HueInfo.java b/src/main/java/com/bwssystems/HABridge/plugins/hue/HueInfo.java index f545f1f..83604f0 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hue/HueInfo.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hue/HueInfo.java @@ -36,6 +36,7 @@ public class HueInfo { } public HueApiResponse getHueApiResponse() { + log.debug("Get hue info to hue " + hueAddress.getName()); HueApiResponse theHueApiResponse = null; if(hueAddress.getUsername() == null) { @@ -103,7 +104,7 @@ public class HueInfo { HttpClient anHttpClient = httpClient.getHttpClient(); try { response = anHttpClient.execute(postRequest); - log.debug("POST execute on URL responded: " + response.getStatusLine().getStatusCode()); + log.debug("registerWithHue - POST execute on " + hueAddress.getName() + "URL responded: " + response.getStatusLine().getStatusCode()); if(response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300){ String theBody = EntityUtils.toString(response.getEntity()); log.debug("registerWithHue response data: " + theBody); @@ -127,6 +128,7 @@ public class HueInfo { } public DeviceResponse getHueDeviceInfo(String hueDeviceId, DeviceDescriptor device) { + log.debug("Get hue device info to "+ hueAddress.getName() + " passthru id " + hueDeviceId); String responseString = null; DeviceResponse deviceResponse = null; if(hueAddress.getUsername() == null) @@ -157,6 +159,7 @@ public class HueInfo { } public String changeState(HueDeviceIdentifier deviceId, String lightId, String body) { + log.debug("Changing state for ha-bridge id " + lightId + " to " + deviceId.getHueName() + " passthru id " + deviceId.getDeviceId() + " with state " + body ); String responseString = null; if(hueAddress.getUsername() == null) registerWithHue(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java b/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java index d80b7cb..7a6b335 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java @@ -117,9 +117,8 @@ public class MQTTHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { validMqtt = bridgeSettings.isValidMQTT(); - if(!validMqtt) { - log.debug("No MQTT configuration"); - } else { + log.info("MQTT Home created." + (validMqtt ? "" : " No MQTT Clients configured.")); + if(validMqtt) { aGsonHandler = new GsonBuilder() .create(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java index 24916cf..b6096cf 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/tcp/TCPHome.java @@ -88,8 +88,8 @@ public class TCPHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { - // noop - return null; + log.info("TCP Home created."); + return this; } @Override diff --git a/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java b/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java index 02a0482..01af52a 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/udp/UDPHome.java @@ -87,8 +87,8 @@ public class UDPHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { - // TODO Auto-generated method stub - return null; + log.info("UDP Home created."); + return this; } @Override diff --git a/src/main/java/com/bwssystems/HABridge/plugins/vera/VeraHome.java b/src/main/java/com/bwssystems/HABridge/plugins/vera/VeraHome.java index cfe2a79..afc5b8b 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/vera/VeraHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/vera/VeraHome.java @@ -94,9 +94,8 @@ public class VeraHome implements Home { @Override public Home createHome(BridgeSettingsDescriptor bridgeSettings) { validVera = bridgeSettings.isValidVera(); - if(!validVera) { - log.debug("No valid veras"); - } else { + log.info("Vera Home created." + (validVera ? "" : " No Veras configured.")); + if(validVera) { veras = new HashMap(); Iterator theList = bridgeSettings.getVeraAddress().getDevices().iterator(); while(theList.hasNext()) { diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index ab19b79..ee39270 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -51,7 +51,8 @@ app.config(function ($routeProvider) { app.run( function (bridgeService) { bridgeService.loadBridgeSettings(); - bridgeService.getHABridgeVersion(); + bridgeService.getHABridgeVersion(); + bridgeService.viewMapTypes(); }); String.prototype.replaceAll = function(search, replace) @@ -68,7 +69,7 @@ String.prototype.replaceAll = function(search, replace) app.service('bridgeService', function ($http, $window, ngToast) { var self = this; - this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: [], mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, habridgeversion: ""}; + this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/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, habridgeversion: ""}; this.displayWarn = function(errorTitle, error) { var toastContent = errorTitle; @@ -384,6 +385,28 @@ app.service('bridgeService', function ($http, $window, ngToast) { ); }; + this.viewMapTypes = function () { + return $http.get(this.state.base + "/map/types").then( + function (response) { + self.state.mapTypes = response.data; + }, + function (error) { + self.displayWarn("Get mapTypes Error: ", error); + } + ); + }; + + this.getMapType = function(aMapType) { + var i, s, len = self.state.mapTypes.length; + for (i=0; i - Name - + Name Update Bridge Device - Target - + Target - Add - Bridge Device + Add Bridge Device - Device - Type + Device Type Map Type + for="device-map-type">Map Type - - ---Please select--- - - Vera Device - Vera Scene - Harmony Activity - Harmony Button - Nest Home Status - Nest Thermostat - Hue Device - HAL Device - HAL Home Status - HAL Thermostat - + - - Clear Device + Clear Device - Unique Id (used for Hue responses) + Unique Id (used for Hue responses) - Map - ID + Map ID - On - URL + On URL - Dim - URL + Dim URL - Off - URL + Off URL - HTTP - Headers + HTTP Headers Http Verb + for="device-http-verb">Http Verb Content Type + for="device-content-type">Content Type - Device - Type + Device Type UDP TCP Execute Script/Program + Switch + Scene + Macro + Group + Activity + Button + Thermo + Pass Thru + + + Device Map + Type + + + + + + On