Skip to content

Commit a937f86

Browse files
authored
feat: adding constants for commands (#31)
feat: adding constants for device types ops: bumping lib version
1 parent 7b6b9f9 commit a937f86

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.bigboxer23</groupId>
66
<artifactId>switchbotapi-java</artifactId>
7-
<version>1.1.0</version>
7+
<version>1.1.1</version>
88

99
<name>switchbotapi-java</name>
1010
<url>https://github.com/bigboxer23/switchbotapi-java</url>
@@ -37,7 +37,7 @@
3737
<dependency>
3838
<groupId>com.bigboxer23</groupId>
3939
<artifactId>utils</artifactId>
40-
<version>2.0.15</version>
40+
<version>2.0.19</version>
4141
</dependency>
4242
<dependency>
4343
<groupId>org.projectlombok</groupId>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.bigboxer23.switch_bot;
2+
3+
import com.bigboxer23.switch_bot.data.DeviceCommand;
4+
5+
/**
6+
*
7+
*/
8+
public interface IDeviceCommands
9+
{
10+
String TURN_OFF = "turnOff";
11+
12+
String TURN_ON = "turnOn";
13+
14+
DeviceCommand CLOSE_CURTAIN = new DeviceCommand(TURN_OFF, "default");
15+
16+
DeviceCommand OPEN_CURTAIN = new DeviceCommand(TURN_ON, "default");
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.bigboxer23.switch_bot;
2+
3+
/**
4+
*
5+
*/
6+
public interface IDeviceTypes
7+
{
8+
String CURTAIN = "Curtain";
9+
String HUB2 = "Hub 2";
10+
String METER = "Meter";
11+
12+
String WOIOSENSOR = "WoIOSensor";
13+
}

src/test/java/com/bigboxer23/switch_bot/SwitchBotApiTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.jupiter.api.Assertions.*;
44

55
import com.bigboxer23.switch_bot.data.Device;
6-
import com.bigboxer23.switch_bot.data.DeviceCommand;
76
import java.io.IOException;
87
import java.util.List;
98
import org.junit.jupiter.api.Test;
@@ -30,14 +29,15 @@ public void testDeviceStatus() throws IOException {
3029
assertNotNull(device.getDeviceId());
3130
Device status = instance.getDeviceApi().getDeviceStatus(device.getDeviceId());
3231
switch (status.getDeviceType()) {
33-
case "Hub 2", "Meter" -> {
34-
assertTrue(status.getTemperature() > 0);
35-
assertTrue(status.getHumidity() > 0);
36-
if ("Hub 2".equals(status.getDeviceType())) {
32+
case IDeviceTypes.HUB2, IDeviceTypes.METER, IDeviceTypes.WOIOSENSOR -> {
33+
assertTrue(status.getTemperature() > -1);
34+
assertTrue(status.getHumidity() > -1);
35+
assertTrue(status.getBattery() >= 0);
36+
if (IDeviceTypes.HUB2.equals(status.getDeviceType())) {
3737
assertTrue(status.getLightLevel() >= 0);
3838
}
3939
}
40-
case "Curtain" -> {
40+
case IDeviceTypes.CURTAIN -> {
4141
assertTrue(status.getSlidePosition() >= 0);
4242
assertTrue(status.getMoving() >= 0);
4343
assertTrue(status.getBattery() >= 0);
@@ -50,13 +50,13 @@ public void testDeviceStatus() throws IOException {
5050
public void testDeviceCommands() throws IOException {
5151
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret);
5252
Device curtain = instance.getDeviceApi().getDevices().stream()
53-
.filter(device -> "Curtain".equals(device.getDeviceType()))
53+
.filter(device -> IDeviceTypes.CURTAIN.equals(device.getDeviceType()))
5454
.filter(Device::isMaster)
5555
.findAny()
5656
.orElse(null);
5757
assertNotNull(curtain);
5858
assertNotNull(curtain.getDeviceId());
5959
instance.getDeviceApi()
60-
.sendDeviceControlCommands(curtain.getDeviceId(), new DeviceCommand("turnOff", "default"));
60+
.sendDeviceControlCommands(curtain.getDeviceId(), IDeviceCommands.CLOSE_CURTAIN);
6161
}
6262
}

0 commit comments

Comments
 (0)