mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 08:13:23 +00:00
First draft and start of tracking for scenes, devices, activities.
Implemented Harmony activity list so far.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>1.0.9</version>
|
||||
<version>1.0.9b</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -5,6 +5,8 @@ package com.bwssystems.HABridge.dao;
|
||||
public class DeviceDescriptor{
|
||||
private String id;
|
||||
private String name;
|
||||
private String mapId;
|
||||
private String mapType;
|
||||
private String deviceType;
|
||||
private String offUrl;
|
||||
private String onUrl;
|
||||
@@ -21,7 +23,23 @@ public class DeviceDescriptor{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
public String getMapId() {
|
||||
return mapId;
|
||||
}
|
||||
|
||||
public void setMapId(String mapId) {
|
||||
this.mapId = mapId;
|
||||
}
|
||||
|
||||
public String getMapType() {
|
||||
return mapType;
|
||||
}
|
||||
|
||||
public void setMapType(String mapType) {
|
||||
this.mapType = mapType;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,8 @@ public class DeviceResource {
|
||||
deviceEntry.setName(device.getName());
|
||||
if (device.getDeviceType() != null)
|
||||
deviceEntry.setDeviceType(device.getDeviceType());
|
||||
deviceEntry.setMapId(device.getMapId());
|
||||
deviceEntry.setMapType(device.getMapType());
|
||||
deviceEntry.setOnUrl(device.getOnUrl());
|
||||
deviceEntry.setOffUrl(device.getOffUrl());
|
||||
deviceEntry.setHttpVerb(device.getHttpVerb());
|
||||
|
||||
@@ -4,11 +4,8 @@ var app = angular.module('habridge', [
|
||||
|
||||
app.config(function ($routeProvider) {
|
||||
$routeProvider.when('/#', {
|
||||
templateUrl: 'views/nonconfiguration.html',
|
||||
controller: 'ViewingController'
|
||||
}).when('/show', {
|
||||
templateUrl: 'views/configuration.html',
|
||||
controller: 'ViewingController'
|
||||
controller: 'ViewingController'
|
||||
}).when('/editor', {
|
||||
templateUrl: 'views/editor.html',
|
||||
controller: 'AddingController'
|
||||
@@ -28,7 +25,7 @@ app.config(function ($routeProvider) {
|
||||
templateUrl: 'views/harmonyactivity.html',
|
||||
controller: 'AddingController'
|
||||
}).otherwise({
|
||||
templateUrl: 'views/nonconfiguration.html',
|
||||
templateUrl: 'views/configuration.html',
|
||||
controller: 'ViewingController'
|
||||
})
|
||||
});
|
||||
@@ -249,22 +246,31 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
|
||||
);
|
||||
};
|
||||
|
||||
this.addDevice = function (id, name, type, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) {
|
||||
this.findHarmonyActivityEntry = function(activityId) {
|
||||
for(var i = 0; i < this.state.devices.length; i++) {
|
||||
if(this.state.devices[i].mapId == activityId)
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
this.addDevice = function (device) {
|
||||
this.state.error = "";
|
||||
if(httpVerb != null && httpVerb != "")
|
||||
type = "custom";
|
||||
if (id) {
|
||||
var putUrl = this.state.base + "/" + id;
|
||||
if(device.httpVerb != null && device.httpVerb != "")
|
||||
device.deviceType = "custom";
|
||||
if (device.id) {
|
||||
var putUrl = this.state.base + "/" + device.id;
|
||||
return $http.put(putUrl, {
|
||||
id: id,
|
||||
name: name,
|
||||
deviceType: type,
|
||||
onUrl: onUrl,
|
||||
offUrl: offUrl,
|
||||
httpVerb: httpVerb,
|
||||
contentType: contentType,
|
||||
contentBody: contentBody,
|
||||
contentBodyOff: contentBodyOff
|
||||
id: device.id,
|
||||
name: device.name,
|
||||
mapId: device.mapId,
|
||||
mapType: device.mapType,
|
||||
deviceType: device.deviceType,
|
||||
onUrl: device.onUrl,
|
||||
offUrl: device.offUrl,
|
||||
httpVerb: device.httpVerb,
|
||||
contentType: device.contentType,
|
||||
contentBody: device.contentBody,
|
||||
contentBodyOff: device.contentBodyOff
|
||||
}).then(
|
||||
function (response) {
|
||||
self.viewDevices();
|
||||
@@ -277,19 +283,21 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if(type == null || type == "")
|
||||
type = "switch";
|
||||
if(httpVerb != null && httpVerb != "")
|
||||
type = "custom";
|
||||
if(device.deviceType == null || device.deviceType == "")
|
||||
device.deviceType = "switch";
|
||||
if(device.httpVerb != null && device.httpVerb != "")
|
||||
device.deviceType = "custom";
|
||||
return $http.post(this.state.base, {
|
||||
name: name,
|
||||
deviceType: type,
|
||||
onUrl: onUrl,
|
||||
offUrl: offUrl,
|
||||
httpVerb: httpVerb,
|
||||
contentType: contentType,
|
||||
contentBody: contentBody,
|
||||
contentBodyOff: contentBodyOff
|
||||
name: device.name,
|
||||
mapId: device.mapId,
|
||||
mapType: device.mapType,
|
||||
deviceType: device.deviceType,
|
||||
onUrl: device.onUrl,
|
||||
offUrl: device.offUrl,
|
||||
httpVerb: device.httpVerb,
|
||||
contentType: device.contentType,
|
||||
contentBody: device.contentBody,
|
||||
contentBodyOff: device.contentBodyOff
|
||||
}).then(
|
||||
function (response) {
|
||||
self.viewDevices();
|
||||
@@ -319,8 +327,8 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
|
||||
);
|
||||
};
|
||||
|
||||
this.editDevice = function (id, name, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) {
|
||||
self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl, httpVerb: httpVerb, contentType: contentType, contentBody: contentBody, contentBodyOff: contentBodyOff};
|
||||
this.editDevice = function (device) {
|
||||
self.state.device = device;
|
||||
};
|
||||
|
||||
this.testUrl = function (device, type) {
|
||||
@@ -356,6 +364,8 @@ app.controller('ViewingController', function ($scope, $location, $http, $window,
|
||||
$scope.bridge = bridgeService.state;
|
||||
bridgeService.updateShowVera();
|
||||
bridgeService.updateShowHarmony();
|
||||
$scope.visible = false;
|
||||
$scope.imgUrl = "glyphicon glyphicon-plus";
|
||||
$scope.predicate = '';
|
||||
$scope.reverse = true;
|
||||
$scope.order = function(predicate) {
|
||||
@@ -373,9 +383,16 @@ app.controller('ViewingController', function ($scope, $location, $http, $window,
|
||||
bridgeService.viewDevices();
|
||||
};
|
||||
$scope.editDevice = function (device) {
|
||||
bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl, device.httpVerb, device.contentType, device.contentBody, device.contentBodyOff);
|
||||
bridgeService.editDevice(device);
|
||||
$location.path('/editdevice');
|
||||
};
|
||||
$scope.toggle = function () {
|
||||
$scope.visible = !$scope.visible;
|
||||
if($scope.visible)
|
||||
$scope.imgUrl = "glyphicon glyphicon-minus";
|
||||
else
|
||||
$scope.imgUrl = "glyphicon glyphicon-plus";
|
||||
};
|
||||
});
|
||||
|
||||
app.controller('AddingController', function ($scope, $location, $http, bridgeService, BridgeSettings) {
|
||||
@@ -392,6 +409,8 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
bridgeService.updateShowVera();
|
||||
bridgeService.updateShowHarmony();
|
||||
$scope.device = bridgeService.state.device;
|
||||
$scope.activitiesVisible = false;
|
||||
$scope.imgActivitiesUrl = "glyphicon glyphicon-plus";
|
||||
$scope.predicate = '';
|
||||
$scope.reverse = true;
|
||||
$scope.device_dim_control = "";
|
||||
@@ -404,6 +423,9 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + $scope.vera.base;
|
||||
}
|
||||
$scope.device.deviceType = "switch";
|
||||
$scope.device.mapType = "veraDevice";
|
||||
$scope.device.mapId = $scope.vera.id;
|
||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&DeviceNum="
|
||||
@@ -424,6 +446,8 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
$scope.vera.base = "http://" + $scope.vera.base;
|
||||
}
|
||||
$scope.device.deviceType = "scene";
|
||||
$scope.device.mapType = "veraScene";
|
||||
$scope.device.mapId = $scope.vera.id;
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||
+ $scope.vera.id;
|
||||
@@ -438,6 +462,8 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
}
|
||||
$scope.device.deviceType = "switch";
|
||||
$scope.device.name = veradevice.name;
|
||||
$scope.device.mapType = "veraDevice";
|
||||
$scope.device.mapId = veradevice.id;
|
||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&DeviceNum="
|
||||
@@ -459,6 +485,8 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
}
|
||||
$scope.device.deviceType = "scene";
|
||||
$scope.device.name = verascene.name;
|
||||
$scope.devoce.mapType = "veraScene";
|
||||
$scope.device.mapId = verascene.id;
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||
+ verascene.id;
|
||||
@@ -470,6 +498,8 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
$scope.buildActivityUrls = function (harmonyactivity) {
|
||||
$scope.device.deviceType = "activity";
|
||||
$scope.device.name = harmonyactivity.label;
|
||||
$scope.device.mapType = "harmonyActivity";
|
||||
$scope.device.mapId = harmonyactivity.id;
|
||||
$scope.device.onUrl = "{\"name\":\"" + harmonyactivity.id + "\"}";
|
||||
$scope.device.offUrl = "{\"name\":\"-1\"}";
|
||||
};
|
||||
@@ -477,6 +507,8 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
$scope.buildButtonUrls = function (harmonydevice, onbutton, offbutton) {
|
||||
$scope.device.deviceType = "button";
|
||||
$scope.device.name = harmonydevice.label;
|
||||
$scope.device.mapType = "harmonyButton";
|
||||
$scope.device.mapId = harmonydevice.id + "-" + onbutton + "-" + offbutton;
|
||||
$scope.device.onUrl = "{\"device\":\"" + harmonydevice.id + "\",\"button\":\"" + onbutton + "\"}";
|
||||
$scope.device.offUrl = "{\"device\":\"" + harmonydevice.id + "\",\"button\":\"" + offbutton + "\"}";
|
||||
};
|
||||
@@ -486,9 +518,11 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
};
|
||||
|
||||
$scope.addDevice = function () {
|
||||
bridgeService.addDevice($scope.device.id, $scope.device.name, $scope.device.deviceType, $scope.device.onUrl, $scope.device.offUrl, $scope.device.httpVerb, $scope.device.contentType, $scope.device.contentBody, $scope.device.contentBodyOff).then(
|
||||
bridgeService.addDevice($scope.device).then(
|
||||
function () {
|
||||
$scope.device.id = "";
|
||||
$scope.device.mapType = null;
|
||||
$scope.device.mapId = null;
|
||||
$scope.device.name = "";
|
||||
$scope.device.onUrl = "";
|
||||
$scope.device.deviceType = "switch";
|
||||
@@ -503,9 +537,44 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
||||
}
|
||||
);
|
||||
}
|
||||
$scope.toggleActivities = function () {
|
||||
$scope.activitiesVisible = !$scope.activitiesVisible;
|
||||
if($scope.activitiesVisible)
|
||||
$scope.imgActivitiesUrl = "glyphicon glyphicon-minus";
|
||||
else
|
||||
$scope.imgActivitiesUrl = "glyphicon glyphicon-plus";
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
app.filter('availableActivity', function(bridgeService) {
|
||||
return function(input) {
|
||||
var out = [];
|
||||
if(input == null)
|
||||
return out;
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
if(!bridgeService.findHarmonyActivityEntry(input[i].id)){
|
||||
out.push(input[i]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
});
|
||||
|
||||
app.filter('unavailableActivity', function(bridgeService) {
|
||||
return function(input) {
|
||||
var out = [];
|
||||
if(input == null)
|
||||
return out;
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
if(bridgeService.findHarmonyActivityEntry(input[i].id)){
|
||||
out.push(input[i]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
});
|
||||
|
||||
app.controller('ErrorsController', function ($scope, bridgeService) {
|
||||
$scope.bridge = bridgeService.state;
|
||||
});
|
||||
|
||||
@@ -60,10 +60,9 @@
|
||||
|
||||
<div class="panel panel-default bridgeServer">
|
||||
<div class="panel-heading">
|
||||
<a href="#/"><span class="glyphicon glyphicon-minus" aria-hidden="true"></span></a>
|
||||
<h1 class="panel-title">Bridge settings</h1>
|
||||
<h1 class="panel-title">Bridge settings <a ng-click="toggle()"><span class={{imgUrl}} aria-hidden="true"></a></h1>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div ng-if="visible" class="animate-if" class="panel-body">
|
||||
|
||||
<form class="form-horizontal">
|
||||
<div class="form-group">
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
|
||||
<div class="panel-heading">
|
||||
<h2 class="panel-title">Add a new device</h2>
|
||||
<h2 class="panel-title">Edit a device</h2>
|
||||
</div>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
@@ -26,6 +26,31 @@
|
||||
<button type="submit" class="col-xs-4 col-sm-2 btn btn-primary">
|
||||
Update Device</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-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>
|
||||
</select>
|
||||
</div>
|
||||
</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>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<input type="text" class="form-control" id="device-map-id"
|
||||
ng-model="device.mapId" placeholder="1111">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On
|
||||
@@ -35,6 +60,7 @@
|
||||
<textarea rows="3" class="form-control" id="device-on-url"
|
||||
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
@@ -45,6 +71,7 @@
|
||||
<textarea rows="3" class="form-control" id="device-off-url"
|
||||
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
@@ -61,7 +88,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
@@ -86,7 +113,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div ng-if="device.httpVerb" class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body">Content Body On</label>
|
||||
@@ -98,7 +125,7 @@
|
||||
<div class="clearfix visible-xs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div ng-if="device.httpVerb" class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body-off">Content Body Off</label>
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<textarea rows="3" class="form-control" id="device-on-url"
|
||||
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
@@ -108,6 +109,7 @@
|
||||
<textarea rows="3" class="form-control" id="device-off-url"
|
||||
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
@@ -124,7 +126,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
@@ -149,7 +151,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div ng-if="device.httpVerb" class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body">Content Body On</label>
|
||||
@@ -161,7 +163,7 @@
|
||||
<div class="clearfix visible-xs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div ng-if="device.httpVerb" class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
for="device-content-body-off">Content Body Off</label>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr ng-repeat="harmonyactivity in bridge.harmonyactivities | orderBy:predicate:reverse">
|
||||
<tr ng-repeat="harmonyactivity in bridge.harmonyactivities | availableActivity | orderBy:predicate:reverse">
|
||||
<td>{{harmonyactivity.label}}</td>
|
||||
<td>{{harmonyactivity.id}}</td>
|
||||
<td>
|
||||
@@ -42,6 +42,31 @@
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="panel-heading">
|
||||
<h2 class="panel-title">Already Configured Activities <a ng-click="toggleActivities()"><span class={{imgActivitiesUrl}} aria-hidden="true"></a></h2>
|
||||
</div>
|
||||
<ul ng-if="activitiesVisible" class="list-group">
|
||||
<li class="list-group-item">
|
||||
<table class="table table-bordered table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<a href="" ng-click="order('label')">Name</a>
|
||||
<span class="sortorder" ng-show="predicate === 'name'" ng-class="{reverse:reverse}"></span>
|
||||
</th>
|
||||
<th>
|
||||
<a href="" ng-click="order('id')">Id</a>
|
||||
<span class="sortorder" ng-show="predicate === 'id'" ng-class="{reverse:reverse}"></span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr ng-repeat="harmonyactivity in bridge.harmonyactivities | unavailableActivity | orderBy:predicate:reverse">
|
||||
<td>{{harmonyactivity.label}}</td>
|
||||
<td>{{harmonyactivity.id}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="panel panel-default bridgeServer" ng-if="!bridge.error">
|
||||
<div class="panel-heading">
|
||||
|
||||
Reference in New Issue
Block a user