mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-20 00:46:02 +00:00
Cleanup
This commit is contained in:
@@ -102,7 +102,7 @@ public class SomfyHome implements Home {
|
|||||||
validSomfy = bridgeSettings.isValidSomfy();
|
validSomfy = bridgeSettings.isValidSomfy();
|
||||||
log.info("Vera Home created." + (validSomfy ? "" : " No Veras configured."));
|
log.info("Vera Home created." + (validSomfy ? "" : " No Veras configured."));
|
||||||
if(validSomfy) {
|
if(validSomfy) {
|
||||||
somfys = new HashMap<String, SomfyInfo>();
|
somfys = new HashMap<>();
|
||||||
Iterator<NamedIP> theList = bridgeSettings.getSomfyAddress().getDevices().iterator();
|
Iterator<NamedIP> theList = bridgeSettings.getSomfyAddress().getDevices().iterator();
|
||||||
while (theList.hasNext()) {
|
while (theList.hasNext()) {
|
||||||
NamedIP aSomfy = theList.next();
|
NamedIP aSomfy = theList.next();
|
||||||
|
|||||||
@@ -51,34 +51,11 @@ public class SomfyInfo {
|
|||||||
|
|
||||||
private void initHttpClient() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
|
private void initHttpClient() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
|
||||||
if(httpClient==null) {
|
if(httpClient==null) {
|
||||||
httpClient = HttpClients.custom().
|
httpClient = HttpClients.createDefault();
|
||||||
setHostnameVerifier(new AllowAllHostnameVerifier()).
|
|
||||||
setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
|
||||||
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}).build()).build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This function executes the url against the vera
|
|
||||||
protected String doHttpGETRequest(String url) {
|
|
||||||
String theContent = null;
|
|
||||||
log.debug("calling GET on URL: " + url);
|
|
||||||
HttpGet httpGet = new HttpGet(url);
|
|
||||||
try {
|
|
||||||
HttpResponse response = httpClient.execute(httpGet);
|
|
||||||
log.debug("GET on URL responded: " + response.getStatusLine().getStatusCode());
|
|
||||||
if(response.getStatusLine().getStatusCode() == 200){
|
|
||||||
theContent = EntityUtils.toString(response.getEntity(), Charset.forName("UTF-8")); //read content for data
|
|
||||||
EntityUtils.consume(response.getEntity()); //close out inputstream ignore content
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("doHttpGETRequest: Error calling out to HA gateway: " + e.getMessage());
|
|
||||||
}
|
|
||||||
return theContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SomfyDevice> getSomfyDevices() {
|
public List<SomfyDevice> getSomfyDevices() {
|
||||||
|
|
||||||
@@ -100,72 +77,51 @@ public class SomfyInfo {
|
|||||||
|
|
||||||
initHttpClient();
|
initHttpClient();
|
||||||
HttpPost httpPost = new HttpPost(BASE_URL + "json/login");
|
HttpPost httpPost = new HttpPost(BASE_URL + "json/login");
|
||||||
|
|
||||||
//HttpHost proxy = new HttpHost("127.0.0.1", 8888, "http");
|
|
||||||
RequestConfig config = RequestConfig.custom()
|
|
||||||
// .setProxy(proxy)
|
|
||||||
.build();
|
|
||||||
httpPost.setConfig(config);
|
|
||||||
httpPost.addHeader("User-Agent","mine");
|
httpPost.addHeader("User-Agent","mine");
|
||||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||||
nvps.add(new BasicNameValuePair("userId", username));
|
nvps.add(new BasicNameValuePair("userId", username));
|
||||||
nvps.add(new BasicNameValuePair("userPassword", password));
|
nvps.add(new BasicNameValuePair("userPassword", password));
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
||||||
System.out.println("Making SOMFY http login call");
|
log.debug("Making SOMFY http login call");
|
||||||
HttpResponse response = httpClient.execute(httpPost);
|
HttpResponse response = httpClient.execute(httpPost);
|
||||||
|
|
||||||
//try {
|
log.debug(response.getStatusLine().toString());
|
||||||
System.out.println(response.getStatusLine());
|
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
EntityUtils.consume(entity);
|
EntityUtils.consume(entity);
|
||||||
//} finally {
|
|
||||||
// response.close();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetSetup getSetup() throws IOException, JSONException {
|
public GetSetup getSetup() throws IOException, JSONException {
|
||||||
HttpGet httpGet = new HttpGet(BASE_URL + "json/getSetup");
|
HttpGet httpGet = new HttpGet(BASE_URL + "json/getSetup");
|
||||||
httpGet.addHeader("User-Agent","mine");
|
httpGet.addHeader("User-Agent","mine");
|
||||||
System.out.println("Making SOMFY http setup call");
|
log.info("Making SOMFY http setup call");
|
||||||
|
|
||||||
HttpResponse response = httpClient.execute(httpGet);
|
HttpResponse response = httpClient.execute(httpGet);
|
||||||
//try {
|
log.debug(response.getStatusLine().toString());
|
||||||
System.out.println(response.getStatusLine());
|
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
|
|
||||||
String json = IOUtils.toString(entity.getContent());
|
String json = IOUtils.toString(entity.getContent());
|
||||||
System.out.println(json);
|
log.debug(json);
|
||||||
GetSetup setupData = new Gson().fromJson(json, GetSetup.class);
|
GetSetup setupData = new Gson().fromJson(json, GetSetup.class);
|
||||||
return setupData;
|
return setupData;
|
||||||
|
|
||||||
//} finally {
|
|
||||||
// response.close();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execApply(String jsonToPost) throws Exception {
|
public void execApply(String jsonToPost) throws Exception {
|
||||||
login("house@edonica.com", "drawde123");
|
login("house@edonica.com", "drawde123");
|
||||||
HttpPost httpPost = new HttpPost(BASE_URL_ENDUSER + "exec/apply");
|
HttpPost httpPost = new HttpPost(BASE_URL_ENDUSER + "exec/apply");
|
||||||
|
|
||||||
//HttpHost proxy = new HttpHost("127.0.0.1", 8888, "http");
|
RequestConfig config = RequestConfig.custom().build();
|
||||||
RequestConfig config = RequestConfig.custom()
|
|
||||||
// .setProxy(proxy)
|
|
||||||
.build();
|
|
||||||
httpPost.setConfig(config);
|
httpPost.setConfig(config);
|
||||||
httpPost.addHeader("User-Agent", "mine");
|
httpPost.addHeader("User-Agent", "mine");
|
||||||
httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
|
httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
|
||||||
httpPost.setEntity(new StringEntity(jsonToPost, "UTF-8"));
|
httpPost.setEntity(new StringEntity(jsonToPost, "UTF-8"));
|
||||||
System.out.println("Making SOMFY http exec call");
|
log.info("Making SOMFY http exec call");
|
||||||
HttpResponse response = httpClient.execute(httpPost);
|
HttpResponse response = httpClient.execute(httpPost);
|
||||||
|
|
||||||
//try {
|
log.info(response.getStatusLine().toString());
|
||||||
System.out.println(response.getStatusLine());
|
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
EntityUtils.consume(entity);
|
EntityUtils.consume(entity);
|
||||||
//} finally {
|
|
||||||
//response.close();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user