Skip to content

Commit

Permalink
feat: add ability to set temperature setpoint on device
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboxer23 committed Oct 14, 2024
1 parent d4ddd0d commit fa43fe9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/main/java/com/bigboxer23/eco_net/EcoNetAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,37 @@ public void subscribeToEvents(IEventSubscriber subscriber) {
initMQTTConnection(); // Init if necessary
subscribers.add(subscriber);
}

public void setMode(String deviceId, String serialNumber, int mode) {
// TODO:

}

/**
* Set the heater's temperature setpoint
*
* @param deviceId device id (name)
* @param serialNumber serial number of device
* @param setpoint setpoint to heat to
*/
public void setTemperatureSetPoint(String deviceId, String serialNumber, int setpoint) {
sendCommand(deviceId, serialNumber, "@SETPOINT", setpoint);
}

private void sendCommand(String deviceId, String serialNumber, String command, int value) {
initMQTTConnection();
try {
MqttMessage message = new MqttMessage();
message.setPayload(new JsonMapBuilder()
.put("transactionId", "ANDROID_" + System.currentTimeMillis())
.put("device_name", deviceId)
.put("serial_number", serialNumber)
.put(command, value)
.toJson()
.getBytes());
mqttClient.publish("user/" + accountId + "/device/desired", message);
} catch (MqttException e) {
logger.error("sendCommand " + command, e);
}
}
}
32 changes: 31 additions & 1 deletion src/test/java/com/bigboxer23/eco_net/EcoNetApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,39 @@ public void fetchEnergyUsage() {
api.fetchUserData().ifPresent(userData -> {
Location location = userData.getResults().getLocations().get(0);
Equipment equipment = location.getEquipments().get(0);
Optional<EnergyResults> data = api.fetchEnergyUsage(equipment.getDeviceName(), equipment.getSerialNumber(), 8, 10, 2024);
Optional<EnergyResults> data =
api.fetchEnergyUsage(equipment.getDeviceName(), equipment.getSerialNumber(), 8, 10, 2024);
assertTrue(data.isPresent());
assertNotNull(data.get().getResults());
});
}

@Test
public void setTemperatureSetPoint() {
EcoNetAPI api = EcoNetAPI.getInstance(email, password);
api.fetchUserData().ifPresent(userData -> {
Location location = userData.getResults().getLocations().get(0);
Equipment equipment = location.getEquipments().get(0);
int currentSetpoint = equipment.getSetpoint().getValue();
assertNotEquals(132, currentSetpoint);
api.setTemperatureSetPoint(equipment.getDeviceName(), equipment.getSerialNumber(), 132);
try {
Thread.sleep(5000);
} catch (InterruptedException theE) {
}
api.fetchUserData().ifPresent(updatedUserData -> {
assertEquals(
132,
updatedUserData
.getResults()
.getLocations()
.get(0)
.getEquipments()
.get(0)
.getSetpoint()
.getValue());
});
api.setTemperatureSetPoint(equipment.getDeviceName(), equipment.getSerialNumber(), currentSetpoint);
});
}
}

0 comments on commit fa43fe9

Please sign in to comment.