mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 08:13:23 +00:00
Updating how controllers work together with shared data.
This commit is contained in:
@@ -106,8 +106,8 @@ public class DeviceResponse {
|
|||||||
deviceState.setCt(313);
|
deviceState.setCt(313);
|
||||||
|
|
||||||
List<Double> xv = new LinkedList<>();
|
List<Double> xv = new LinkedList<>();
|
||||||
xv.add(0.4255);
|
xv.add(Double.valueOf("0.4255"));
|
||||||
xv.add(0.3998);
|
xv.add(Double.valueOf("0.3998"));
|
||||||
deviceState.setXy(xv);
|
deviceState.setXy(xv);
|
||||||
deviceState.setColormode("ct");
|
deviceState.setColormode("ct");
|
||||||
response.setName(name);
|
response.setName(name);
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ public class DeviceRepository {
|
|||||||
|
|
||||||
public void save(DeviceDescriptor aDescriptor) {
|
public void save(DeviceDescriptor aDescriptor) {
|
||||||
int id = random.nextInt(Integer.MAX_VALUE);
|
int id = random.nextInt(Integer.MAX_VALUE);
|
||||||
|
if(aDescriptor.getId() != null)
|
||||||
|
devices.remove(aDescriptor.getId());
|
||||||
|
else
|
||||||
aDescriptor.setId(String.valueOf(id));
|
aDescriptor.setId(String.valueOf(id));
|
||||||
put(id, aDescriptor);
|
put(id, aDescriptor);
|
||||||
JsonTransformer aRenderer = new JsonTransformer();
|
JsonTransformer aRenderer = new JsonTransformer();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>HA Bridge Configuration</title>
|
<title>HA Bridge</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
padding-top: 60px;
|
padding-top: 60px;
|
||||||
|
|||||||
@@ -15,15 +15,46 @@ app.config(function ($routeProvider) {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
app.factory('BridgeSettings'), function() {
|
app.run( function (bridgeService) {
|
||||||
return {
|
bridgeService.viewBridgeSettings();
|
||||||
name : 'anonymous'
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.service('bridgeService', function ($http) {
|
app.factory('BridgeSettings', function() {
|
||||||
|
var BridgeSettings = {};
|
||||||
|
|
||||||
|
BridgeSettings.upnpconfigaddress = "";
|
||||||
|
BridgeSettings.serverport = "";
|
||||||
|
BridgeSettings.upnpdevicedb = "";
|
||||||
|
BridgeSettings.upnpresponseport = "";
|
||||||
|
BridgeSettings.veraaddress = "";
|
||||||
|
|
||||||
|
BridgeSettings.setupnpconfigaddress = function(aconfigaddress){
|
||||||
|
BridgeSettings.upnpconfigaddress = aconfigaddress;
|
||||||
|
};
|
||||||
|
|
||||||
|
BridgeSettings.setserverport = function(aserverport){
|
||||||
|
BridgeSettings.serverport = aserverport;
|
||||||
|
};
|
||||||
|
|
||||||
|
BridgeSettings.setupnpdevicedb = function(aupnpdevicedb){
|
||||||
|
BridgeSettings.upnpdevicedb = aupnpdevicedb;
|
||||||
|
};
|
||||||
|
|
||||||
|
BridgeSettings.setupnpresponseport = function(aupnpresponseport){
|
||||||
|
BridgeSettings.upnpresponseport = aupnpresponseport;
|
||||||
|
};
|
||||||
|
|
||||||
|
BridgeSettings.setveraaddress = function(averaaddress){
|
||||||
|
BridgeSettings.veraaddress = averaaddress;
|
||||||
|
};
|
||||||
|
|
||||||
|
return BridgeSettings;
|
||||||
|
});
|
||||||
|
|
||||||
|
app.service('bridgeService', function ($http, BridgeSettings) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], error: ""};
|
self.BridgeSettings = BridgeSettings;
|
||||||
|
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], device: [], error: ""};
|
||||||
|
|
||||||
this.viewDevices = function () {
|
this.viewDevices = function () {
|
||||||
this.state.error = "";
|
this.state.error = "";
|
||||||
@@ -47,11 +78,11 @@ app.service('bridgeService', function ($http) {
|
|||||||
this.state.error = "";
|
this.state.error = "";
|
||||||
return $http.get(this.state.upnpbase).then(
|
return $http.get(this.state.upnpbase).then(
|
||||||
function (response) {
|
function (response) {
|
||||||
self.state.upnpconfigaddress = response.data.upnpconfigaddress;
|
self.BridgeSettings.setupnpconfigaddress(response.data.upnpconfigaddress);
|
||||||
self.state.serverport = response.data.serverport;
|
self.BridgeSettings.setserverport(response.data.serverport);
|
||||||
self.state.upnpdevicedb = response.data.upnpdevicedb;
|
self.BridgeSettings.setupnpdevicedb(response.data.upnpdevicedb);
|
||||||
self.state.upnpresponseport = response.data.upnpresponseport;
|
self.BridgeSettings.setupnpresponseport(response.data.upnpresponseport);
|
||||||
self.state.veraaddress = response.data.veraaddress;
|
self.BridgeSettings.setveraaddress(response.data.veraaddress);
|
||||||
},
|
},
|
||||||
function (error) {
|
function (error) {
|
||||||
if (error.data) {
|
if (error.data) {
|
||||||
@@ -158,18 +189,14 @@ app.service('bridgeService', function ($http) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.editDevice = function (id, name, onUrl, offUrl) {
|
this.editDevice = function (id, name, onUrl, offUrl) {
|
||||||
this.device.id = id;
|
self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl};
|
||||||
this.device.name = name;
|
|
||||||
this.device.onUrl = onUrl;
|
|
||||||
this.device.offUrl = offUrl;
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
app.controller('ViewingController', function ($scope, bridgeService) {
|
app.controller('ViewingController', function ($scope, $location, bridgeService, BridgeSettings) {
|
||||||
|
|
||||||
|
$scope.BridgeSettings = bridgeService.BridgeSettings;
|
||||||
bridgeService.viewDevices();
|
bridgeService.viewDevices();
|
||||||
bridgeService.viewBridgeSettings();
|
|
||||||
bridgeService.viewVeraDevices();
|
|
||||||
bridgeService.viewVeraScenes();
|
|
||||||
$scope.bridge = bridgeService.state;
|
$scope.bridge = bridgeService.state;
|
||||||
$scope.deleteDevice = function (device) {
|
$scope.deleteDevice = function (device) {
|
||||||
bridgeService.deleteDevice(device.id);
|
bridgeService.deleteDevice(device.id);
|
||||||
@@ -183,13 +210,20 @@ app.controller('ViewingController', function ($scope, bridgeService) {
|
|||||||
};
|
};
|
||||||
$scope.editDevice = function (device) {
|
$scope.editDevice = function (device) {
|
||||||
bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl);
|
bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl);
|
||||||
|
$location.path('/editor');
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
app.controller('AddingController', function ($scope, bridgeService) {
|
app.controller('AddingController', function ($scope, bridgeService, BridgeSettings) {
|
||||||
|
|
||||||
$scope.device = {id: "", name: "", type: "switch", onUrl: "", offUrl: ""};
|
$scope.device = {id: "", name: "", type: "switch", onUrl: "", offUrl: ""};
|
||||||
$scope.vera = {base: "", port: "3480", id: ""};
|
$scope.vera = {base: "", port: "3480", id: ""};
|
||||||
|
$scope.vera.base = "http://" + BridgeSettings.veraaddress;
|
||||||
bridgeService.device = $scope.device;
|
bridgeService.device = $scope.device;
|
||||||
|
bridgeService.viewVeraDevices();
|
||||||
|
bridgeService.viewVeraScenes();
|
||||||
|
$scope.bridge = bridgeService.state;
|
||||||
|
$scope.device = bridgeService.state.device;
|
||||||
|
|
||||||
$scope.buildUrls = function () {
|
$scope.buildUrls = function () {
|
||||||
if ($scope.vera.base.indexOf("http") < 0) {
|
if ($scope.vera.base.indexOf("http") < 0) {
|
||||||
@@ -203,9 +237,9 @@ app.controller('AddingController', function ($scope, bridgeService) {
|
|||||||
+ $scope.vera.id;
|
+ $scope.vera.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.buildDeviceUrls = function (veradevice, veraaddr) {
|
$scope.buildDeviceUrls = function (veradevice) {
|
||||||
if ($scope.vera.base.indexOf("http") < 0) {
|
if ($scope.vera.base.indexOf("http") < 0) {
|
||||||
$scope.vera.base = "http://" + veraaddr;
|
$scope.vera.base = "http://" + $scope.vera.base;
|
||||||
}
|
}
|
||||||
$scope.device.name = veradevice.name;
|
$scope.device.name = veradevice.name;
|
||||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||||
@@ -216,9 +250,9 @@ app.controller('AddingController', function ($scope, bridgeService) {
|
|||||||
+ veradevice.id;
|
+ veradevice.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.buildSceneUrls = function (verascene, veraaddr) {
|
$scope.buildSceneUrls = function (verascene) {
|
||||||
if ($scope.vera.base.indexOf("http") < 0) {
|
if ($scope.vera.base.indexOf("http") < 0) {
|
||||||
$scope.vera.base = "http://" + veraaddr;
|
$scope.vera.base = "http://" + $scope.vera.base;
|
||||||
}
|
}
|
||||||
$scope.device.name = verascene.name;
|
$scope.device.name = verascene.name;
|
||||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||||
@@ -229,10 +263,6 @@ app.controller('AddingController', function ($scope, bridgeService) {
|
|||||||
+ verascene.id;
|
+ verascene.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.setVeraAddress = function (anAddress) {
|
|
||||||
$scope.vera.base = "http://" + anAddress;
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.testUrl = function (url) {
|
$scope.testUrl = function (url) {
|
||||||
window.open(url, "_blank");
|
window.open(url, "_blank");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,23 +33,23 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>upnp.config.address</td>
|
<td>upnp.config.address</td>
|
||||||
<td>{{bridge.upnpconfigaddress}}</td>
|
<td>{{BridgeSettings.upnpconfigaddress}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>server.port</td>
|
<td>server.port</td>
|
||||||
<td>{{bridge.serverport}}</td>
|
<td>{{BridgeSettings.serverport}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>upnp.devices.db</td>
|
<td>upnp.devices.db</td>
|
||||||
<td>{{bridge.upnpdevicedb}}</td>
|
<td>{{BridgeSettings.upnpdevicedb}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>upnp.response.port</td>
|
<td>upnp.response.port</td>
|
||||||
<td>{{bridge.upnpresponseport}}</td>
|
<td>{{BridgeSettings.upnpresponseport}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>vera.address</td>
|
<td>vera.address</td>
|
||||||
<td>{{bridge.veraaddress}}</td>
|
<td>{{BridgeSettings.veraaddress}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<td>{{veradevice.room}}</td>
|
<td>{{veradevice.room}}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-success" type="submit"
|
<button class="btn btn-success" type="submit"
|
||||||
ng-click="buildDeviceUrls(veradevice, bridge.veraaddress)">Generate
|
ng-click="buildDeviceUrls(veradevice)">Generate
|
||||||
Device URLs</button>
|
Device URLs</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
<td>{{verascene.room}}</td>
|
<td>{{verascene.room}}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-success" type="submit"
|
<button class="btn btn-success" type="submit"
|
||||||
ng-click="buildSceneUrls(verascene, bridge.veraaddress)">Generate
|
ng-click="buildSceneUrls(verascene)">Generate
|
||||||
Device URLs</button>
|
Device URLs</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -89,9 +89,6 @@
|
|||||||
ng-model="vera.base"
|
ng-model="vera.base"
|
||||||
placeholder="Vera URL (e.g. http://192.168.1.100)">
|
placeholder="Vera URL (e.g. http://192.168.1.100)">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" ng-click="setVeraAddress(bridge.veraaddress)"
|
|
||||||
class="col-xs-4 col-sm-2 btn btn-success">Use
|
|
||||||
vera.address</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-xs-2 col-sm-2 control-label" for="vera-port">Vera
|
<label class="col-xs-2 col-sm-2 control-label" for="vera-port">Vera
|
||||||
|
|||||||
Reference in New Issue
Block a user