Fixed issues with 4beta1

This commit is contained in:
Admin
2016-12-30 15:00:31 -06:00
parent 363fb605a6
commit 9c4eb58739
20 changed files with 182 additions and 124 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>4beta1.1</version>
<version>4beta2</version>
<packaging>jar</packaging>
<name>HA Bridge</name>
@@ -15,6 +15,7 @@
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>

View File

@@ -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<String[]> deviceMapTypes;
@@ -37,7 +35,6 @@ public class DeviceMapTypes {
super();
deviceMapTypes = new ArrayList<String[]>();
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<String[]> 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;
}
}

View File

@@ -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) {

View File

@@ -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) -> {

View File

@@ -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]);
}

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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<String, HalInfo> 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<HalDevice> theResponse = null;
Iterator<String> keys = hals.keySet().iterator();
@@ -92,6 +95,8 @@ public class HalHome implements Home {
}
private Boolean addHalDevices(List<HalDevice> theDeviceList, List<HalDevice> theSourceList, String theKey) {
if(!validHal)
return null;
Iterator<HalDevice> 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<String, HalInfo>();
if(!bridgeSettings.isValidHal())
validHal = bridgeSettings.isValidHal();
log.info("HAL Home created." + (validHal ? "" : " No HAL devices configured."));
if(!validHal)
return null;
hals = new HashMap<String, HalInfo>();
Iterator<NamedIP> theList = bridgeSettings.getHaladdress().getDevices().iterator();
while(theList.hasNext()) {
NamedIP aHal = theList.next();

View File

@@ -40,6 +40,8 @@ public class HarmonyHome implements Home {
@Override
public void closeHome() {
if(!validHarmony)
return;
if(isDevMode || hubs == null)
return;
Iterator<String> 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<HarmonyActivity> getActivities() {
Iterator<String> keys = hubs.keySet().iterator();
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
if(!validHarmony)
return null;
while(keys.hasNext()) {
String key = keys.next();
Iterator<Activity> activities = hubs.get(key).getMyHarmony().getActivities().iterator();
@@ -88,6 +94,8 @@ public class HarmonyHome implements Home {
public List<HarmonyActivity> getCurrentActivities() {
Iterator<String> keys = hubs.keySet().iterator();
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
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<HarmonyDevice> getDevices() {
Iterator<String> keys = hubs.keySet().iterator();
ArrayList<HarmonyDevice> deviceList = new ArrayList<HarmonyDevice>();
if(!validHarmony)
return null;
while(keys.hasNext()) {
String key = keys.next();
Iterator<Device> 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<String, HarmonyServer>();
aGsonHandler =
new GsonBuilder()

View File

@@ -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<String,HomeAssistant>();
aGsonHandler =
new GsonBuilder()
@@ -95,6 +94,8 @@ public class HassHome implements Home {
}
private Boolean addHassDevices(List<HassDevice> theDeviceList, List<State> theSourceList, String theKey) {
if(!validHass)
return null;
Iterator<State> 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<String> keys = hassMap.keySet().iterator();
while(keys.hasNext()) {
String key = keys.next();

View File

@@ -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;
}

View File

@@ -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<String> keys = hues.keySet().iterator();
ArrayList<HueDevice> deviceList = new ArrayList<HueDevice>();
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<String, HueInfo>();
Iterator<NamedIP> 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<String> keys = hues.keySet().iterator();
while(keys.hasNext()) {
String key = keys.next();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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

View File

@@ -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

View File

@@ -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<String, VeraInfo>();
Iterator<NamedIP> theList = bridgeSettings.getVeraAddress().getDevices().iterator();
while(theList.hasNext()) {

View File

@@ -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<len; ++i) {
if (i in self.state.mapTypes) {
s = self.state.mapTypes[i];
if(aMapType == s[0])
return self.state.mapTypes[i];
}
}
return null;
}
this.updateLogLevels = function(logComponents) {
return $http.put(this.state.systemsbase + "/logmgmt/update", logComponents ).then(
function (response) {
@@ -732,6 +755,7 @@ app.service('bridgeService', function ($http, $window, ngToast) {
app.controller('SystemController', function ($scope, $location, $http, $window, bridgeService) {
bridgeService.viewConfigs();
bridgeService.loadBridgeSettings();
$scope.bridge = bridgeService.state;
$scope.optionalbackupname = "";
$scope.bridge.isInControl = false;
@@ -2002,8 +2026,10 @@ app.controller('HassController', function ($scope, $location, $http, bridgeServi
});
app.controller('EditController', function ($scope, $location, $http, bridgeService) {
bridgeService.viewMapTypes();
$scope.bridge = bridgeService.state;
$scope.device = $scope.bridge.device;
$scope.mapTypeSelected = bridgeService.getMapType($scope.device.mapType);
$scope.device_dim_control = "";
$scope.bulk = { devices: [] };
$scope.imgButtonsUrl = "glyphicon glyphicon-plus";
@@ -2016,7 +2042,7 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi
$scope.addDevice = function () {
if($scope.device.name == "" && $scope.device.onUrl == "")
return;
bridgeService.buildUrls($scope.device.onUrl, $scope.device.dimUrl, $scope.device.offUrl, true, null, null, $scope.device.deviceType, null, null, null);
$scope.device.mapType = $scope.mapTypeSelected[0];
bridgeService.addDevice($scope.device).then(
function () {
$scope.clearDevice();

View File

@@ -36,8 +36,7 @@
</div>
<form class="form-horizontal">
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-name">Name
</label>
<label class="col-xs-12 col-sm-2 control-label" for="device-name">Name</label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-name"
@@ -47,20 +46,17 @@
ng-click="addDevice()">Update Bridge Device</button>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-target">Target
</label>
<label class="col-xs-12 col-sm-2 control-label" for="device-target">Target</label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-target"
ng-model="device.targetDevice" placeholder="default">
</div>
<button class="btn btn-primary" ng-click="copyDevice()">Add
Bridge Device</button>
<button class="btn btn-primary" ng-click="copyDevice()">Add Bridge Device</button>
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-type">Device
Type </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-type">Device Type</label>
<div class="col-xs-8 col-sm-7">
<select name="device-type" id="device-type"
@@ -86,31 +82,16 @@
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label"
for="device-map-type">Map Type </label>
for="device-map-type">Map Type</label>
<div class="col-xs-8 col-sm-7">
<select name="device-map-type" id="device-map-type"
ng-model="device.mapType">
<option value="">---Please select---</option>
<!-- not selected / blank option -->
<option value="veraDevice">Vera Device</option>
<option value="veraScene">Vera Scene</option>
<option value="harmonyActivity">Harmony Activity</option>
<option value="harmonyButton">Harmony Button</option>
<option value="nestHomeAway">Nest Home Status</option>
<option value="nestThermoSet">Nest Thermostat</option>
<option value="hueDevice">Hue Device</option>
<option value="halDevice">HAL Device</option>
<option value="halHome">HAL Home Status</option>
<option value="halThermoSet">HAL Thermostat</option>
</select>
<select ng-options="mapType as mapType[1] for mapType in bridge.mapTypes track by mapType[0]" ng-model="mapTypeSelected"></select>
</div>
<button class="btn btn-danger" ng-click="clearDevice()">
Clear Device</button>
<button class="btn btn-danger" ng-click="clearDevice()">Clear Device</button>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-unique-id">Unique Id (used for Hue responses) </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-unique-id">Unique Id (used for Hue responses)</label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-unique-id"
@@ -118,8 +99,7 @@
</div>
</div>
<div ng-if="device.mapType" class="form-group">
<label class="col-xs-12 col-sm-2 control-label" for="device-map-id">Map
ID </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-map-id">Map ID</label>
<div class="col-xs-8 col-sm-7">
<input type="text" class="form-control" id="device-map-id"
@@ -128,8 +108,7 @@
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On
URL </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On URL</label>
<div class="col-xs-8 col-sm-7">
<textarea rows="3" class="form-control" id="device-on-url"
@@ -139,8 +118,7 @@
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-dim-url">Dim
URL </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-dim-url">Dim URL</label>
<div class="col-xs-8 col-sm-7">
<textarea rows="3" class="form-control" id="device-dim-url"
@@ -150,8 +128,7 @@
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-off-url">Off
URL </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-off-url">Off URL</label>
<div class="col-xs-8 col-sm-7">
<textarea rows="3" class="form-control" id="device-off-url"
@@ -161,8 +138,7 @@
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-headers">HTTP
Headers </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-headers">HTTP Headers</label>
<div class="col-xs-8 col-sm-7">
<textarea rows="3" class="form-control" id="device-headers"
@@ -174,7 +150,7 @@
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label"
for="device-http-verb">Http Verb </label>
for="device-http-verb">Http Verb</label>
<div class="col-xs-8 col-sm-7">
<select name="device-http-verb" id="device-http-verb"
@@ -191,7 +167,7 @@
<div ng-if="device.httpVerb" class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label"
for="device-content-type">Content Type </label>
for="device-content-type">Content Type</label>
<div class="col-xs-8 col-sm-7">
<select name="device-content-type" id="device-content-type"

View File

@@ -53,8 +53,7 @@
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-type">Device
Type </label>
<label class="col-xs-12 col-sm-2 control-label" for="device-type">Device Type</label>
<div class="col-xs-8 col-sm-7">
<select name="device-type" id="device-type"
@@ -65,10 +64,28 @@
<option value="UDP">UDP</option>
<option value="TCP">TCP</option>
<option value="exec">Execute Script/Program</option>
<option value="switch">Switch</option>
<option value="scene">Scene</option>
<option value="macro">Macro</option>
<option value="group">Group</option>
<option value="activity">Activity</option>
<option value="button">Button</option>
<option value="thermo">Thermo</option>
<option value="passthru">Pass Thru</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-map-type">Device Map
Type </label>
<div class="col-xs-8 col-sm-7">
<select ng-options="mapType as mapType[1] for mapType in bridge.mapTypes track by mapType[0]" ng-model="mapTypeSelected"></select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On