Skip to content

Commit

Permalink
feat: add ability to change modes on the heater (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboxer23 authored Oct 14, 2024
1 parent bd3e26f commit 802f497
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/bigboxer23/eco_net/EcoNetAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,23 @@ public void subscribeToEvents(IEventSubscriber subscriber) {
subscribers.add(subscriber);
}

/**
* Sets the devices mode
*
* @param deviceId device id (name)
* @param serialNumber serial number of device
* @param mode See {@link Modes} for possible mode values
*/
public void setMode(String deviceId, String serialNumber, int mode) {
// TODO:

sendCommand(deviceId, serialNumber, "@MODE", mode);
}

/**
* Set the heater's temperature setpoint
*
* @param deviceId device id (name)
* @param serialNumber serial number of device
* @param setpoint setpoint to heat to
* @param setpoint setpoint to heat to in deg fahrenheit
*/
public void setTemperatureSetPoint(String deviceId, String serialNumber, int setpoint) {
sendCommand(deviceId, serialNumber, "@SETPOINT", setpoint);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/bigboxer23/eco_net/data/Modes.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
/** */
@Data
public class Modes {
public static final int HEAT_PUMP_MODE = 0;
public static final int VACATION_MODE = 1;

private Constraints constraints;

@Json(name = "status")
private String activeMode;

@Json(name = "value")
private int activeValue;
}
33 changes: 29 additions & 4 deletions src/test/java/com/bigboxer23/eco_net/EcoNetApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import static org.junit.jupiter.api.Assertions.*;

import com.bigboxer23.eco_net.data.EnergyResults;
import com.bigboxer23.eco_net.data.Equipment;
import com.bigboxer23.eco_net.data.Location;
import com.bigboxer23.eco_net.data.UserData;
import com.bigboxer23.eco_net.data.*;
import com.bigboxer23.utils.properties.PropertyUtils;
import java.util.Optional;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -92,6 +89,34 @@ public void fetchEnergyUsage() {
});
}

@Test
public void setMode() {
EcoNetAPI api = EcoNetAPI.getInstance(email, password);
api.fetchUserData().ifPresent(userData -> {
Location location = userData.getResults().getLocations().get(0);
Equipment equipment = location.getEquipments().get(0);
Modes currentMode = equipment.getModes();
api.setMode(equipment.getDeviceName(), equipment.getSerialNumber(), Modes.VACATION_MODE);
try {
Thread.sleep(5000);
} catch (InterruptedException theE) {
}
api.fetchUserData().ifPresent(updatedUserData -> {
assertEquals(
Modes.VACATION_MODE,
updatedUserData
.getResults()
.getLocations()
.get(0)
.getEquipments()
.get(0)
.getModes()
.getActiveValue());
});
api.setMode(equipment.getDeviceName(), equipment.getSerialNumber(), currentMode.getActiveValue());
});
}

@Test
public void setTemperatureSetPoint() {
EcoNetAPI api = EcoNetAPI.getInstance(email, password);
Expand Down

0 comments on commit 802f497

Please sign in to comment.