mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 00:20:26 +00:00
Update application from amazon-echo-bridge-compact to ha-bridge.
Try to remove most code naming away from amazon. Fix package names being incorrect. Added Vera query functionality, needs some fine tuning.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
angular.module('amazonechobridge', [])
|
||||
angular.module('habridge', [])
|
||||
.service('bridgeService', ["$http", function ($http) {
|
||||
var self = this;
|
||||
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/configaddress", devices: [], error: ""};
|
||||
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], error: ""};
|
||||
|
||||
this.viewDevices = function () {
|
||||
this.state.error = "";
|
||||
@@ -21,11 +21,51 @@ angular.module('amazonechobridge', [])
|
||||
);
|
||||
};
|
||||
|
||||
this.viewConfigAddress = function () {
|
||||
this.viewBridgeSettings = function () {
|
||||
this.state.error = "";
|
||||
return $http.get(this.state.upnpbase).then(
|
||||
function (response) {
|
||||
self.state.upnpconfigaddress = response.data;
|
||||
self.state.upnpconfigaddress = response.data.upnpconfigaddress;
|
||||
self.state.serverport = response.data.serverport;
|
||||
self.state.upnpdevicedb = response.data.upnpdevicedb;
|
||||
self.state.upnpresponseport = response.data.upnpresponseport;
|
||||
self.state.veraaddress = response.data.veraaddress;
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
} else {
|
||||
self.state.error = "If you're not seeing any address, you may be running into problems with CORS. " +
|
||||
"You can work around this by running a fresh launch of Chrome with the --disable-web-security flag.";
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.viewVeraDevices = function () {
|
||||
this.state.error = "";
|
||||
return $http.get(this.state.base + "/vera/devices").then(
|
||||
function (response) {
|
||||
self.state.veradevices = response.data;
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
self.state.error = error.data.message;
|
||||
} else {
|
||||
self.state.error = "If you're not seeing any address, you may be running into problems with CORS. " +
|
||||
"You can work around this by running a fresh launch of Chrome with the --disable-web-security flag.";
|
||||
}
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.viewVeraScenes = function () {
|
||||
this.state.error = "";
|
||||
return $http.get(this.state.base + "/vera/scenes").then(
|
||||
function (response) {
|
||||
self.state.verascenes = response.data;
|
||||
},
|
||||
function (error) {
|
||||
if (error.data) {
|
||||
@@ -105,7 +145,9 @@ angular.module('amazonechobridge', [])
|
||||
|
||||
.controller('ViewingController', ["$scope", "bridgeService", function ($scope, bridgeService) {
|
||||
bridgeService.viewDevices();
|
||||
bridgeService.viewConfigAddress();
|
||||
bridgeService.viewBridgeSettings();
|
||||
bridgeService.viewVeraDevices();
|
||||
bridgeService.viewVeraScenes();
|
||||
$scope.bridge = bridgeService.state;
|
||||
$scope.deleteDevice = function (device) {
|
||||
bridgeService.deleteDevice(device.id);
|
||||
@@ -123,12 +165,10 @@ angular.module('amazonechobridge', [])
|
||||
}])
|
||||
|
||||
.controller('AddingController', ["$scope", "bridgeService", function ($scope, bridgeService) {
|
||||
|
||||
$scope.bridge = bridgeService.state;
|
||||
$scope.device = {id: "", name: "", type: "switch", onUrl: "", offUrl: ""};
|
||||
$scope.vera = {base: "", port: "3480", id: ""};
|
||||
bridgeService.device = $scope.device;
|
||||
|
||||
|
||||
$scope.buildUrls = function () {
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + $scope.vera.base;
|
||||
@@ -141,6 +181,36 @@ angular.module('amazonechobridge', [])
|
||||
+ $scope.vera.id;
|
||||
};
|
||||
|
||||
$scope.buildDeviceUrls = function (veradevice, veraaddr) {
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + veraaddr;
|
||||
}
|
||||
$scope.device.name = veradevice.name;
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ veradevice.id;
|
||||
$scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum="
|
||||
+ veradevice.id;
|
||||
};
|
||||
|
||||
$scope.buildSceneUrls = function (verascene, veraaddr) {
|
||||
if ($scope.vera.base.indexOf("http") < 0) {
|
||||
$scope.vera.base = "http://" + veraaddr;
|
||||
}
|
||||
$scope.device.name = verascene.name;
|
||||
$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;
|
||||
$scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||
+ verascene.id;
|
||||
};
|
||||
|
||||
$scope.setVeraAddress = function (anAddress) {
|
||||
$scope.vera.base = "http://" + anAddress;
|
||||
};
|
||||
|
||||
$scope.testUrl = function (url) {
|
||||
window.open(url, "_blank");
|
||||
};
|
||||
@@ -157,6 +227,7 @@ angular.module('amazonechobridge', [])
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}])
|
||||
|
||||
.controller('ErrorsController', ["$scope", "bridgeService", function ($scope, bridgeService) {
|
||||
|
||||
Reference in New Issue
Block a user