Skip to content

Commit 1544779

Browse files
committed
refactor battery status to an optional characteristic
rather than have everyone implement an interface directly for every concrete accessory also refactor in an AbstractSensor[Service] base class/interface so taht all the different sensors don't have to repeat their optional characteristics
1 parent 939c344 commit 1544779

24 files changed

+63
-63
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.beowulfe.hap.accessories;
2+
3+
import com.beowulfe.hap.HomekitAccessory;
4+
import com.beowulfe.hap.accessories.characteristics.LowBatteryStatus;
5+
import java.util.Optional;
6+
7+
/**
8+
* A several characteristics that are shared among all Sensor type accesories
9+
*
10+
* @author Cody Cutrer initial contribution
11+
*/
12+
public interface AbstractSensor extends HomekitAccessory {
13+
/** returns the optional implementation of LowBatteryStatus */
14+
default Optional<LowBatteryStatus> getLowBatteryStatusCharacteristic() {
15+
Optional<LowBatteryStatus> result = Optional.empty();
16+
return result;
17+
}
18+
}

src/main/java/com/beowulfe/hap/accessories/BatteryAccessory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import java.util.concurrent.CompletableFuture;
55

66
/**
7-
* Do not use. Devices that have battery levels should implement LowBatteryStatusAccessory.
7+
* Do not use. Devices that have battery levels should implement Characteristic.LowBatteryStatus
8+
* instead.
89
*
910
* @author Gaston Dombiak
1011
*/

src/main/java/com/beowulfe/hap/accessories/CarbonMonoxideSensor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.beowulfe.hap.accessories;
22

3-
import com.beowulfe.hap.HomekitAccessory;
43
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
54
import com.beowulfe.hap.Service;
65
import com.beowulfe.hap.accessories.properties.CarbonMonoxideDetectedState;
@@ -13,11 +12,11 @@
1312
* A carbon monoxide sensor reports whether carbon monoxide has been detected or not.
1413
*
1514
* <p>Carbon monoxide sensors that run on batteries will need to implement this interface and also
16-
* implement {@link BatteryStatusAccessory}.
15+
* implement LowBatteryStatus.
1716
*
1817
* @author Gaston Dombiak
1918
*/
20-
public interface CarbonMonoxideSensor extends HomekitAccessory {
19+
public interface CarbonMonoxideSensor extends AbstractSensor {
2120

2221
/**
2322
* Retrieves the state of the sensor that indicates if carbon monoxide has been detected.

src/main/java/com/beowulfe/hap/accessories/ContactSensor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.beowulfe.hap.accessories;
22

3-
import com.beowulfe.hap.HomekitAccessory;
43
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
54
import com.beowulfe.hap.Service;
65
import com.beowulfe.hap.accessories.properties.ContactState;
@@ -14,11 +13,11 @@
1413
* window/door sensors. When contact is detected it means that the door/window is closed.
1514
*
1615
* <p>Contact sensors that run on batteries will need to implement this interface and also implement
17-
* {@link BatteryStatusAccessory}.
16+
* LowBatteryStatus.
1817
*
1918
* @author Gaston Dombiak
2019
*/
21-
public interface ContactSensor extends HomekitAccessory {
20+
public interface ContactSensor extends AbstractSensor {
2221

2322
/**
2423
* Retrieves the state of the contact. This is whether the contact is detected or not. Detected

src/main/java/com/beowulfe/hap/accessories/HumiditySensor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @author Andy Lintner
1313
*/
14-
public interface HumiditySensor extends HomekitAccessory {
14+
public interface HumiditySensor extends AbstractSensor {
1515

1616
/**
1717
* Retrieves the current relative humidity.

src/main/java/com/beowulfe/hap/accessories/LeakSensor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.beowulfe.hap.accessories;
22

3-
import com.beowulfe.hap.HomekitAccessory;
43
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
54
import com.beowulfe.hap.Service;
65
import com.beowulfe.hap.impl.services.LeakSensorService;
@@ -12,11 +11,11 @@
1211
* A leak sensor that reports whether a leak has been detected.
1312
*
1413
* <p>Leak sensors that run on batteries will need to implement this interface and also implement
15-
* {@link BatteryStatusAccessory}.
14+
* LowBatteryStatus.
1615
*
1716
* @author Tim Harper
1817
*/
19-
public interface LeakSensor extends HomekitAccessory {
18+
public interface LeakSensor extends AbstractSensor {
2019

2120
/**
2221
* Retrieves the state of the leak sensor. If true then leak has been detected.

src/main/java/com/beowulfe/hap/accessories/LightSensor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.beowulfe.hap.accessories;
22

3-
import com.beowulfe.hap.HomekitAccessory;
43
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
54
import com.beowulfe.hap.Service;
65
import com.beowulfe.hap.impl.services.LightSensorService;
@@ -13,7 +12,7 @@
1312
*
1413
* @author Gaston Dombiak
1514
*/
16-
public interface LightSensor extends HomekitAccessory {
15+
public interface LightSensor extends AbstractSensor {
1716

1817
/**
1918
* Retrieves the current ambient light level.

src/main/java/com/beowulfe/hap/accessories/LockMechanism.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
* A lock capable of exposing its binary locked state. For a lock that can be locked/unlocked, use
1414
* {@link LockableLockMechanism}.
1515
*
16-
* <p>Locks that run on batteries will need to implement this interface and also implement {@link
17-
* BatteryStatusAccessory}.
18-
*
1916
* @author Andy Lintner
2017
*/
2118
public interface LockMechanism extends HomekitAccessory {

src/main/java/com/beowulfe/hap/accessories/MotionSensor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.beowulfe.hap.accessories;
22

3-
import com.beowulfe.hap.HomekitAccessory;
43
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
54
import com.beowulfe.hap.Service;
65
import com.beowulfe.hap.impl.services.MotionSensorService;
@@ -11,12 +10,9 @@
1110
/**
1211
* A motion sensor that reports whether motion has been detected.
1312
*
14-
* <p>Motion sensors that run on batteries will need to implement this interface and also implement
15-
* {@link BatteryStatusAccessory}.
16-
*
1713
* @author Gaston Dombiak
1814
*/
19-
public interface MotionSensor extends HomekitAccessory {
15+
public interface MotionSensor extends AbstractSensor {
2016

2117
/**
2218
* Retrieves the state of the motion sensor. If true then motion has been detected.

src/main/java/com/beowulfe/hap/accessories/OccupancySensor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.beowulfe.hap.accessories;
22

3-
import com.beowulfe.hap.HomekitAccessory;
43
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
54
import com.beowulfe.hap.Service;
65
import com.beowulfe.hap.impl.services.OccupancySensorService;
@@ -11,12 +10,9 @@
1110
/**
1211
* An occupancy sensor that reports whether occupancy has been detected.
1312
*
14-
* <p>Occupancy sensors that run on batteries will need to implement this interface and also
15-
* implement {@link BatteryStatusAccessory}.
16-
*
1713
* @author Tim Harper
1814
*/
19-
public interface OccupancySensor extends HomekitAccessory {
15+
public interface OccupancySensor extends AbstractSensor {
2016
/**
2117
* Retrieves the state of the occupancy sensor. If true then occupancy has been detected.
2218
*

0 commit comments

Comments
 (0)