Skip to content

Commit 53eea84

Browse files
committed
Added more logging for nest communication.
1 parent bfdd1e5 commit 53eea84

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

Diff for: pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.bwssystems</groupId>
44
<artifactId>nest-controller</artifactId>
5-
<version>1.0.4</version>
5+
<version>1.0.5</version>
66
<packaging>jar</packaging>
77

88
<name>Nest Controller</name>

Diff for: src/main/java/com/bwssystems/nest/controller/Home.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
import org.apache.http.client.methods.HttpPost;
66
import org.apache.http.entity.StringEntity;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
79

810
import com.bwssystems.nest.protocol.status.StructureDetail;
911

1012
public class Home {
13+
private Logger log = LoggerFactory.getLogger(Nest.class);
1114
private NestSession theSession;
1215
private String theName;
1316
private StructureDetail theDetail;
@@ -24,11 +27,14 @@ public void reinitialize(StructureDetail aDetail) {
2427
}
2528

2629
public void setAway(Boolean isAway) {
27-
HttpPost postRequest = new HttpPost(theSession.getTransport_url() + "/v2/put/structure." + theName);
30+
String theUrl = theSession.getTransport_url() + "/v2/put/structure." + theName;
31+
HttpPost postRequest = new HttpPost(theUrl);
2832
StringEntity requestBody = new StringEntity("{\"away_timestamp\":" + Long.toString(new Date().getTime()) + ",\"away\":" + isAway.toString() + ",\"away_setter\":0}", NestSession.parsedContentType);
33+
log.debug("setAway for home: " + theUrl + " with body: " + requestBody);
2934
postRequest.setEntity(requestBody);
3035

31-
theSession.execute(postRequest);
36+
String theResponse = theSession.execute(postRequest);
37+
log.debug("setAway post request response: " + theResponse);
3238
}
3339

3440
public StructureDetail getDetail() {

Diff for: src/main/java/com/bwssystems/nest/controller/Nest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ public Nest(NestSession aSession) {
4646
}
4747

4848
private void _getStatus() {
49-
log.debug("getting status...");
50-
HttpGet newRequest = new HttpGet(theSession.getTransport_url() + "/v2/mobile/user." + theSession.getUserid());
49+
String theUrl = theSession.getTransport_url() + "/v2/mobile/user." + theSession.getUserid();
50+
log.debug("getting status: " + theUrl);
51+
HttpGet newRequest = new HttpGet(theUrl);
5152
String response = theSession.execute(newRequest);
53+
log.debug("status response: " + response);
5254
theStatus = gson.fromJson(response, NestStatus.class);
5355
for(String key : theStatus.getDevice().getDevices().keySet()) {
5456
if(theThermostats.get(key) == null)

Diff for: src/main/java/com/bwssystems/nest/controller/NestSession.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void _login() throws LoginException {
7777
StringEntity requestBody = new StringEntity("{\"email\":\"" + theUsername + "\",\"password\":\"" + thePassword + "\"}", parsedContentType);
7878
postRequest.setEntity(requestBody);
7979
String authResponse = _execute(postRequest);
80-
log.debug("The Response: " + authResponse);
80+
log.debug("_login Response: " + authResponse);
8181
theAuth = new Gson().fromJson(authResponse, SessionAuthorization.class);
8282
if(theAuth.getAccess_token() == null && theAuth.getUser() == null) {
8383
NestError anError = new Gson().fromJson(authResponse, NestError.class);
@@ -138,7 +138,7 @@ private String _execute(HttpRequestBase aRequest) {
138138
else {
139139
log.warn("Cannot execute http request, failed 3 times....");
140140
retry = 4;
141-
theBody = null;
141+
theBody = "Cannot execute http request, failed 3 times....";
142142
}
143143
}
144144
return theBody;

Diff for: src/main/java/com/bwssystems/nest/controller/Thermostat.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public void reinitialize(DeviceDetail aDevice, SharedDetail aShared) {
3030

3131
public void setTargetTemperature(Float theTemp) {
3232
if(theTemp < 33.0 & theTemp > 9.0) {
33-
HttpPost postRequest = new HttpPost(theSession.getTransport_url() + "/v2/put/shared." + deviceName);
33+
String theUrl = theSession.getTransport_url() + "/v2/put/shared." + deviceName;
34+
HttpPost postRequest = new HttpPost(theUrl);
3435
String target = null;
3536
if(deviceDetail.getCurrentScheduleMode().toLowerCase() == "range") {
3637
if(theTemp < sharedDetail.getTargetTemperature())
@@ -41,33 +42,41 @@ public void setTargetTemperature(Float theTemp) {
4142
else
4243
target = "target_temperature";
4344
StringEntity requestBody = new StringEntity("{\"target_change_pending\":true,\"" + target + "\":" + String.format("%3.1f", theTemp)+ "}", NestSession.parsedContentType);
45+
log.debug("setTargetTemperature for thermostat: " + theUrl + " with body: " + requestBody);
4446
postRequest.setEntity(requestBody);
45-
theSession.execute(postRequest);
47+
String theResponse = theSession.execute(postRequest);
48+
log.debug("setTargetTemperature response: " + theResponse);
4649
}
4750
else
48-
log.warn("temperature outside of Nest paramaters of 10C to 33C derees, not setting with this paramter: " + theTemp.toString());
51+
log.warn("setTargetTemperature outside of Nest paramaters of 10C to 33C derees, not setting with this paramter: " + theTemp.toString());
4952
}
5053

5154
public void setTargetType(String theType) {
5255
if(theType.equals("cool") || theType.equals("heat") || theType.equals("range") || theType.equals("off")) {
53-
HttpPost postRequest = new HttpPost(theSession.getTransport_url() + "/v2/put/shared." + deviceName);
56+
String theUrl = theSession.getTransport_url() + "/v2/put/shared." + deviceName;
57+
HttpPost postRequest = new HttpPost(theUrl);
5458
StringEntity requestBody = new StringEntity("{\"target_temperature_type\":\"" + theType + "\"}", NestSession.parsedContentType);
59+
log.debug("setTargetType for thermostat: " + theUrl + " with body: " + requestBody);
5560
postRequest.setEntity(requestBody);
56-
theSession.execute(postRequest);
61+
String theResponse = theSession.execute(postRequest);
62+
log.debug("setTargetType response: " + theResponse);
5763
}
5864
else
59-
log.warn("target type of Nest thermostat not one of the following: hest, cool, range or off, not setting with this paramter: " + theType);
65+
log.warn("setTargetType of Nest thermostat not one of the following: hest, cool, range or off, not setting with this paramter: " + theType);
6066
}
6167

6268
public void setFanMode(String theMode) {
6369
if(theMode.equals("on") || theMode.equals("auto")) {
64-
HttpPost postRequest = new HttpPost(theSession.getTransport_url() + "/v2/put/device." + deviceName);
70+
String theUrl = theSession.getTransport_url() + "/v2/put/device." + deviceName;
71+
HttpPost postRequest = new HttpPost(theUrl);
6572
StringEntity requestBody = new StringEntity("{\"fan_mode\":\"" + theMode + "\"}", NestSession.parsedContentType);
73+
log.debug("setFanMode for thermostat: " + theUrl + " with body: " + requestBody);
6674
postRequest.setEntity(requestBody);
67-
theSession.execute(postRequest);
75+
String theResponse = theSession.execute(postRequest);
76+
log.debug("setFanMode response: " + theResponse);
6877
}
6978
else
70-
log.warn("fan mode of Nest thermostat not one of the following: auto or off, not setting with this paramter: " + theMode);
79+
log.warn("setFanMode of Nest thermostat not one of the following: auto or off, not setting with this paramter: " + theMode);
7180
}
7281

7382
public DeviceDetail getDeviceDetail() {

0 commit comments

Comments
 (0)