Completing ZigbeeTest with doorlock test
[iot2.git] / benchmarks / other / DoorlockAndOutlet / DoorlockSensor.java
index a1d6d95..c069949 100644 (file)
@@ -26,18 +26,16 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor {
        private final int TIMEOUT_FOR_RESEND_MSEC = 900;
 
        private IoTZigbee zigConnection = null;
-
-       private int status = 0;
        private boolean didClose; // make sure that the clean up was done correctly
-       //private boolean detectStatus = false;
+       private boolean detectStatus = false;
 
-       //private int detectedValue = 0;
+       private int detectedValue = 0;
        private Date timestampOfLastDetecting = null;
 
        private AtomicBoolean didAlreadyClose = new AtomicBoolean(true);
        private AtomicBoolean didAlreadyInit = new AtomicBoolean(false);
        private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
-       //private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
+       private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
        private AtomicBoolean didBind = new AtomicBoolean(false);
        private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei
        static Semaphore gettingLatestDataMutex = new Semaphore(1);
@@ -156,12 +154,13 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor {
        }
 
        // made by Jiawei
-    public int getStatus() {
+    //public int getStatus() {
+       public int getValue() {
                int tmp = 0;
 
                try {
                        gettingLatestDataMutex.acquire();
-                       tmp = status;
+                       tmp = detectedValue;
 
                } catch (Exception e) {
                        e.printStackTrace();
@@ -171,6 +170,16 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor {
                return tmp;
        }
 
+       public boolean isActiveValue() {
+
+               int tmp = getValue();
+               if (tmp == 1)
+                       detectStatus = true;    // Door is locked
+               else
+                       detectStatus = false;   // Door is not locked/not fully locked
+               return detectStatus;
+       }
+
        public void close() {
 
                if (didAlreadyClose.compareAndSet(false, true) == false) {
@@ -248,7 +257,7 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor {
 
                                        try {
                                                gettingLatestDataMutex.acquire();
-                                               status = value;
+                                               detectedValue = value;
                                                timestampOfLastDetecting = new Date();
                                        } catch (Exception e) {
                                                e.printStackTrace();
@@ -257,7 +266,7 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor {
 
                                        try {
                                                for (SmartthingsSensorCallback cb : callbackList) {
-                                                       cb.newReadingAvailable(this);
+                                                       cb.newReadingAvailable(this.getValue(), this.isActiveValue());
                                                }
                                        } catch (Exception e) {
                                                e.printStackTrace();