Finished Domoticz impl and secure calls for Home Assistant

This commit is contained in:
Admin
2017-01-25 16:24:44 -06:00
parent 6abe1b082c
commit 4b7ba0fabe
8 changed files with 59 additions and 40 deletions

View File

@@ -3,6 +3,7 @@ package com.bwssystems.HABridge.plugins.domoticz;
public class DomoticzDevice {
private String devicetype;
private String devicename;
private String idx;
private String domoticzaddress;
private String domoticzname;
public String getDevicetype() {
@@ -17,6 +18,12 @@ public class DomoticzDevice {
public void setDevicename(String devicename) {
this.devicename = devicename;
}
public String getIdx() {
return idx;
}
public void setIdx(String idx) {
this.idx = idx;
}
public String getDomoticzaddress() {
return domoticzaddress;
}

View File

@@ -57,7 +57,8 @@ public class DomoticzHandler {
DomoticzDevice aNewDomoticzDevice = new DomoticzDevice();
aNewDomoticzDevice.setDevicetype(theDevice.getType());
aNewDomoticzDevice.setDevicename(theDevice.getName());
aNewDomoticzDevice.setDomoticzaddress(domoticzAddress.getIp());
aNewDomoticzDevice.setIdx(theDevice.getIdx());
aNewDomoticzDevice.setDomoticzaddress(domoticzAddress.getIp() + ":" + domoticzAddress.getPort());
aNewDomoticzDevice.setDomoticzname(domoticzAddress.getName());
deviceList.add(aNewDomoticzDevice);

View File

@@ -65,12 +65,7 @@ public class DomoticzHome implements Home {
Iterator<DomoticzDevice> devices = theSourceList.iterator();
while(devices.hasNext()) {
DomoticzDevice theDevice = devices.next();
DomoticzDevice aNewDomoticzDevice = new DomoticzDevice();
aNewDomoticzDevice.setDevicetype(theDevice.getDevicetype());
aNewDomoticzDevice.setDevicename(theDevice.getDevicename());
aNewDomoticzDevice.setDomoticzaddress(domoticzs.get(theKey).getDomoticzAddress().getIp());
aNewDomoticzDevice.setDomoticzname(theKey);
theDeviceList.add(aNewDomoticzDevice);
theDeviceList.add(theDevice);
}
anHttpHandler = new HTTPHandler();
return true;

View File

@@ -4,6 +4,7 @@ public class HassDevice {
private State deviceState;
private String deviceName;
private String domain;
private Boolean secure;
private String hassaddress;
private String hassname;
public State getDeviceState() {
@@ -24,6 +25,12 @@ public class HassDevice {
public void setDomain(String domain) {
this.domain = domain;
}
public Boolean getSecure() {
return secure;
}
public void setSecure(Boolean secure) {
this.secure = secure;
}
public String getHassaddress() {
return hassaddress;
}

View File

@@ -36,7 +36,12 @@ public class HomeAssistant {
public Boolean callCommand(HassCommand aCommand) {
log.debug("calling HomeAssistant: " + aCommand.getHassName() + " - "
+ 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() + "\"";
NameValue[] headers = null;
if(hassAddress.getPassword() != null && !hassAddress.getPassword().isEmpty()) {
@@ -75,7 +80,11 @@ public class HomeAssistant {
headers = new NameValue[1];
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);
if(theData != null) {
log.debug("GET Hass States - data: " + theData);