HomeAssistant continuation

This commit is contained in:
Admin
2016-12-16 16:10:49 -06:00
parent 74cccd6de3
commit 74c15db202
7 changed files with 98 additions and 71 deletions

View File

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

View File

@@ -195,7 +195,7 @@ public class HueMulator implements HueErrorStringSet {
return new Gson().toJson(theResponse, GroupResponse.class);
}
return "[{\"error\":{\"type\":\"3\", \"address\": \"/api/" + userId + "/groups/" + "0"
return "[{\"error\":{\"type\":\"3\", \"address\": \"/api/" + userId + "/groups/" + groupId
+ "\",\"description\": \"Object not found\"}}]";
});
// http://ip_address:port/api/{userId}/scenes returns json objects of
@@ -495,6 +495,37 @@ public class HueMulator implements HueErrorStringSet {
return apiResponse;
} , new JsonTransformer());
// http://ip_address:port/api/{userId}/ returns json objects for the full
// state
get(HUE_CONTEXT + "/:userid/", "application/json", (request, response) -> {
String userId = request.params(":userid");
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.type("application/json");
response.status(HttpStatus.SC_OK);
log.debug("hue api full state requested: " + userId + " from " + request.ip());
if (validateWhitelistUser(userId, false) == null) {
log.debug("Valudate user, No User supplied");
HueErrorResponse theErrorResp = new HueErrorResponse();
theErrorResp.addError(new HueError(
new HueErrorDetails("1", "/api/" + userId, "unauthorized user", null, null, null)));
return theErrorResp.getTheErrors();
}
List<DeviceDescriptor> descriptorList = repository.findAll();
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(),
bridgeSettings.getWhitelist());
Map<String, DeviceResponse> deviceList = new HashMap<>();
if (descriptorList != null) {
descriptorList.forEach(descriptor -> {
DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor);
deviceList.put(descriptor.getId(), deviceResponse);
});
apiResponse.setLights(deviceList);
}
return apiResponse;
} , new JsonTransformer());
// http://ip_address:port/api/{userId}/lights/{lightId} returns json
// object for a given light
get(HUE_CONTEXT + "/:userid/lights/:id", "application/json", (request, response) -> {

View File

@@ -2,6 +2,8 @@ package com.bwssystems.hass;
public class HassDevice {
private State deviceState;
private String deviceName;
private String domain;
private String hassaddress;
private String hassname;
public State getDeviceState() {
@@ -10,6 +12,18 @@ public class HassDevice {
public void setDeviceState(State deviceState) {
this.deviceState = deviceState;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getHassaddress() {
return hassaddress;
}

View File

@@ -59,6 +59,8 @@ public class HassHome {
aNewHassDevice.setDeviceState(theDevice);
aNewHassDevice.setHassaddress(hassMap.get(theKey).getHassAddress().getIp());
aNewHassDevice.setHassname(theKey);
aNewHassDevice.setDeviceName(theDevice.getAttributes().get("friendly_name").getAsString());
aNewHassDevice.setDomain(theDevice.getEntityId().substring(0, theDevice.getEntityId().indexOf(".")));
theDeviceList.add(aNewHassDevice);
}
return true;

View File

@@ -41,7 +41,7 @@ app.config(function ($routeProvider) {
templateUrl: 'views/mqttpublish.html',
controller: 'MQTTController'
}).when('/hassdevices', {
templateUrl: 'views/hassevice.html',
templateUrl: 'views/hassdevice.html',
controller: 'HassController'
}).otherwise({
templateUrl: 'views/configuration.html',
@@ -742,6 +742,23 @@ app.controller('SystemController', function ($scope, $location, $http, $window,
}
}
};
$scope.addHasstoSettings = function (newhassname, newhassip, newhassport) {
if($scope.bridge.settings.hassaddress == null) {
$scope.bridge.settings.hassaddress = { devices: [] };
}
var newhass = {name: newhassname, ip: newhassip, port: newhassport }
$scope.bridge.settings.hassaddress.devices.push(newhass);
$scope.newhassname = null;
$scope.newhassip = null;
$scope.newhassport = null;
};
$scope.removeHasstoSettings = function (hassname, hassip) {
for(var i = $scope.bridge.settings.hassaddress.devices.length - 1; i >= 0; i--) {
if($scope.bridge.settings.hassaddress.devices[i].name === hassname && $scope.bridge.settings.hassaddress.devices[i].ip === hassip) {
$scope.bridge.settings.hassaddress.devices.splice(i, 1);
}
}
};
$scope.bridgeReinit = function () {
bridgeService.reinit();
};
@@ -951,6 +968,10 @@ app.controller('DeleteMapandIdDialogCtrl', function ($scope, bridgeService, ngDi
bridgeService.viewHueDevices();
if(mapandid.mapType == "halDevice")
bridgeService.viewHalDevices();
if(mapandid.mapType == "mqttMessage")
bridgeService.viewMQTTDevices();
if(mapandid.mapType == "hassDevice")
bridgeService.viewHassDevices();
$scope.bridge.mapandid = null;
};
});
@@ -1856,72 +1877,25 @@ app.controller('HassController', function ($scope, $location, $http, bridgeServi
$scope.buildDeviceUrls = function (hassdevice, dim_control) {
bridgeService.clearDevice();
$scope.device = $scope.bridge.device;
var preOnCmd = "";
var preDimCmd = "";
var preOffCmd = "";
var nameCmd = ""
var postCmd = "?Token=" + $scope.bridge.settings.haltoken;
if(hassdevice.hassdevicetype == "Group") {
$scope.device.deviceType = "group";
preOnCmd = "/GroupService!GroupCmd=On";
preOffCmd = "/GroupService!GroupCmd=Off";
nameCmd = "!GroupName=";
if( $scope.device.mapType == "hassDevice" ) {
$scope.device.mapId = $scope.device.mapId + "-" + hassdevice.deviceState.entity_id;
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"item\":\"{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"state\":\"on\"}\"}]";
if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0))
$scope.device.dimUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"item\":\"{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"state\":\"on\",\"bri\":\"" + dim_control + "\"}\"}]";
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"item\":\"{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"state\":\"off\"}\"}]";
}
else if(hassdevice.hassdevicetype == "Macro") {
$scope.device.deviceType = "macro";
preOnCmd = "/MacroService!MacroCmd=Set!MacroName=";
preOffCmd = preOnCmd;
}
else if(hassdevice.hassdevicetype == "Scene") {
$scope.device.deviceType = "scene";
preOnCmd = "/SceneService!SceneCmd=Set!SceneName=";
preOffCmd = preOnCmd;
}
else {
$scope.device.deviceType = "switch";
preOnCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=On";
preDimCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=Dim!DevicePercent=";
preOffCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=Off";
nameCmd = "!DeviceName=";
}
$scope.device.name = hassdevice.hassdevicename;
$scope.device.targetDevice = hassdevice.halname;
$scope.device.mapType = "hassdevice";
$scope.device.mapId = hassdevice.hassdevicename + "-" + hassdevice.halname;
if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && $scope.device.deviceType == "switch")
$scope.device.dimUrl = "http://" + hassdevice.haladdress
+ preDimCmd
+ dim_control
+ nameCmd
+ hassdevice.hassdevicename.replaceAll(" ", "%20")
+ postCmd;
else
$scope.device.dimUrl = "http://" + hassdevice.haladdress
+ preOnCmd
+ nameCmd
+ hassdevice.hassdevicename.replaceAll(" ", "%20")
+ postCmd;
$scope.device.onUrl = "http://" + hassdevice.haladdress
+ preOnCmd
+ nameCmd
+ hassdevice.hassdevicename.replaceAll(" ", "%20")
+ postCmd;
$scope.device.offUrl = "http://" + hassdevice.haladdress
+ preOffCmd
+ nameCmd
+ hassdevice.hassdevicename.replaceAll(" ", "%20")
+ postCmd;
};
$scope.buildHassHomeUrls = function (hassdevice) {
else if ($scope.device.mapType == null || $scope.device.mapType == "") {
bridgeService.clearDevice();
$scope.device.deviceType = "home";
$scope.device.name = hassdevice.hassdevicename;
$scope.device.targetDevice = hassdevice.halname;
$scope.device.mapType = "halHome";
$scope.device.mapId = hassdevice.hassdevicename + "-" + hassdevice.halname + "-HomeAway";
$scope.device.onUrl = "http://" + hassdevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Home?Token=" + $scope.bridge.settings.haltoken;
$scope.device.offUrl = "http://" + hassdevice.haladdress + "/ModeService!ModeCmd=Set!ModeName=Away?Token=" + $scope.bridge.settings.haltoken;
$scope.device.deviceType = hassdevice.domain;
$scope.device.targetDevice = hassdevice.hassname;
$scope.device.name = hassdevice.deviceState.entity_id;
$scope.device.mapType = "hassDevice";
$scope.device.mapId = hassdevice.hassname + "-" + hassdevice.deviceState.entity_id;
$scope.device.onUrl = "[{\"item\":\"{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"state\":\"on\"}\"}]";
if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0))
$scope.device.dimUrl = "[{\"item\":\"{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"state\":\"on\",\"bri\":\"" + dim_control + "\"}\"}]";
$scope.device.offUrl = "[{\"item\":\"{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"state\":\"off\"}\"}]";
}
};
$scope.buildHassHeatUrls = function (hassdevice) {

View File

@@ -70,10 +70,10 @@
{{hassdevice.deviceState.entity_id}}</td>
<td>{{hassdevice.hassname}}</td>
<td>
<button ng-if="hassdevice.hassdevicetype != 'Home' && hassdevice.hassdevicetype != 'HVAC' && hassdevice.hassdevicetype != 'IrData'" class="btn btn-success" type="submit"
<button ng-if="hassdevice.domain != 'climate' && hassdevice.domain != 'sensor' && hassdevice.domain != 'sun'" class="btn btn-success" type="submit"
ng-click="buildDeviceUrls(hassdevice, device_dim_control)">Generate
Bridge Device</button>
<ul ng-if="hassdevice.hassdevicetype == 'HVAC'" class="list-group">
<ul ng-if="hassdevice.domain == 'climate'" class="list-group">
<li class="list-group-item">
<p>
<button class="btn btn-success" type="submit"

View File

@@ -276,6 +276,7 @@
<th>Name</th>
<th>IP</th>
<th>Port</th>
<th>Password (opt)</th>
<th>Manage</th>
</tr>
</thead>
@@ -283,6 +284,8 @@
<td>{{hass.name}}</td>
<td>{{hass.ip}}</td>
<td>{{hass.port}}</td>
<td ng-if="hass.password">*******</td>
<td ng-if="!hass.password"> </td>
<td><button class="btn btn-danger" type="submit"
ng-click="removeHasstoSettings(hass.name, hass.ip)">Del</button></td>
</tr>
@@ -295,9 +298,12 @@
placeholder="192.168.1.3"></td>
<td><input id="bridge-settings-next-hass-port"
class="form-control" type="text" ng-model="newhassport"
deafult="8123"></td>
placeholder="8123"></td>
<td><input id="bridge-settings-next-hass-password"
class="form-control" type="password" ng-model="newhasspassword"
placeholder="MQTT Broker password (opt)"></td>
<td><button class="btn btn-success" type="submit"
ng-click="addHasstoSettings(newhassname, newhassip, newhassport)">Add</button></td>
ng-click="addHasstoSettings(newhassname, newhassip, newhassport, newhasspassword)">Add</button></td>
</tr>
</table></td>
</tr>