Skip to content

Commit

Permalink
feat: add ability to get the current tank's compressor status and fil…
Browse files Browse the repository at this point in the history
…l level (#31)
  • Loading branch information
bigboxer23 authored Jan 7, 2025
1 parent d720333 commit 047a359
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.bigboxer23</groupId>
<artifactId>econetapi-java</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>

<name>econet-java</name>
<url>https://github.com/bigboxer23/econetapi-java</url>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/bigboxer23/eco_net/EcoNetAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class EcoNetAPI implements IEcoNetConstants {

private static MqttAsyncClient mqttClient;

private List<IEventSubscriber> subscribers = new ArrayList<>();
private final List<IEventSubscriber> subscribers = new ArrayList<>();
private final String userToken;
private final String accountId;

Expand Down Expand Up @@ -74,10 +74,10 @@ public Optional<UserData> fetchUserData() {
baseUrl + "/code/" + CLEAR_BLADE_SYSTEM_KEY + "/getUserDataForApp",
OkHttpRequestBodyUtils.createBodyFromString(new JsonMapBuilder()
.put("location_only", false)
.put("type", "com.econet.econetconsumerandroid")
.put("version", "6.0.0-375-01b4870e")
.put("type", TYPE)
.put("version", VERSION)
.toJson()),
getHeaders(Collections.singletonMap("ClearBlade-UserToken", userToken)))) {
getHeaders(Collections.singletonMap(CLEAR_BLADE_USER_TOKEN, userToken)))) {
Optional<UserData> body = OkHttpUtil.getBody(response, UserData.class);
if (body.isPresent() && !body.get().isSuccess()) {
logger.error("fetchUserData: ");
Expand All @@ -96,7 +96,7 @@ public Optional<EnergyResults> fetchEnergyUsage(
baseUrl + "/code/" + CLEAR_BLADE_SYSTEM_KEY + "/dynamicAction",
OkHttpRequestBodyUtils.createBodyFromJsonObject(
new FetchUsageCommand(deviceId, serialNumber, day, month, year), FetchUsageCommand.class),
getHeaders(Collections.singletonMap("ClearBlade-UserToken", userToken)))) {
getHeaders(Collections.singletonMap(CLEAR_BLADE_USER_TOKEN, userToken)))) {
Optional<EnergyResults> body = OkHttpUtil.getBody(response, EnergyResults.class);
if (body.isPresent() && !body.get().isSuccess()) {
logger.error("fetchEnergyUsage: " + body.get().getLogs());
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/bigboxer23/eco_net/IEcoNetConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public interface IEcoNetConstants {
String baseUrl = "https://rheem.clearblade.com/api/v/1/";
String CLEAR_BLADE_SYSTEM_KEY = "e2e699cb0bb0bbb88fc8858cb5a401";
String CLEAR_BLADE_SYSTEM_SECRET = "E2E699CB0BE6C6FADDB1B0BC9A20";
String TYPE = "com.econet.econetconsumerandroid";
String VERSION = "6.0.0-375-01b4870e";
String CLEAR_BLADE_USER_TOKEN = "ClearBlade-UserToken";
int TIMEOUT = 60000;
int QOS = 2;
}
10 changes: 10 additions & 0 deletions src/main/java/com/bigboxer23/eco_net/data/Equipment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ public class Equipment {

@Json(name = "@MODE")
private Modes modes;

@Json(name = "@RUNNING")
private String compressorStatus;

@Json(name = "@HOTWATER")
private String tankStatusUrl;

public float getTankStatus() {
return TankStatus.getTankStatus(tankStatusUrl);
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/bigboxer23/eco_net/data/TankStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.bigboxer23.eco_net.data;

import org.apache.commons.lang3.StringUtils;

/** */
public class TankStatus {
private static final String EMPTY = "ic_tank_zero_percent_v2.png.png";
private static final String ONE_THIRD = "ic_tank_ten_percent_v2.png";
private static final String TWO_THIRD = "ic_tank_fourty_percent_v2.png";
private static final String FULL = "ic_tank_hundread_percent_v2.png";

public static float getTankStatus(String tankStatusUrl) {
return switch (StringUtils.defaultIfEmpty(tankStatusUrl, "")) {
case EMPTY -> 0.0f;
case ONE_THIRD -> .33f;
case TWO_THIRD -> .66f;
case FULL -> 1f;
default -> -1f;
};
}
}
15 changes: 15 additions & 0 deletions src/test/java/com/bigboxer23/eco_net/EcoNetApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ public void getUserData() {
.get(0)
.getSetpoint()
.getValue());
assertTrue(result.get()
.getResults()
.getLocations()
.get(0)
.getEquipments()
.get(0)
.getTankStatus()
>= 0);
assertNotNull(result.get()
.getResults()
.getLocations()
.get(0)
.getEquipments()
.get(0)
.getCompressorStatus());
}

@Test
Expand Down

0 comments on commit 047a359

Please sign in to comment.