Continuation of nest implementation.

This commit is contained in:
Admin
2016-01-11 16:45:02 -06:00
parent d3cc961dfb
commit c28f07d628
15 changed files with 260 additions and 28 deletions

View File

@@ -17,6 +17,7 @@ public class BridgeSettings {
private boolean devmode;
private String nestuser;
private String nestpwd;
private boolean nestconfigured;
public String getUpnpConfigAddress() {
return upnpconfigaddress;
@@ -102,6 +103,12 @@ public class BridgeSettings {
public void setNestpwd(String nestpwd) {
this.nestpwd = nestpwd;
}
public boolean isNestConfigured() {
return nestconfigured;
}
public void setNestConfigured(boolean isNestConfigured) {
this.nestconfigured = isNestConfigured;
}
public Boolean isValidVera() {
if(this.veraaddress.contains(Configuration.DEFAULT_VERA_ADDRESS))
return false;

View File

@@ -225,24 +225,14 @@ public class DeviceResource {
return myHarmonyHome.getDevices();
}, new JsonTransformer());
get (API_CONTEXT + "/nest/homes", "application/json", (request, response) -> {
log.debug("Get nest homes");
get (API_CONTEXT + "/nest/items", "application/json", (request, response) -> {
log.debug("Get nest items");
if(nestHome == null) {
response.status(HttpStatus.SC_NOT_FOUND);
return null;
}
response.status(HttpStatus.SC_OK);
return nestHome.getHomeNames();
}, new JsonTransformer());
get (API_CONTEXT + "/nest/thermostats", "application/json", (request, response) -> {
log.debug("Get nest thermostats");
if(nestHome == null) {
response.status(HttpStatus.SC_NOT_FOUND);
return null;
}
response.status(HttpStatus.SC_OK);
return nestHome.getThermostatNames();
return nestHome.getItems();
}, new JsonTransformer());
}
}

View File

@@ -345,7 +345,7 @@ public class HueMulator {
else
myHarmony.pressButton(aDeviceButton);
}
else if(device.getDeviceType().toLowerCase().contains("home") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestHome")))
else if(device.getDeviceType().toLowerCase().contains("home") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("nestHomeAway")))
{
log.debug("executing set away for nest home: " + url);
HomeAway homeAway = new Gson().fromJson(url, HomeAway.class);

View File

@@ -53,6 +53,7 @@ public class UpnpSettingsResource {
this.theSettings.setUpnpResponsePort(theBridgeSettings.getUpnpResponsePort());
this.theSettings.setUpnpStrict(theBridgeSettings.isUpnpStrict());
this.theSettings.setVeraAddress(theBridgeSettings.getVeraAddress());
this.theSettings.setNestConfigured(theBridgeSettings.isValidNest());
}
public void setupServer() {

View File

@@ -2,26 +2,36 @@ package com.bwssystems.NestBridge;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.nest.controller.Home;
import com.bwssystems.nest.controller.Nest;
import com.bwssystems.nest.controller.NestSession;
import com.bwssystems.nest.controller.Thermostat;
import com.bwssystems.nest.protocol.error.LoginException;
import com.bwssystems.nest.protocol.status.WhereDetail;
import com.bwssystems.nest.protocol.status.WhereItem;
public class NestHome {
private static final Logger log = LoggerFactory.getLogger(NestHome.class);
private NestSession theSession;
private Nest theNest;
private ArrayList<NestItem> nestItems;
public NestHome(BridgeSettings bridgeSettings) {
theSession = null;
theNest = null;
nestItems = null;
if(bridgeSettings.isValidNest())
if(!bridgeSettings.isValidNest()) {
log.info("not a valid nest");
return;
}
try {
theSession = new NestSession(bridgeSettings.getNestuser(), bridgeSettings.getNestpwd());
@@ -32,18 +42,58 @@ public class NestHome {
}
}
public List<String> getHomeNames() {
public List<NestItem> getItems() {
if(theNest == null)
return null;
return new ArrayList<String>(theNest.getHomeNames()); /* list of home structures i.e. MyHouse */
if(nestItems == null) {
nestItems = new ArrayList<NestItem>();
Set<String> homeNames = theNest.getHomeNames();
Home aHome = null;
NestItem anItem = null;
for(String name : homeNames) {
aHome = theNest.getHome(name);
anItem = new NestItem();
anItem.setId(name);
anItem.setName(aHome.getDetail().getName());
anItem.setType("Home");
anItem.setLocation(aHome.getDetail().getLocation());
nestItems.add(anItem);
}
Thermostat thermo = null;
Set<String> thermoNames = theNest.getThermostatNames();
for(String name : thermoNames) {
thermo = theNest.getThermostat(name);
anItem = new NestItem();
anItem.setId(name);
anItem.setType("Thermostat");
String where = null;
String homeName= null;
Boolean found = false;
for(String aHomeName : homeNames) {
WhereDetail aDetail = theNest.getWhere(aHomeName);
ListIterator<WhereItem> anIterator = aDetail.getWheres().listIterator();
while(anIterator.hasNext()) {
WhereItem aWhereItem = (WhereItem) anIterator.next();
if(aWhereItem.getWhereId().equals(thermo.getDeviceDetail().getWhereId())) {
where = aWhereItem.getName();
homeName = theNest.getHome(aHomeName).getDetail().getName();
found = true;
break;
}
}
if(found)
break;
}
anItem.setName(where + "(" + name.substring(name.length() - 4) + ")");
anItem.setLocation(where + " - " + homeName);
nestItems.add(anItem);
}
}
return nestItems;
}
public List<String> getThermostatNames() {
if(theNest == null)
return null;
return new ArrayList<String>(theNest.getThermostatNames()); /* list of thermostats in all structure */
}
public Nest getTheNest() {
return theNest;
}