Pre-release of multiple Harmony Hub Support

This commit is contained in:
Admin
2015-12-02 15:34:30 -06:00
parent 9fc13c6c45
commit 2e5596a6e4
9 changed files with 130 additions and 44 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>1.1.0g</version> <version>1.1.0i</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>

View File

@@ -1,5 +1,20 @@
package com.bwssystems.harmony; package com.bwssystems.harmony;
public class HarmonyDevice { import net.whistlingfish.harmony.config.Device;
public class HarmonyDevice {
private Device device;
private String hub;
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
public String getHub() {
return hub;
}
public void setHub(String hub) {
this.hub = hub;
}
} }

View File

@@ -1,9 +1,9 @@
package com.bwssystems.harmony; package com.bwssystems.harmony;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -14,6 +14,7 @@ import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.NamedIP; import com.bwssystems.HABridge.NamedIP;
import net.whistlingfish.harmony.config.Activity; import net.whistlingfish.harmony.config.Activity;
import net.whistlingfish.harmony.config.Device;
public class HarmonyHome { public class HarmonyHome {
private static final Logger log = LoggerFactory.getLogger(HarmonyHome.class); private static final Logger log = LoggerFactory.getLogger(HarmonyHome.class);
@@ -35,36 +36,67 @@ public class HarmonyHome {
} }
public HarmonyHandler getHarmonyHandler(String aName) { public HarmonyHandler getHarmonyHandler(String aName) {
HarmonyHandler aHandler = null;
if(aName == null || aName.equals("")) { if(aName == null || aName.equals("")) {
HarmonyHandler aHandler = hubs.get("default").getMyHarmony(); aName = "default";
if(aHandler == null) {
Set<String> keys = hubs.keySet();
if(!keys.isEmpty()) {
aHandler = hubs.get(keys.toArray()[0]).getMyHarmony();
}
else
aHandler = null;
}
return aHandler;
} }
return hubs.get(aName).getMyHarmony();
if(hubs.get(aName) == null) {
Set<String> keys = hubs.keySet();
if(!keys.isEmpty()) {
aHandler = hubs.get(keys.toArray()[0]).getMyHarmony();
}
else
aHandler = null;
}
else
aHandler = hubs.get(aName).getMyHarmony();
return aHandler;
} }
public List<HarmonyActivity> getActivities() { public List<HarmonyActivity> getActivities() {
Iterator<String> keys = hubs.keySet().iterator(); Iterator<String> keys = hubs.keySet().iterator();
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
while(keys.hasNext()) { while(keys.hasNext()) {
List<Activity> theActivities = hubs.get(keys.next()).getMyHarmony().getActivities(); String key = keys.next();
ListIterator<Activity> activities = theActivities.listIterator(); Iterator<Activity> activities = hubs.get(key).getMyHarmony().getActivities().iterator();
while(activities.hasNext()) { while(activities.hasNext()) {
HarmonyActivity anActivity = new HarmonyActivity();
anActivity.setActivity(activities.next());
anActivity.setHub(key);
activityList.add(anActivity);
} }
} }
return null; return activityList;
} }
public List<HarmonyCurrentActivity> getCurrentActivities() { public List<HarmonyActivity> getCurrentActivities() {
return null; Iterator<String> keys = hubs.keySet().iterator();
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
while(keys.hasNext()) {
String key = keys.next();
Iterator<Activity> activities = hubs.get(key).getMyHarmony().getActivities().iterator();
while(activities.hasNext()) {
HarmonyActivity anActivity = new HarmonyActivity();
anActivity.setActivity(activities.next());
anActivity.setHub(key);
activityList.add(anActivity);
}
}
return activityList;
} }
public List<HarmonyDevice> getDevices() { public List<HarmonyDevice> getDevices() {
return null; Iterator<String> keys = hubs.keySet().iterator();
ArrayList<HarmonyDevice> deviceList = new ArrayList<HarmonyDevice>();
while(keys.hasNext()) {
String key = keys.next();
Iterator<Device> devices = hubs.get(key).getMyHarmony().getDevices().iterator();
while(devices.hasNext()) {
HarmonyDevice aDevice = new HarmonyDevice();
aDevice.setDevice(devices.next());
aDevice.setHub(key);
deviceList.add(aDevice);
}
}
return deviceList;
} }
} }

View File

@@ -29,6 +29,7 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li> <li class="active"><a href="#">Home</a></li>
<li><a href="http://echo.amazon.com/#cards" target="_blank">My Echo</a></li> <li><a href="http://echo.amazon.com/#cards" target="_blank">My Echo</a></li>
<li><a href="https://github.com/bwssytems/ha-bridge/blob/master/README.md" target="_blank">Help</a></li>
<li class="dropdown"> <li class="dropdown">
<a id="dropdownMenu1" href="" class="dropdown-toggle" <a id="dropdownMenu1" href="" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-haspopup="true" data-toggle="dropdown" role="button" aria-haspopup="true"

View File

@@ -246,9 +246,9 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
); );
}; };
this.findDeviceByMapId = function(id, type) { this.findDeviceByMapId = function(id, target, type) {
for(var i = 0; i < this.state.devices.length; i++) { for(var i = 0; i < this.state.devices.length; i++) {
if(this.state.devices[i].mapId == id && this.state.devices[i].mapType == type) if(this.state.devices[i].mapId == id && this.state.devices[i].mapType == type && this.state.devices[i].targetDevice == target)
return true; return true;
} }
return false; return false;
@@ -266,6 +266,7 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
mapId: device.mapId, mapId: device.mapId,
mapType: device.mapType, mapType: device.mapType,
deviceType: device.deviceType, deviceType: device.deviceType,
targetDevice: device.targetDevice,
onUrl: device.onUrl, onUrl: device.onUrl,
offUrl: device.offUrl, offUrl: device.offUrl,
httpVerb: device.httpVerb, httpVerb: device.httpVerb,
@@ -293,6 +294,7 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
mapId: device.mapId, mapId: device.mapId,
mapType: device.mapType, mapType: device.mapType,
deviceType: device.deviceType, deviceType: device.deviceType,
targetDevice: device.targetDevice,
onUrl: device.onUrl, onUrl: device.onUrl,
offUrl: device.offUrl, offUrl: device.offUrl,
httpVerb: device.httpVerb, httpVerb: device.httpVerb,
@@ -514,20 +516,22 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
$scope.buildActivityUrls = function (harmonyactivity) { $scope.buildActivityUrls = function (harmonyactivity) {
$scope.device.deviceType = "activity"; $scope.device.deviceType = "activity";
$scope.device.name = harmonyactivity.label; $scope.device.targetDevice = harmonyactivity.hub;
$scope.device.name = harmonyactivity.activity.label;
$scope.device.mapType = "harmonyActivity"; $scope.device.mapType = "harmonyActivity";
$scope.device.mapId = harmonyactivity.id; $scope.device.mapId = harmonyactivity.activity.id;
$scope.device.onUrl = "{\"name\":\"" + harmonyactivity.id + "\"}"; $scope.device.onUrl = "{\"name\":\"" + harmonyactivity.activity.id + "\"}";
$scope.device.offUrl = "{\"name\":\"-1\"}"; $scope.device.offUrl = "{\"name\":\"-1\"}";
}; };
$scope.buildButtonUrls = function (harmonydevice, onbutton, offbutton) { $scope.buildButtonUrls = function (harmonydevice, onbutton, offbutton) {
$scope.device.deviceType = "button"; $scope.device.deviceType = "button";
$scope.device.name = harmonydevice.label; $scope.device.targetDevice = harmonydevice.hub;
$scope.device.name = harmonydevice.device.label;
$scope.device.mapType = "harmonyButton"; $scope.device.mapType = "harmonyButton";
$scope.device.mapId = harmonydevice.id + "-" + onbutton + "-" + offbutton; $scope.device.mapId = harmonydevice.device.id + "-" + onbutton + "-" + offbutton;
$scope.device.onUrl = "{\"device\":\"" + harmonydevice.id + "\",\"button\":\"" + onbutton + "\"}"; $scope.device.onUrl = "{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + onbutton + "\"}";
$scope.device.offUrl = "{\"device\":\"" + harmonydevice.id + "\",\"button\":\"" + offbutton + "\"}"; $scope.device.offUrl = "{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + offbutton + "\"}";
}; };
$scope.testUrl = function (device, type) { $scope.testUrl = function (device, type) {
@@ -543,6 +547,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
$scope.device.name = ""; $scope.device.name = "";
$scope.device.onUrl = ""; $scope.device.onUrl = "";
$scope.device.deviceType = "switch"; $scope.device.deviceType = "switch";
$scope.device.targetDevice = null;
$scope.device.offUrl = ""; $scope.device.offUrl = "";
$scope.device.httpVerb = null; $scope.device.httpVerb = null;
$scope.device.contentType = null; $scope.device.contentType = null;
@@ -587,8 +592,8 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
$scope.imgScenesUrl = "glyphicon glyphicon-plus"; $scope.imgScenesUrl = "glyphicon glyphicon-plus";
}; };
$scope.deleteDeviceByMapId = function (id) { $scope.deleteDeviceByMapId = function (id, mapType) {
bridgeService.deleteDeviceByMapId(id); bridgeService.deleteDeviceByMapId(id, mapType);
}; };
}); });
@@ -599,7 +604,7 @@ app.filter('availableHarmonyActivityId', function(bridgeService) {
if(input == null) if(input == null)
return out; return out;
for (var i = 0; i < input.length; i++) { for (var i = 0; i < input.length; i++) {
if(!bridgeService.findDeviceByMapId(input[i].id, "harmonyActivity")){ if(!bridgeService.findDeviceByMapId(input[i].activity.id, input[i].hub, "harmonyActivity")){
out.push(input[i]); out.push(input[i]);
} }
} }
@@ -613,7 +618,7 @@ app.filter('unavailableHarmonyActivityId', function(bridgeService) {
if(input == null) if(input == null)
return out; return out;
for (var i = 0; i < input.length; i++) { for (var i = 0; i < input.length; i++) {
if(bridgeService.findDeviceByMapId(input[i].id, "harmonyActivity")){ if(bridgeService.findDeviceByMapId(input[i].activity.id, input[i].hub, "harmonyActivity")){
out.push(input[i]); out.push(input[i]);
} }
} }

View File

@@ -37,6 +37,9 @@
<th> <th>
<a href="" ng-click="order('deviceType')">Type</a> <a href="" ng-click="order('deviceType')">Type</a>
<span class="sortorder" ng-show="predicate === 'deviceType'" ng-class="{reverse:reverse}"></span></th> <span class="sortorder" ng-show="predicate === 'deviceType'" ng-class="{reverse:reverse}"></span></th>
<th>
<a href="" ng-click="order('targetDevice')">Target</a>
<span class="sortorder" ng-show="predicate === 'targetDevice'" ng-class="{reverse:reverse}"></span></th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
@@ -44,6 +47,7 @@
<td>{{device.id}}</td> <td>{{device.id}}</td>
<td>{{device.name}}</td> <td>{{device.name}}</td>
<td>{{device.deviceType}}</td> <td>{{device.deviceType}}</td>
<td>{{device.targetDevice}}</td>
<td> <td>
<button class="btn btn-info" type="submit" <button class="btn btn-info" type="submit"
ng-click="testUrl(device, 'on')">Test ON</button> ng-click="testUrl(device, 'on')">Test ON</button>
@@ -66,7 +70,7 @@
<form class="form-horizontal"> <form class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label class="col-xs-12 col-sm-3 control-label" for="bridge-base">Bridge <label class="col-xs-12 col-sm-2 control-label" for="bridge-base">Bridge
server</label> server</label>
<div class="col-xs-8 col-sm-7"> <div class="col-xs-8 col-sm-7">

View File

@@ -26,6 +26,15 @@
<button type="submit" class="col-xs-4 col-sm-2 btn btn-primary"> <button type="submit" class="col-xs-4 col-sm-2 btn btn-primary">
Update Device</button> Update Device</button>
</div> </div>
<div class="form-group">
<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>
</div>
<div class="form-group"> <div class="form-group">
<div class="row"> <div class="row">
<label class="col-xs-12 col-sm-2 control-label" for="device-map-type">Map Type <label class="col-xs-12 col-sm-2 control-label" for="device-map-type">Map Type

View File

@@ -26,13 +26,18 @@
<th> <th>
<a href="" ng-click="order('id')">Id</a> <a href="" ng-click="order('id')">Id</a>
<span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span> <span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span>
</th>
<th>
<a href="" ng-click="order('hub')">Hub</a>
<span class="sortorder" ng-show="predicate === 'hub'" ng-class="{reverse:reverse}"></span>
</th> </th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tr ng-repeat="harmonyactivity in bridge.harmonyactivities | availableHarmonyActivityId | orderBy:predicate:reverse"> <tr ng-repeat="harmonyactivity in bridge.harmonyactivities | availableHarmonyActivityId | orderBy:predicate:reverse">
<td>{{harmonyactivity.label}}</td> <td>{{harmonyactivity.activity.label}}</td>
<td>{{harmonyactivity.id}}</td> <td>{{harmonyactivity.activity.id}}</td>
<td>{{harmonyactivity.hub}}</td>
<td> <td>
<button class="btn btn-success" type="submit" <button class="btn btn-success" type="submit"
ng-click="buildActivityUrls(harmonyactivity)">Generate ng-click="buildActivityUrls(harmonyactivity)">Generate
@@ -57,15 +62,20 @@
<th> <th>
<a href="" ng-click="order('id')">Id</a> <a href="" ng-click="order('id')">Id</a>
<span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span> <span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span>
</th>
<th>
<a href="" ng-click="order('hub')">Hub</a>
<span class="sortorder" ng-show="predicate === 'hub'" ng-class="{reverse:reverse}"></span>
</th> </th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>
<tr ng-repeat="harmonyactivity in bridge.harmonyactivities | unavailableHarmonyActivityId | orderBy:predicate:reverse"> <tr ng-repeat="harmonyactivity in bridge.harmonyactivities | unavailableHarmonyActivityId | orderBy:predicate:reverse">
<td>{{harmonyactivity.label}}</td> <td>{{harmonyactivity.activity.label}}</td>
<td>{{harmonyactivity.id}}</td> <td>{{harmonyactivity.activity.id}}</td>
<td>{{harmonyactivity.hub}}</td>
<td><button class="btn btn-danger" type="submit" <td><button class="btn btn-danger" type="submit"
ng-click="deleteDeviceByMapId(harmonyactivity.id, 'harmonyActivity')">Delete</button></td> ng-click="deleteDeviceByMapId(harmonyactivity.activity.id, 'harmonyActivity')">Delete</button></td>
</tr> </tr>
</table> </table>
</li> </li>

View File

@@ -26,6 +26,10 @@
<th> <th>
<a href="" ng-click="order('id')">Id</a> <a href="" ng-click="order('id')">Id</a>
<span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span> <span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span>
</th>
<th>
<a href="" ng-click="order('hub')">Hub</a>
<span class="sortorder" ng-show="predicate === 'hub'" ng-class="{reverse:reverse}"></span>
</th> </th>
<th>On Button</th> <th>On Button</th>
<th>Off Button</th> <th>Off Button</th>
@@ -33,18 +37,19 @@
</tr> </tr>
</thead> </thead>
<tr ng-repeat="harmonydevice in bridge.harmonydevices | orderBy:predicate:reverse"> <tr ng-repeat="harmonydevice in bridge.harmonydevices | orderBy:predicate:reverse">
<td>{{harmonydevice.label}}</td> <td>{{harmonydevice.device.label}}</td>
<td>{{harmonydevice.id}}</td> <td>{{harmonydevice.device.id}}</td>
<td>{{harmonydevice.hub}}</td>
<td> <td>
<select name="device-ctrlon" id="device-ctrlon" ng-model="devicectrlon"> <select name="device-ctrlon" id="device-ctrlon" ng-model="devicectrlon">
<optgroup ng-repeat="ctrlon in harmonydevice.controlGroup" label="{{ctrlon.name}}"> <optgroup ng-repeat="ctrlon in harmonydevice.device.controlGroup" label="{{ctrlon.name}}">
<option ng-repeat="funcon in ctrlon.function">{{funcon.name}}</option> <option ng-repeat="funcon in ctrlon.function">{{funcon.name}}</option>
</optgroup > </optgroup >
</select> </select>
</td> </td>
<td> <td>
<select name="device-ctrloff" id="device-ctrloff" ng-model="devicectrloff"> <select name="device-ctrloff" id="device-ctrloff" ng-model="devicectrloff">
<optgroup ng-repeat="ctrloff in harmonydevice.controlGroup" label="{{ctrloff.name}}"> <optgroup ng-repeat="ctrloff in harmonydevice.device.controlGroup" label="{{ctrloff.name}}">
<option ng-repeat="funcoff in ctrloff.function">{{funcoff.name}}</option> <option ng-repeat="funcoff in ctrloff.function">{{funcoff.name}}</option>
</optgroup > </optgroup >
</select> </select>
@@ -73,6 +78,10 @@
<th> <th>
<a href="" ng-click="order('id')">Device Id</a> <a href="" ng-click="order('id')">Device Id</a>
<span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span> <span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span>
</th>
<th>
<a href="" ng-click="order('targetDevice')">Hub</a>
<span class="sortorder" ng-show="predicate === 'targetDevice'" ng-class="{reverse:reverse}"></span>
</th> </th>
<th> <th>
<a href="" ng-click="order('mapId')">Harmony Device-Button On-Button Off</a> <a href="" ng-click="order('mapId')">Harmony Device-Button On-Button Off</a>
@@ -84,6 +93,7 @@
<tr ng-repeat="device in bridge.devices | configuredButtons | orderBy:predicate:reverse"> <tr ng-repeat="device in bridge.devices | configuredButtons | orderBy:predicate:reverse">
<td>{{device.name}}</td> <td>{{device.name}}</td>
<td>{{device.id}}</td> <td>{{device.id}}</td>
<td>{{device.targetDevice}}</td>
<td>{{device.mapId}}</td> <td>{{device.mapId}}</td>
<td> <td>
<button class="btn btn-danger" type="submit" <button class="btn btn-danger" type="submit"