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

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>2.0.7-hal-b</version>
<version>2.0.7-hal-c</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

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;

View File

@@ -1429,6 +1429,118 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
};
$scope.buildHALHomeUrls = function (haldevice) {
bridgeService.clearDevice();
$scope.device.deviceType = "home";
$scope.device.name = haldevice.haldevicename;
$scope.device.targetDevice = haldevice.halname;
$scope.device.mapType = "halHome";
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname + "-HomeAway";
$scope.device.onUrl = "http://" + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Home?Token=" + $scope.bridge.settings.haltoken;
$scope.device.offUrl = "http://" + haldevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Away?Token=" + $scope.bridge.settings.haltoken;
};
$scope.buildHALHeatUrls = function (haldevice) {
bridgeService.clearDevice();
$scope.device.deviceType = "thermo";
$scope.device.name = haldevice.haldevicename + " Heat";
$scope.device.targetDevice = haldevice.halname;
$scope.device.mapType = "HALThermoSet";
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname + "-SetHeat";
$scope.device.onUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Heat?Token="
+ $scope.bridge.settings.haltoken;
$scope.device.dimUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Heat!HeatSpValue=${intensity.percent}?Token="
+ $scope.bridge.settings.haltoken;
$scope.device.offUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Off?Token="
};
$scope.buildHALCoolUrls = function (haldevice) {
bridgeService.clearDevice();
$scope.device.deviceType = "thermo";
$scope.device.name = haldevice.haldevicename + " Cool";
$scope.device.targetDevice = haldevice.halname;
$scope.device.mapType = "HALThermoSet";
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname + "-SetCool";
$scope.device.onUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Cool?Token="
+ $scope.bridge.settings.haltoken;
$scope.device.dimUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Cool!CoolSpValue=${intensity.percent}?Token="
+ $scope.bridge.settings.haltoken;
$scope.device.offUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Off?Token="
};
$scope.buildHALAutoUrls = function (haldevice) {
bridgeService.clearDevice();
$scope.device.deviceType = "thermo";
$scope.device.name = haldevice.haldevicename + " Auto";
$scope.device.targetDevice = haldevice.halname;
$scope.device.mapType = "HALThermoSet";
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname + "-SetAuto";
$scope.device.onUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Auto?Token="
+ $scope.bridge.settings.haltoken;
$scope.device.offUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Off?Token="
};
$scope.buildHALOffUrls = function (haldevice) {
bridgeService.clearDevice();
$scope.device.deviceType = "thermo";
$scope.device.name = haldevice.haldevicename + " Thermostat";
$scope.device.targetDevice = haldevice.halname;
$scope.device.mapType = "HALThermoSet";
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname + "-TurnOff";
$scope.device.onUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Auto?Token="
+ $scope.bridge.settings.haltoken;
$scope.device.offUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!HVACMode=Off?Token="
};
$scope.buildHALFanUrls = function (haldevice) {
bridgeService.clearDevice();
$scope.device.deviceType = "thermo";
$scope.device.name = haldevice.haldevicename + " Fan";
$scope.device.targetDevice = haldevice.halname;
$scope.device.mapType = "HALThermoSet";
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname + "-SetFan";
$scope.device.onUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!FanMode=On?Token="
+ $scope.bridge.settings.haltoken;
$scope.device.offUrl = "http://" + haldevice.haladdress
+ "/HVACService!HVACCmd=Set!HVACName="
+ haldevice.haldevicename.replaceAll(" ", "%20")
+ "!FanMode=Auto?Token="
+ $scope.bridge.settings.haltoken;
};
$scope.addDevice = function () {
if($scope.device.name == "" && $scope.device.onUrl == "")
return;
@@ -1450,7 +1562,12 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
for(var i = 0; i < $scope.bulk.devices.length; i++) {
for(var x = 0; x < bridgeService.state.haldevices.length; x++) {
if(bridgeService.state.haldevices[x].haldevicename == $scope.bulk.devices[i]) {
$scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control);
if(bridgeService.state.haldevices[x].haldevicetype == "HVAC")
$scope.buildHALAutoUrls(bridgeService.state.haldevices[x]);
else if(bridgeService.state.haldevices[x].haldevicetype == "HOME")
$scope.buildHALHomeUrls(bridgeService.state.haldevices[x]);
else
$scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control);
devicesList[i] = {
name: $scope.device.name,
mapId: $scope.device.mapId,
@@ -1523,6 +1640,10 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
$scope.deleteDeviceByMapId = function (haldevicename, halname, mapType) {
var id = haldevicename + "-" + halname;
if(mapType == "HOME")
id = id + "-HomeAway";
if(mapType == "HALThermoSet")
id = id + "-SetAuto";
$scope.bridge.mapandid = { id, mapType };
ngDialog.open({
template: 'deleteMapandIdDialog',
@@ -1770,7 +1891,8 @@ app.filter('availableHalDeviceId', function(bridgeService) {
if(input == null)
return out;
for (var i = 0; i < input.length; i++) {
if(!bridgeService.findDeviceByMapId(input[i].haldevicename + "-" + input[i].halname, input[i].halname, "halDevice")){
if(!bridgeService.findDeviceByMapId(input[i].haldevicename + "-" + input[i].halname, input[i].halname, "halDevice") &&
!bridgeService.findDeviceByMapId(input[i].haldevicename + "-" + input[i].halname + "-HomeAway", input[i].halname, "halHome") ){
out.push(input[i]);
}
}
@@ -1788,6 +1910,16 @@ app.filter('unavailableHalDeviceId', function(bridgeService) {
out.push(input[i]);
}
}
for (var i = 0; i < input.length; i++) {
if(bridgeService.findDeviceByMapId(input[i].haldevicename + "-" + input[i].halname + "-HomeAway", input[i].halname, "halHome")){
out.push(input[i]);
}
}
for (var i = 0; i < input.length; i++) {
if(input[i].mapType == "HALThermoSet"){
out.push(input[i]);
}
}
return out;
}
});

View File

@@ -10,7 +10,7 @@
href="#/harmonyactivities">Harmony Activities</a></li>
<li ng-if="bridge.showHarmony" role="presentation"><a
href="#/harmonydevices">Harmony Devices</a></li>
<li ng-if="bridge.showNest" role="presentation"><a href="#/nest">Nest</a></li>
<li ng-if="bridge.showHAL" role="presentation"><a href="#/HAL">HAL</a></li>
<li ng-if="bridge.showHue" role="presentation"><a
href="#/huedevices">Hue Devices</a></li>
<li role="presentation" class="active"><a href="#/haldevices">HAL
@@ -70,9 +70,29 @@
<td>{{haldevice.haldevicetype}}</td>
<td>{{haldevice.halname}}</td>
<td>
<button class="btn btn-success" type="submit"
<button ng-if="haldevice.haldevicetype === 'Light' || haldevice.haldevicetype === 'Appl' || haldevice.haldevicetype === 'Theatre' || haldevice.haldevicetype === 'Custom'" class="btn btn-success" type="submit"
ng-click="buildDeviceUrls(haldevice, device_dim_control)">Generate
Bridge Device</button>
<button ng-if="haldevice.haldevicetype === 'HOME'" class="btn btn-success" type="submit"
ng-click="buildHALHomeUrls(haldevice)">Home/Away</button>
<ul ng-if="haldevice.haldevicetype === 'HVAC'" class="list-group">
<li class="list-group-item">
<p>
<button class="btn btn-success" type="submit"
ng-click="buildHALHeatUrls(haldevice)">Heat</button>
<button class="btn btn-success" type="submit"
ng-click="buildHALCoolUrls(haldevice)">Cool</button>
<button class="btn btn-success" type="submit"
ng-click="buildHALAutoUrls(haldevice)">Auto</button>
</p>
<p>
<button class="btn btn-success" type="submit"
ng-click="buildHALOffUrls(haldevice)">Off</button>
<button class="btn btn-success" type="submit"
ng-click="buildHALFanUrls(haldevice)">Fan</button>
</p>
</li>
</ul>
</td>
</tr>
</table>
@@ -109,7 +129,7 @@
<td>{{haldevice.halname}}</td>
<td>
<button class="btn btn-danger" type="submit"
ng-click="deleteDeviceByMapId(haldevice.haldevicename, haldevice.halname, 'halDevice')">Delete</button>
ng-click="deleteDeviceByMapId(haldevice.haldevicename, haldevice.halname, haldevice.haldevicetype)">Delete</button>
</td>
</tr>
</table>