mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 16:17:30 +00:00
Finished Domoticz impl and secure calls for Home Assistant
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>4.1.0beta3</version>
|
<version>4.1.0beta4</version>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.bwssystems.HABridge.plugins.domoticz;
|
|||||||
public class DomoticzDevice {
|
public class DomoticzDevice {
|
||||||
private String devicetype;
|
private String devicetype;
|
||||||
private String devicename;
|
private String devicename;
|
||||||
|
private String idx;
|
||||||
private String domoticzaddress;
|
private String domoticzaddress;
|
||||||
private String domoticzname;
|
private String domoticzname;
|
||||||
public String getDevicetype() {
|
public String getDevicetype() {
|
||||||
@@ -17,6 +18,12 @@ public class DomoticzDevice {
|
|||||||
public void setDevicename(String devicename) {
|
public void setDevicename(String devicename) {
|
||||||
this.devicename = devicename;
|
this.devicename = devicename;
|
||||||
}
|
}
|
||||||
|
public String getIdx() {
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
public void setIdx(String idx) {
|
||||||
|
this.idx = idx;
|
||||||
|
}
|
||||||
public String getDomoticzaddress() {
|
public String getDomoticzaddress() {
|
||||||
return domoticzaddress;
|
return domoticzaddress;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ public class DomoticzHandler {
|
|||||||
DomoticzDevice aNewDomoticzDevice = new DomoticzDevice();
|
DomoticzDevice aNewDomoticzDevice = new DomoticzDevice();
|
||||||
aNewDomoticzDevice.setDevicetype(theDevice.getType());
|
aNewDomoticzDevice.setDevicetype(theDevice.getType());
|
||||||
aNewDomoticzDevice.setDevicename(theDevice.getName());
|
aNewDomoticzDevice.setDevicename(theDevice.getName());
|
||||||
aNewDomoticzDevice.setDomoticzaddress(domoticzAddress.getIp());
|
aNewDomoticzDevice.setIdx(theDevice.getIdx());
|
||||||
|
aNewDomoticzDevice.setDomoticzaddress(domoticzAddress.getIp() + ":" + domoticzAddress.getPort());
|
||||||
aNewDomoticzDevice.setDomoticzname(domoticzAddress.getName());
|
aNewDomoticzDevice.setDomoticzname(domoticzAddress.getName());
|
||||||
deviceList.add(aNewDomoticzDevice);
|
deviceList.add(aNewDomoticzDevice);
|
||||||
|
|
||||||
|
|||||||
@@ -65,12 +65,7 @@ public class DomoticzHome implements Home {
|
|||||||
Iterator<DomoticzDevice> devices = theSourceList.iterator();
|
Iterator<DomoticzDevice> devices = theSourceList.iterator();
|
||||||
while(devices.hasNext()) {
|
while(devices.hasNext()) {
|
||||||
DomoticzDevice theDevice = devices.next();
|
DomoticzDevice theDevice = devices.next();
|
||||||
DomoticzDevice aNewDomoticzDevice = new DomoticzDevice();
|
theDeviceList.add(theDevice);
|
||||||
aNewDomoticzDevice.setDevicetype(theDevice.getDevicetype());
|
|
||||||
aNewDomoticzDevice.setDevicename(theDevice.getDevicename());
|
|
||||||
aNewDomoticzDevice.setDomoticzaddress(domoticzs.get(theKey).getDomoticzAddress().getIp());
|
|
||||||
aNewDomoticzDevice.setDomoticzname(theKey);
|
|
||||||
theDeviceList.add(aNewDomoticzDevice);
|
|
||||||
}
|
}
|
||||||
anHttpHandler = new HTTPHandler();
|
anHttpHandler = new HTTPHandler();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ public class HassDevice {
|
|||||||
private State deviceState;
|
private State deviceState;
|
||||||
private String deviceName;
|
private String deviceName;
|
||||||
private String domain;
|
private String domain;
|
||||||
|
private Boolean secure;
|
||||||
private String hassaddress;
|
private String hassaddress;
|
||||||
private String hassname;
|
private String hassname;
|
||||||
public State getDeviceState() {
|
public State getDeviceState() {
|
||||||
@@ -24,6 +25,12 @@ public class HassDevice {
|
|||||||
public void setDomain(String domain) {
|
public void setDomain(String domain) {
|
||||||
this.domain = domain;
|
this.domain = domain;
|
||||||
}
|
}
|
||||||
|
public Boolean getSecure() {
|
||||||
|
return secure;
|
||||||
|
}
|
||||||
|
public void setSecure(Boolean secure) {
|
||||||
|
this.secure = secure;
|
||||||
|
}
|
||||||
public String getHassaddress() {
|
public String getHassaddress() {
|
||||||
return hassaddress;
|
return hassaddress;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ public class HomeAssistant {
|
|||||||
public Boolean callCommand(HassCommand aCommand) {
|
public Boolean callCommand(HassCommand aCommand) {
|
||||||
log.debug("calling HomeAssistant: " + aCommand.getHassName() + " - "
|
log.debug("calling HomeAssistant: " + aCommand.getHassName() + " - "
|
||||||
+ aCommand.getEntityId() + " - " + aCommand.getState() + " - " + aCommand.getBri());
|
+ aCommand.getEntityId() + " - " + aCommand.getState() + " - " + aCommand.getBri());
|
||||||
String aUrl = "http://" + hassAddress.getIp() + ":" + hassAddress.getPort() + "/api/services/" + aCommand.getEntityId().substring(0, aCommand.getEntityId().indexOf("."));
|
String aUrl = null;
|
||||||
|
if(hassAddress.getSecure())
|
||||||
|
aUrl = "https";
|
||||||
|
else
|
||||||
|
aUrl = "http";
|
||||||
|
aUrl = aUrl + "://" + hassAddress.getIp() + ":" + hassAddress.getPort() + "/api/services/" + aCommand.getEntityId().substring(0, aCommand.getEntityId().indexOf("."));
|
||||||
String aBody = "{\"entity_id\":\"" + aCommand.getEntityId() + "\"";
|
String aBody = "{\"entity_id\":\"" + aCommand.getEntityId() + "\"";
|
||||||
NameValue[] headers = null;
|
NameValue[] headers = null;
|
||||||
if(hassAddress.getPassword() != null && !hassAddress.getPassword().isEmpty()) {
|
if(hassAddress.getPassword() != null && !hassAddress.getPassword().isEmpty()) {
|
||||||
@@ -75,7 +80,11 @@ public class HomeAssistant {
|
|||||||
headers = new NameValue[1];
|
headers = new NameValue[1];
|
||||||
headers[0] = password;
|
headers[0] = password;
|
||||||
}
|
}
|
||||||
theUrl = "http://" + hassAddress.getIp() + ":" + hassAddress.getPort() + "/api/states";
|
if(hassAddress.getSecure())
|
||||||
|
theUrl = "https";
|
||||||
|
else
|
||||||
|
theUrl = "http";
|
||||||
|
theUrl = theUrl + "://" + hassAddress.getIp() + ":" + hassAddress.getPort() + "/api/states";
|
||||||
theData = anHttpHandler.doHttpRequest(theUrl, HttpGet.METHOD_NAME, "application/json", null, headers);
|
theData = anHttpHandler.doHttpRequest(theUrl, HttpGet.METHOD_NAME, "application/json", null, headers);
|
||||||
if(theData != null) {
|
if(theData != null) {
|
||||||
log.debug("GET Hass States - data: " + theData);
|
log.debug("GET Hass States - data: " + theData);
|
||||||
|
|||||||
@@ -947,11 +947,11 @@ app.controller ('SystemController', function ($scope, $location, $http, $window,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$scope.addHasstoSettings = function (newhassname, newhassip, newhassport, newhasspassword) {
|
$scope.addHasstoSettings = function (newhassname, newhassip, newhassport, newhasspassword, newhasssecure) {
|
||||||
if($scope.bridge.settings.hassaddress === undefined || $scope.bridge.settings.hassaddress === null) {
|
if($scope.bridge.settings.hassaddress === undefined || $scope.bridge.settings.hassaddress === null) {
|
||||||
$scope.bridge.settings.hassaddress = { devices: [] };
|
$scope.bridge.settings.hassaddress = { devices: [] };
|
||||||
}
|
}
|
||||||
var newhass = {name: newhassname, ip: newhassip, port: newhassport, password: newhasspassword }
|
var newhass = {name: newhassname, ip: newhassip, port: newhassport, password: newhasspassword, secure: newhasssecure }
|
||||||
$scope.bridge.settings.hassaddress.devices.push(newhass);
|
$scope.bridge.settings.hassaddress.devices.push(newhass);
|
||||||
$scope.newhassname = null;
|
$scope.newhassname = null;
|
||||||
$scope.newhassip = null;
|
$scope.newhassip = null;
|
||||||
@@ -2141,47 +2141,42 @@ app.controller('DomoticzController', function ($scope, $location, $http, bridgeS
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.buildDeviceUrls = function (domoticzdevice, dim_control) {
|
$scope.buildDeviceUrls = function (domoticzdevice, dim_control) {
|
||||||
var preOnCmd = "";
|
var preCmd = "";
|
||||||
var preDimCmd = "";
|
var postOnCmd = "";
|
||||||
var preOffCmd = "";
|
var postDimCmd = "";
|
||||||
|
var postOffCmd = "";
|
||||||
var nameCmd = "";
|
var nameCmd = "";
|
||||||
var aDeviceType;
|
var aDeviceType;
|
||||||
var postCmd = "";
|
var postCmd = "";
|
||||||
if(domoticzdevice.devicetype === "Scene") {
|
if(domoticzdevice.devicetype === "Scene") {
|
||||||
aDeviceType = "scene";
|
aDeviceType = "scene";
|
||||||
preOnCmd = "/SceneService!SceneCmd=Set!SceneName=";
|
preCmd = "/json.htm?type=command¶m=switchscene&idx="
|
||||||
preOffCmd = preOnCmd;
|
postOnCmd = "&switchcmd=On";
|
||||||
|
postOffCmd = "&switchcmd=Off";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
aDeviceType = "switch";
|
aDeviceType = "switch";
|
||||||
preOnCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=On";
|
preCmd = "/json.htm?type=command¶m=switchlight&idx="
|
||||||
preDimCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=Dim!DevicePercent=";
|
postOnCmd = "&switchcmd=On";
|
||||||
preOffCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=Off";
|
postDimCmd = "&switchcmd=Set%20Level&level=";
|
||||||
nameCmd = "!DeviceName=";
|
postOffCmd = "&switchcmd=Off";
|
||||||
}
|
}
|
||||||
if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && aDeviceType === "switch")
|
if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && aDeviceType === "switch")
|
||||||
dimpayload = "http://" + domoticzdevice.domoticzaddress
|
dimpayload = "http://" + domoticzdevice.domoticzaddress
|
||||||
+ preDimCmd
|
+ preCmd
|
||||||
+ dim_control
|
+ domoticzdevice.idx
|
||||||
+ nameCmd
|
+ postDimCmd
|
||||||
+ domoticzdevice.devicename.replaceAll(" ", "%20")
|
+ dim_control;
|
||||||
+ postCmd;
|
|
||||||
else
|
else
|
||||||
dimpayload = "http://" + domoticzdevice.domoticzaddress
|
dimpayload = null;
|
||||||
+ preOnCmd
|
|
||||||
+ nameCmd
|
|
||||||
+ domoticzdevice.devicename.replaceAll(" ", "%20")
|
|
||||||
+ postCmd;
|
|
||||||
onpayload = "http://" + domoticzdevice.domoticzaddress
|
onpayload = "http://" + domoticzdevice.domoticzaddress
|
||||||
+ preOnCmd
|
+ preCmd
|
||||||
+ nameCmd
|
+ domoticzdevice.idx
|
||||||
+ domoticzdevice.devicename.replaceAll(" ", "%20")
|
+ postOnCmd;
|
||||||
+ postCmd;
|
|
||||||
offpayload = "http://" + domoticzdevice.domoticzaddress
|
offpayload = "http://" + domoticzdevice.domoticzaddress
|
||||||
+ preOffCmd
|
+ preCmd
|
||||||
+ nameCmd
|
+ domoticzdevice.idx
|
||||||
+ domoticzdevice.haldevicename.replaceAll(" ", "%20")
|
+ postOffCmd;
|
||||||
+ postCmd;
|
|
||||||
bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, domoticzdevice.devicename + "-" + domoticzdevice.domoticzname, domoticzdevice.devicename, domoticzdevice.domoticzname, aDeviceType, "domoticzDevice", null, null);
|
bridgeService.buildUrls(onpayload, dimpayload, offpayload, false, domoticzdevice.devicename + "-" + domoticzdevice.domoticzname, domoticzdevice.devicename, domoticzdevice.domoticzname, aDeviceType, "domoticzDevice", null, null);
|
||||||
$scope.device = bridgeService.state.device;
|
$scope.device = bridgeService.state.device;
|
||||||
bridgeService.editNewDevice($scope.device);
|
bridgeService.editNewDevice($scope.device);
|
||||||
|
|||||||
@@ -277,6 +277,7 @@
|
|||||||
<th>IP</th>
|
<th>IP</th>
|
||||||
<th>Port</th>
|
<th>Port</th>
|
||||||
<th>Password (opt)</th>
|
<th>Password (opt)</th>
|
||||||
|
<th>Use SSL</th>
|
||||||
<th>Manage</th>
|
<th>Manage</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -286,6 +287,7 @@
|
|||||||
<td>{{hass.port}}</td>
|
<td>{{hass.port}}</td>
|
||||||
<td ng-if="hass.password">*******</td>
|
<td ng-if="hass.password">*******</td>
|
||||||
<td ng-if="!hass.password"> </td>
|
<td ng-if="!hass.password"> </td>
|
||||||
|
<td>{{hass.secure}}</td>
|
||||||
<td><button class="btn btn-danger" type="submit"
|
<td><button class="btn btn-danger" type="submit"
|
||||||
ng-click="removeHasstoSettings(hass.name, hass.ip)">Del</button></td>
|
ng-click="removeHasstoSettings(hass.name, hass.ip)">Del</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -302,8 +304,11 @@
|
|||||||
<td><input id="bridge-settings-next-hass-password"
|
<td><input id="bridge-settings-next-hass-password"
|
||||||
class="form-control" type="password" ng-model="newhasspassword"
|
class="form-control" type="password" ng-model="newhasspassword"
|
||||||
placeholder="Home Assistant password (opt)"></td>
|
placeholder="Home Assistant password (opt)"></td>
|
||||||
|
<td><input type="checkbox"
|
||||||
|
ng-model="newhasssecure" ng-true-value=true
|
||||||
|
ng-false-value=false></td>
|
||||||
<td><button class="btn btn-success" type="submit"
|
<td><button class="btn btn-success" type="submit"
|
||||||
ng-click="addHasstoSettings(newhassname, newhassip, newhassport, newhasspassword)">Add</button></td>
|
ng-click="addHasstoSettings(newhassname, newhassip, newhassport, newhasspassword, newhasssecure)">Add</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table></td>
|
</table></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user