1- package com .bigboxer23 .switch_bot ;
1+ package com .bigboxer23 .switch_bot . integration ;
22
33import static org .junit .jupiter .api .Assertions .*;
44
5+ import com .bigboxer23 .switch_bot .IDeviceCommands ;
6+ import com .bigboxer23 .switch_bot .IDeviceTypes ;
7+ import com .bigboxer23 .switch_bot .SwitchBotApi ;
58import com .bigboxer23 .switch_bot .data .Device ;
69import com .bigboxer23 .utils .command .Command ;
710import com .bigboxer23 .utils .properties .PropertyUtils ;
811import java .io .IOException ;
912import java .util .List ;
13+ import org .junit .jupiter .api .Tag ;
1014import org .junit .jupiter .api .Test ;
1115
12- /** Need to define environment variables for SwitchBotToken/SwitchBotSecret to run tests */
13- public class SwitchBotApiTest {
16+ @ Tag ( "integration" )
17+ public class SwitchBotApiIntegrationTest {
1418 private static final String token = PropertyUtils .getProperty ("switchbot_token" );
15-
1619 private static final String secret = PropertyUtils .getProperty ("switchbot_secret" );
17-
1820 private static final SwitchBotApi instance = SwitchBotApi .getInstance (token , secret );
1921
2022 @ Test
2123 public void testGetDevices () throws IOException {
2224 List <Device > devices = instance .getDeviceApi ().getDevices ();
23- assertFalse (devices .isEmpty ());
25+ assertFalse (devices .isEmpty (), "Device list should not be empty" );
2426 assertNotNull (devices .get (0 ).getDeviceId ());
2527 }
2628
@@ -37,9 +39,8 @@ public void getDeviceNameFromId() throws IOException {
3739 public void testDeviceStatus () throws IOException {
3840 try {
3941 instance .getDeviceApi ().getDeviceStatus ("123" );
40- fail ();
41- } catch (IOException e ) {
42-
42+ fail ("Expected IOException for invalid device ID" );
43+ } catch (IOException ignored ) {
4344 }
4445 for (Device device : instance .getDeviceApi ().getDevices ()) {
4546 assertNotNull (device .getDeviceId ());
@@ -55,17 +56,16 @@ public void testDeviceStatus() throws IOException {
5556 }
5657 case IDeviceTypes .CURTAIN -> {
5758 assertTrue (status .getSlidePosition () >= 0 );
58- assertTrue (status .isMoving ());
5959 assertTrue (status .getBattery () >= 0 );
6060 }
6161 case IDeviceTypes .PLUG_MINI -> {
6262 assertTrue ("on" .equals (status .getPower ()) || "off" .equals (status .getPower ()));
63- assertTrue (status .getVoltage () > 0 );
63+ assertTrue (status .getVoltage () > - 1 );
6464 assertTrue (status .getWatts () > -1 );
6565 assertTrue (status .getElectricityOfDay () >= 0 );
6666 assertTrue (status .getElectricCurrent () > -1 );
6767 }
68- case IDeviceTypes .WATER_DETECTOR -> assertTrue (status .isWet ());
68+ case IDeviceTypes .WATER_DETECTOR -> assertTrue (status .isWet () || status . isDry () );
6969 case IDeviceTypes .METER_PRO_CO2 -> assertTrue (status .getCo2 () > 0 );
7070 }
7171 }
@@ -80,25 +80,14 @@ public void testCurtainDeviceCommands() throws IOException, InterruptedException
8080 .orElse (null );
8181 assertNotNull (curtain );
8282 assertNotNull (curtain .getDeviceId ());
83- System .out .println ("slide position "
84- + instance .getDeviceApi ().getDeviceStatus (curtain .getDeviceId ()).getSlidePosition ());
8583
8684 instance .getDeviceApi ().sendDeviceControlCommands (curtain .getDeviceId (), IDeviceCommands .CURTAIN_CLOSE );
87- pollForStatus (() -> {
88- int slidePosition = instance .getDeviceApi ()
89- .getDeviceStatus (curtain .getDeviceId ())
90- .getSlidePosition ();
91- System .out .println ("slide position " + slidePosition );
92- return slidePosition >= 90 ;
93- });
85+ pollForStatus (() ->
86+ instance .getDeviceApi ().getDeviceStatus (curtain .getDeviceId ()).getSlidePosition () >= 90 );
87+
9488 instance .getDeviceApi ().sendDeviceControlCommands (curtain .getDeviceId (), IDeviceCommands .CURTAIN_OPEN );
95- pollForStatus (() -> {
96- int slidePosition = instance .getDeviceApi ()
97- .getDeviceStatus (curtain .getDeviceId ())
98- .getSlidePosition ();
99- System .out .println ("slide position " + slidePosition );
100- return slidePosition == 0 ;
101- });
89+ pollForStatus (() ->
90+ instance .getDeviceApi ().getDeviceStatus (curtain .getDeviceId ()).getSlidePosition () == 0 );
10291 }
10392
10493 @ Test
@@ -120,8 +109,7 @@ public void testPlugDeviceCommands() throws IOException, InterruptedException {
120109
121110 private void pollForStatus (Command <Boolean > command ) throws IOException , InterruptedException {
122111 boolean result = command .execute ();
123- for (int ai = 0 ; ai < 10 && !result ; ai ++) {
124- System .out .println ("sleeping " + ai );
112+ for (int i = 0 ; i < 10 && !result ; i ++) {
125113 Thread .sleep (2000 );
126114 result = command .execute ();
127115 }
0 commit comments