Added Home control, Thermostat and other enhancements.

This commit is contained in:
Admin
2016-05-25 16:09:29 -05:00
parent 7f816b03d5
commit 6b4693eaaf
8 changed files with 258 additions and 12 deletions

View File

@@ -395,7 +395,7 @@ public class HueMulator implements HueErrorStringSet {
theHeaders = new Gson().fromJson(device.getHeaders(), NameValue[].class);
responseString = this.formatSuccessHueResponse(state, request.body(), stateHasOn, lightId);
if(device.getDeviceType().toLowerCase().contains("hue") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("hueDevice")))
if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("hueDevice")))
{
if(myHueHome != null) {
url = device.getOnUrl();
@@ -460,7 +460,7 @@ public class HueMulator implements HueErrorStringSet {
}
if(device.getDeviceType().toLowerCase().contains("activity") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyActivity")))
if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyActivity")))
{
log.debug("executing HUE api request to change activity to Harmony: " + url);
if(myHarmonyHome != null)
@@ -480,7 +480,7 @@ public class HueMulator implements HueErrorStringSet {
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Should not get here, no harmony configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
}
}
else if(device.getDeviceType().toLowerCase().contains("button") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyButton")))
else if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyButton")))
{
log.debug("executing HUE api request to button press(es) to Harmony: " + url);
if(myHarmonyHome != null)
@@ -510,7 +510,7 @@ public class HueMulator implements HueErrorStringSet {
}
}
else if(device.getDeviceType().toLowerCase().contains("home") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestHomeAway")))
else if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestHomeAway")))
{
log.debug("executing HUE api request to set away for nest home: " + url);
if(theNest == null)
@@ -523,7 +523,7 @@ public class HueMulator implements HueErrorStringSet {
theNest.getHome(homeAway.getName()).setAway(homeAway.getAway());
}
}
else if(device.getDeviceType().toLowerCase().contains("thermo") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestThermoSet")))
else if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestThermoSet")))
{
log.debug("executing HUE api request to set thermostat for nest: " + url);
if(theNest == null)

View File

@@ -0,0 +1,15 @@
package com.bwssystems.hal;
import java.util.List;
public class HVACElements {
private List<HVACName> HVACElements;
public List<HVACName> getHVACElements() {
return HVACElements;
}
public void setHVACElements(List<HVACName> hVACElements) {
HVACElements = hVACElements;
}
}

View File

@@ -0,0 +1,13 @@
package com.bwssystems.hal;
public class HVACName {
private String HVACName;
public String getHVACName() {
return HVACName;
}
public void setHVACName(String hVACName) {
HVACName = hVACName;
}
}

View File

@@ -60,6 +60,16 @@ public class HalHome {
addHalDevices(deviceList, theResponse, key);
else
log.warn("Cannot get custom for Hal with name: " + key);
theResponse = hals.get(key).getHVAC();
if(theResponse != null)
addHalDevices(deviceList, theResponse, key);
else
log.warn("Cannot get HVAC for Hal with name: " + key);
theResponse = hals.get(key).getHome(key);
if(theResponse != null)
addHalDevices(deviceList, theResponse, key);
else
log.warn("Cannot get HVAC for Hal with name: " + key);
}
return deviceList;
}

View File

@@ -20,12 +20,15 @@ import com.google.gson.Gson;
public class HalInfo {
private static final Logger log = LoggerFactory.getLogger(HalInfo.class);
private static final String DEVICE_REQUEST = "/DeviceData!DeviceCmd=GetNames!DeviceType=";
private static final String HVAC_REQUEST = "/HVACData!HVACCmd=GetNames";
private static final String TOKEN_REQUEST = "?Token=";
private static final String LIGHT_REQUEST = "Light";
private static final String APPL_REQUEST = "Appl";
private static final String VIDEO_REQUEST = "Video";
// private static final String VIDEO_REQUEST = "Video";
private static final String THEATRE_REQUEST = "Theatre";
private static final String CUSTOM_REQUEST = "Custom";
private static final String HVAC_TYPE = "HVAC";
private static final String HOME_TYPE = "HOME";
private HttpClient httpClient;
private NamedIP halAddress;
private String theToken;
@@ -53,6 +56,20 @@ public class HalInfo {
return getHalDevices(DEVICE_REQUEST + CUSTOM_REQUEST + TOKEN_REQUEST, CUSTOM_REQUEST);
}
public List<HalDevice> getHVAC() {
return getHalHVAC(HVAC_REQUEST + TOKEN_REQUEST, HVAC_TYPE);
}
public List<HalDevice> getHome(String theDeviceName) {
List<HalDevice> deviceList = null;
deviceList = new ArrayList<HalDevice>();
HalDevice aNewHalDevice = new HalDevice();
aNewHalDevice.setHaldevicetype(HOME_TYPE);
aNewHalDevice.setHaldevicename(theDeviceName);
deviceList.add(aNewHalDevice);
return deviceList;
}
private List<HalDevice> getHalDevices(String apiType, String deviceType) {
DeviceElements theHalApiResponse = null;
List<HalDevice> deviceList = null;
@@ -92,6 +109,45 @@ public class HalInfo {
return deviceList;
}
private List<HalDevice> getHalHVAC(String apiType, String deviceType) {
HVACElements theHalApiResponse = null;
List<HalDevice> deviceList = null;
String theUrl = null;
String theData;
theUrl = "http://" + halAddress.getIp() + apiType + theToken;
theData = doHttpGETRequest(theUrl);
if(theData != null) {
log.debug("GET HalApiResponse - data: " + theData);
theHalApiResponse = new Gson().fromJson(theData, HVACElements.class);
if(theHalApiResponse.getHVACElements() == null) {
StatusDescription theStatus = new Gson().fromJson(theData, StatusDescription.class);
if(theStatus.getStatus() == null) {
log.warn("Cannot get an devices for type " + deviceType + " for hal " + halAddress.getName() + " as response is not parsable.");
}
else {
log.warn("Cannot get an devices for type " + deviceType + " for hal " + halAddress.getName() + ". Status: " + theStatus.getStatus() + ", with description: " + theStatus.getDescription());
}
return deviceList;
}
deviceList = new ArrayList<HalDevice>();
Iterator<HVACName> theDeviceNames = theHalApiResponse.getHVACElements().iterator();
while(theDeviceNames.hasNext()) {
HVACName theDevice = theDeviceNames.next();
HalDevice aNewHalDevice = new HalDevice();
aNewHalDevice.setHaldevicetype(deviceType);
aNewHalDevice.setHaldevicename(theDevice.getHVACName());
deviceList.add(aNewHalDevice);
}
}
else {
log.warn("Get Hal device types " + deviceType + " for " + halAddress.getName() + " - returned null, no data.");
}
return deviceList;
}
// This function executes the url against the hal
protected String doHttpGETRequest(String url) {
String theContent = null;