diff --git a/src/main/java/com/bigboxer23/eco_net/EcoNetAPI.java b/src/main/java/com/bigboxer23/eco_net/EcoNetAPI.java index 2b91a32..a7ffe32 100644 --- a/src/main/java/com/bigboxer23/eco_net/EcoNetAPI.java +++ b/src/main/java/com/bigboxer23/eco_net/EcoNetAPI.java @@ -200,9 +200,15 @@ 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); } /** @@ -210,7 +216,7 @@ public void setMode(String deviceId, String serialNumber, int mode) { * * @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); diff --git a/src/main/java/com/bigboxer23/eco_net/data/Modes.java b/src/main/java/com/bigboxer23/eco_net/data/Modes.java index ee76125..b8caaf7 100644 --- a/src/main/java/com/bigboxer23/eco_net/data/Modes.java +++ b/src/main/java/com/bigboxer23/eco_net/data/Modes.java @@ -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; } diff --git a/src/test/java/com/bigboxer23/eco_net/EcoNetApiTest.java b/src/test/java/com/bigboxer23/eco_net/EcoNetApiTest.java index bbc2a99..7590f99 100644 --- a/src/test/java/com/bigboxer23/eco_net/EcoNetApiTest.java +++ b/src/test/java/com/bigboxer23/eco_net/EcoNetApiTest.java @@ -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; @@ -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);