Skip to content

Commit f66b76d

Browse files
committed
Added window covering accessory type
1 parent 9cf9820 commit f66b76d

15 files changed

+607
-11
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.beowulfe.hap.accessories;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
6+
7+
/**
8+
* Extends WindowCovering with the ability to control horizontal tilt angles
9+
*
10+
* @author Andy Lintner
11+
*/
12+
public interface HorizontalTiltingWindowCovering extends WindowCovering {
13+
14+
/**
15+
* Retrieves the current horizontal tilt angle
16+
* @return a future that will contain the position as a value between -90 and 90
17+
*/
18+
CompletableFuture<Integer> getCurrentHorizontalTiltAngle();
19+
20+
/**
21+
* Retrieves the target horizontal tilt angle
22+
* @return a future that will contain the target position as a value between -90 and 90
23+
*/
24+
CompletableFuture<Integer> getTargetHorizontalTiltAngle();
25+
26+
/**
27+
* Sets the target position
28+
* @param angle the target angle to set, as a value between -90 and 90
29+
* @return a future that completes when the change is made
30+
* @throws Exception when the change cannot be made
31+
*/
32+
public CompletableFuture<Void> setTargetHorizontalTiltAngle(int angle) throws Exception;
33+
34+
/**
35+
* Subscribes to changes in the current horizontal tilt angle.
36+
* @param callback the function to call when the state changes.
37+
*/
38+
void subscribeCurrentHorizontalTiltAngle(HomekitCharacteristicChangeCallback callback);
39+
40+
/**
41+
* Subscribes to changes in the target horizontal tilt angle.
42+
* @param callback the function to call when the state changes.
43+
*/
44+
void subscribeTargetHorizontalTiltAngle(HomekitCharacteristicChangeCallback callback);
45+
46+
/**
47+
* Unsubscribes from changes in the current horizontal tilt angle
48+
*/
49+
void unsubscribeCurrentHorizontalTiltAngle();
50+
51+
/**
52+
* Unsubscribes from changes in the target horizontal tilt angle
53+
*/
54+
void unsubscribeTargetHorizontalTiltAngle();
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.beowulfe.hap.accessories;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
6+
7+
/**
8+
* Extends WindowCovering with the ability to control vertical tilt angles
9+
*
10+
* @author Andy Lintner
11+
*/
12+
public interface VerticalTiltingWindowCovering extends WindowCovering {
13+
14+
/**
15+
* Retrieves the current vertical tilt angle
16+
* @return a future that will contain the position as a value between -90 and 90
17+
*/
18+
CompletableFuture<Integer> getCurrentVerticalTiltAngle();
19+
20+
/**
21+
* Retrieves the target vertical tilt angle
22+
* @return a future that will contain the target position as a value between -90 and 90
23+
*/
24+
CompletableFuture<Integer> getTargetVerticalTiltAngle();
25+
26+
/**
27+
* Sets the target position
28+
* @param angle the target angle to set, as a value between -90 and 90
29+
* @return a future that completes when the change is made
30+
* @throws Exception when the change cannot be made
31+
*/
32+
public CompletableFuture<Void> setTargetVerticalTiltAngle(int angle) throws Exception;
33+
34+
/**
35+
* Subscribes to changes in the current vertical tilt angle.
36+
* @param callback the function to call when the state changes.
37+
*/
38+
void subscribeCurrentVerticalTiltAngle(HomekitCharacteristicChangeCallback callback);
39+
40+
/**
41+
* Subscribes to changes in the target vertical tilt angle.
42+
* @param callback the function to call when the state changes.
43+
*/
44+
void subscribeTargetVerticalTiltAngle(HomekitCharacteristicChangeCallback callback);
45+
46+
/**
47+
* Unsubscribes from changes in the current vertical tilt angle
48+
*/
49+
void unsubscribeCurrentVerticalTiltAngle();
50+
51+
/**
52+
* Unsubscribes from changes in the target vertical tilt angle
53+
*/
54+
void unsubscribeTargetVerticalTiltAngle();
55+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.beowulfe.hap.accessories;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.concurrent.CompletableFuture;
6+
7+
import com.beowulfe.hap.*;
8+
import com.beowulfe.hap.accessories.properties.WindowCoveringPositionState;
9+
import com.beowulfe.hap.impl.services.WindowCoveringService;
10+
11+
/**
12+
* A window covering, like blinds, which can be remotely controlled.
13+
*
14+
* @author Andy Lintner
15+
*/
16+
public interface WindowCovering extends HomekitAccessory {
17+
18+
/**
19+
* Retrieves the current position
20+
* @return a future that will contain the position as a value between 0 and 100
21+
*/
22+
CompletableFuture<Integer> getCurrentPosition();
23+
24+
/**
25+
* Retrieves the target position
26+
* @return a future that will contain the target position as a value between 0 and 100
27+
*/
28+
CompletableFuture<Integer> getTargetPosition();
29+
30+
/**
31+
* Retrieves the state of the position: increasing, decreasing, or stopped
32+
* @return a future that will contain the current state
33+
*/
34+
CompletableFuture<WindowCoveringPositionState> getPositionState();
35+
36+
/**
37+
* Retrieves an indication that the window covering is obstructed from moving
38+
* @return a future that will contain a boolean indicating whether an obstruction is present
39+
*/
40+
CompletableFuture<Boolean> getObstructionDetected();
41+
42+
@Override
43+
default public Collection<Service> getServices() {
44+
return Collections.singleton(new WindowCoveringService(this));
45+
}
46+
47+
/**
48+
* Sets the target position
49+
* @param position the target position to set, as a value between 1 and 100
50+
* @return a future that completes when the change is made
51+
* @throws Exception when the change cannot be made
52+
*/
53+
public CompletableFuture<Void> setTargetPosition(int position) throws Exception;
54+
55+
/**
56+
* Sets the hold position state
57+
* @param hold whether or not to hold the current position state
58+
* @return a future that completes when the change is made
59+
* @throws Exception when the change cannot be made
60+
*/
61+
public CompletableFuture<Void> setHoldPosition(boolean hold) throws Exception;
62+
63+
/**
64+
* Subscribes to changes in the current position.
65+
* @param callback the function to call when the state changes.
66+
*/
67+
void subscribeCurrentPosition(HomekitCharacteristicChangeCallback callback);
68+
69+
/**
70+
* Subscribes to changes in the target position.
71+
* @param callback the function to call when the state changes.
72+
*/
73+
void subscribeTargetPosition(HomekitCharacteristicChangeCallback callback);
74+
75+
/**
76+
* Subscribes to changes in the position state: increasing, decreasing, or stopped
77+
* @param callback the function to call when the state changes.
78+
*/
79+
void subscribePositionState(HomekitCharacteristicChangeCallback callback);
80+
81+
/**
82+
* Subscribes to changes in the obstruction detected state
83+
* @param callback the function to call when the state changes.
84+
*/
85+
void subscribeObstructionDetected(HomekitCharacteristicChangeCallback callback);
86+
87+
/**
88+
* Unsubscribes from changes in the current position.
89+
*/
90+
void unsubscribeCurrentPosition();
91+
92+
/**
93+
* Unsubscribes from changes in the target position.
94+
*/
95+
void unsubscribeTargetPosition();
96+
97+
/**
98+
* Unsubscribes from changes in the position state
99+
*/
100+
void unsubscribePositionState();
101+
102+
/**
103+
* Unsubscribes from changes in the obstruction detected state
104+
*/
105+
void unsubscribeObstructionDetected();
106+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.beowulfe.hap.accessories.properties;
2+
3+
import java.util.Arrays;
4+
import java.util.Map;
5+
import java.util.stream.Collectors;
6+
7+
import com.beowulfe.hap.accessories.WindowCovering;
8+
9+
/**
10+
* The position state used by a {@link WindowCovering}
11+
*
12+
* @author Andy Lintner
13+
*/
14+
public enum WindowCoveringPositionState {
15+
DECREASING(0),
16+
INCREASING(1),
17+
STOPPED(2)
18+
;
19+
20+
private final static Map<Integer, WindowCoveringPositionState> reverse;
21+
static {
22+
reverse = Arrays.stream(WindowCoveringPositionState.values()).collect(Collectors.toMap(t -> t.getCode(), t -> t));
23+
}
24+
25+
public static WindowCoveringPositionState fromCode(Integer code) {
26+
return reverse.get(code);
27+
}
28+
29+
private final int code;
30+
31+
private WindowCoveringPositionState(int code) {
32+
this.code = code;
33+
}
34+
35+
public int getCode() {
36+
return code;
37+
}
38+
}

src/main/java/com/beowulfe/hap/impl/characteristics/garage/ObstructionDetectedCharacteristic.java renamed to src/main/java/com/beowulfe/hap/impl/characteristics/common/ObstructionDetectedCharacteristic.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
package com.beowulfe.hap.impl.characteristics.garage;
1+
package com.beowulfe.hap.impl.characteristics.common;
22

33
import java.util.concurrent.CompletableFuture;
4+
import java.util.function.Consumer;
5+
import java.util.function.Supplier;
46

57
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
6-
import com.beowulfe.hap.accessories.GarageDoor;
78
import com.beowulfe.hap.characteristics.BooleanCharacteristic;
89
import com.beowulfe.hap.characteristics.EventableCharacteristic;
910

1011
public class ObstructionDetectedCharacteristic extends BooleanCharacteristic implements EventableCharacteristic {
1112

12-
private final GarageDoor door;
13+
private final Supplier<CompletableFuture<Boolean>> getter;
14+
private final Consumer<HomekitCharacteristicChangeCallback> subscriber;
15+
private final Runnable unsubscriber;
1316

14-
public ObstructionDetectedCharacteristic(GarageDoor door) {
15-
super("00000024-0000-1000-8000-0026BB765291", false, true, "An obstruction to the door has been detected");
16-
this.door = door;
17+
public ObstructionDetectedCharacteristic(Supplier<CompletableFuture<Boolean>> getter,
18+
Consumer<HomekitCharacteristicChangeCallback> subscriber, Runnable unsubscriber) {
19+
super("00000024-0000-1000-8000-0026BB765291", false, true, "An obstruction has been detected");
20+
this.getter = getter;
21+
this.subscriber = subscriber;
22+
this.unsubscriber = unsubscriber;
1723
}
1824

1925
@Override
@@ -23,17 +29,17 @@ protected void setValue(Boolean value) throws Exception {
2329

2430
@Override
2531
protected CompletableFuture<Boolean> getValue() {
26-
return door.getObstructionDetected();
32+
return getter.get();
2733
}
2834

2935
@Override
3036
public void subscribe(HomekitCharacteristicChangeCallback callback) {
31-
door.subscribeObstructionDetected(callback);
37+
subscriber.accept(callback);
3238
}
3339

3440
@Override
3541
public void unsubscribe() {
36-
door.unsubscribeObstructionDetected();
42+
unsubscriber.run();
3743
}
3844

3945

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.beowulfe.hap.impl.characteristics.windowcovering;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
6+
import com.beowulfe.hap.accessories.HorizontalTiltingWindowCovering;
7+
import com.beowulfe.hap.characteristics.EventableCharacteristic;
8+
import com.beowulfe.hap.characteristics.IntegerCharacteristic;
9+
10+
public class CurrentHorizontalTiltAngleCharacteristic extends IntegerCharacteristic implements EventableCharacteristic {
11+
12+
private final HorizontalTiltingWindowCovering windowCovering;
13+
14+
public CurrentHorizontalTiltAngleCharacteristic(HorizontalTiltingWindowCovering windowCovering) {
15+
super("0000006C-0000-1000-8000-0026BB765291", false, true, "The current horizontal tilt angle", -90, 90, "Arc Degree");
16+
this.windowCovering = windowCovering;
17+
}
18+
19+
@Override
20+
protected void setValue(Integer value) throws Exception {
21+
//Read Only
22+
}
23+
24+
@Override
25+
protected CompletableFuture<Integer> getValue() {
26+
return windowCovering.getCurrentHorizontalTiltAngle();
27+
}
28+
29+
@Override
30+
public void subscribe(HomekitCharacteristicChangeCallback callback) {
31+
windowCovering.subscribeCurrentHorizontalTiltAngle(callback);
32+
}
33+
34+
@Override
35+
public void unsubscribe() {
36+
windowCovering.unsubscribeCurrentHorizontalTiltAngle();
37+
}
38+
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.beowulfe.hap.impl.characteristics.windowcovering;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
6+
import com.beowulfe.hap.accessories.WindowCovering;
7+
import com.beowulfe.hap.characteristics.EventableCharacteristic;
8+
import com.beowulfe.hap.characteristics.IntegerCharacteristic;
9+
10+
public class CurrentPositionCharacteristic extends IntegerCharacteristic implements EventableCharacteristic {
11+
12+
private final WindowCovering windowCovering;
13+
14+
public CurrentPositionCharacteristic(WindowCovering windowCovering) {
15+
super("0000006D-0000-1000-8000-0026BB765291", false, true, "The current position", 0, 100, "%");
16+
this.windowCovering = windowCovering;
17+
}
18+
19+
@Override
20+
protected void setValue(Integer value) throws Exception {
21+
//Read Only
22+
}
23+
24+
@Override
25+
protected CompletableFuture<Integer> getValue() {
26+
return windowCovering.getCurrentPosition();
27+
}
28+
29+
@Override
30+
public void subscribe(HomekitCharacteristicChangeCallback callback) {
31+
windowCovering.subscribeCurrentPosition(callback);
32+
}
33+
34+
@Override
35+
public void unsubscribe() {
36+
windowCovering.unsubscribeCurrentPosition();
37+
}
38+
39+
}

0 commit comments

Comments
 (0)