Skip to content

Commit ade37fa

Browse files
committed
Added new accessory types
Added Fan, GarageDoor, Outlet, and Switch accessories
1 parent 4e05b25 commit ade37fa

20 files changed

+751
-44
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.HomekitAccessory;
8+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
9+
import com.beowulfe.hap.Service;
10+
import com.beowulfe.hap.accessories.properties.RotationDirection;
11+
import com.beowulfe.hap.impl.services.FanService;
12+
13+
/**
14+
* A fan, with power and rotational characteristics.
15+
*
16+
* @author Andy Lintner
17+
*/
18+
public interface Fan extends HomekitAccessory {
19+
20+
/**
21+
* Retrieves the current binary state of the fan's power.
22+
* @return a future that will contain the binary state
23+
*/
24+
CompletableFuture<Boolean> getFanPower();
25+
26+
/**
27+
* Retrieves the current rotation direction of the fan.
28+
* @return a future that will contain the direction
29+
*/
30+
CompletableFuture<RotationDirection> getRotationDirection();
31+
32+
/**
33+
* Retrieves the current speed of the fan's rotation
34+
* @return a future that will contain the speed, expressed as an integer between 0 and 100.
35+
*/
36+
CompletableFuture<Integer> getRotationSpeed();
37+
38+
/**
39+
* Sets the binary state of the fan's power
40+
* @param state the binary state to set
41+
* @return a future that completes when the change is made
42+
* @throws Exception when the change cannot be made
43+
*/
44+
CompletableFuture<Void> setFanPower(boolean state) throws Exception;
45+
46+
/**
47+
* Sets the rotation direction of the fan
48+
* @param direction the direction to set
49+
* @return a future that completes when the change is made
50+
* @throws Exception when the change cannot be made
51+
*/
52+
CompletableFuture<Void> setRotationDirection(RotationDirection direction) throws Exception;
53+
54+
55+
/**
56+
* Sets the speed of the fan's rotation
57+
* @param speed the speed to set, expressed as an integer between 0 and 100.
58+
* @return a future that completes when the change is made
59+
* @throws Exception when the change cannot be made
60+
*/
61+
CompletableFuture<Void> setRotationSpeed(Integer speed) throws Exception;
62+
63+
@Override
64+
default public Collection<Service> getServices() {
65+
return Collections.singleton(new FanService(this));
66+
}
67+
68+
/**
69+
* Subscribes to changes in the binary state of the fan's power.
70+
* @param callback the function to call when the state changes.
71+
*/
72+
void subscribeFanPower(HomekitCharacteristicChangeCallback callback);
73+
74+
/**
75+
* Subscribes to changes in the rotation direction of the fan.
76+
* @param callback the function to call when the direction changes.
77+
*/
78+
void subscribeRotationDirection(HomekitCharacteristicChangeCallback callback);
79+
80+
/**
81+
* Subscribes to changes in the rotation speed of the fan.
82+
* @param callback the function to call when the speed changes.
83+
*/
84+
void subscribeRotationSpeed(HomekitCharacteristicChangeCallback callback);
85+
86+
/**
87+
* Unsubscribes from changes in the binary state of the fan's power.
88+
*/
89+
void unsubscribeFanPower();
90+
91+
/**
92+
* Unsubscribes from changes in the rotation direction of the fan.
93+
*/
94+
void unsubscribeRotationDirection();
95+
96+
/**
97+
* Unsubscribes from changes in the fan's rotation speed.
98+
*/
99+
void unsubscribeRotationSpeed();
100+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.HomekitAccessory;
8+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
9+
import com.beowulfe.hap.Service;
10+
import com.beowulfe.hap.accessories.properties.DoorState;
11+
import com.beowulfe.hap.impl.services.GarageDoorService;
12+
13+
/**
14+
* A garage door opener, with control and status of a garage door
15+
*
16+
* @author Andy Lintner
17+
*/
18+
public interface GarageDoor extends HomekitAccessory {
19+
20+
/**
21+
* Retrieves the current state of the door
22+
* @return a future which will contain the door's state
23+
*/
24+
CompletableFuture<DoorState> getCurrentDoorState();
25+
26+
/**
27+
* Retrieves the targeted state of the door
28+
* @return a future which will contain the door's targeted state
29+
*/
30+
CompletableFuture<DoorState> getTargetDoorState();
31+
32+
/**
33+
* Retrieves an indicator of an obstruction detected by the door
34+
* @return a future which will contain the indicator
35+
*/
36+
CompletableFuture<Boolean> getObstructionDetected();
37+
38+
/**
39+
* Sets the targeted state of the door.
40+
* @param state the targeted state
41+
* @return a future that completes when the change is made
42+
* @throws Exception when the change cannot be made
43+
*/
44+
CompletableFuture<Void> setTargetDoorState(DoorState state) throws Exception;
45+
46+
/**
47+
* Subscribes to changes in the door's state
48+
* @param callback the function to call when the state changes
49+
*/
50+
void subscribeCurrentDoorState(HomekitCharacteristicChangeCallback callback);
51+
52+
/**
53+
* Subscribes to changes in the door's targeted state
54+
* @param callback the function to call when the targeted state changes
55+
*/
56+
void subscribeTargetDoorState(HomekitCharacteristicChangeCallback callback);
57+
58+
/**
59+
* Subscribes to changes in the obstruction detected indicator
60+
* @param callback the function to call when the indicator chnages
61+
*/
62+
void subscribeObstructionDetected(HomekitCharacteristicChangeCallback callback);
63+
64+
/**
65+
* Unsubscribes from changes in the door's state
66+
*/
67+
void unsubscribeCurrentDoorState();
68+
69+
/**
70+
* Unsubscribes from changes in the door's targeted state
71+
*/
72+
void unsubscribeTargetDoorState();
73+
74+
/**
75+
* Unsubscribes from changes in the door's obstruction detected indicator
76+
*/
77+
void unsubscribeObstructionDetected();
78+
79+
80+
@Override
81+
default public Collection<Service> getServices() {
82+
return Collections.singleton(new GarageDoorService(this));
83+
}
84+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.HomekitAccessory;
8+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
9+
import com.beowulfe.hap.Service;
10+
import com.beowulfe.hap.impl.services.OutletService;
11+
12+
/**
13+
* A power outlet with boolean power and usage states.
14+
*
15+
* @author Andy Lintner
16+
*/
17+
public interface Outlet extends HomekitAccessory {
18+
19+
@Override
20+
default public Collection<Service> getServices() {
21+
return Collections.singleton(new OutletService(this));
22+
}
23+
24+
/**
25+
* Retrieves the current binary state of the outlet's power.
26+
* @return a future that will contain the binary state
27+
*/
28+
public CompletableFuture<Boolean> getPowerState();
29+
30+
/**
31+
* Retrieves the current binary state indicating whether the outlet is in use.
32+
* @return a future that will contain the binary state
33+
*/
34+
public CompletableFuture<Boolean> getOutletInUse();
35+
36+
/**
37+
* Sets the binary state of the outlet's power.
38+
* @param state the binary state to set
39+
* @return a future that completes when the change is made
40+
* @throws Exception when the change cannot be made
41+
*/
42+
public CompletableFuture<Void> setPowerState(boolean state);
43+
44+
/**
45+
* Subscribes to changes in the binary state of the outlet's power.
46+
* @param callback the function to call when the state changes.
47+
*/
48+
public void subscribePowerState(HomekitCharacteristicChangeCallback callback);
49+
50+
/**
51+
* Subscribes to changes in the binary state indicating whether the outlet is in use.
52+
* @param callback the function to call when the state changes.
53+
*/
54+
public void subscribeOutletInUse(HomekitCharacteristicChangeCallback callback);
55+
56+
/**
57+
* Unsubscribes from changes in the binary state of the outlet's power.
58+
*/
59+
public void unsubscribePowerState();
60+
61+
/**
62+
* Unsubscribes from changes in the binary state indicating whether hte outlet is in use.
63+
*/
64+
public void unsubscribeOutletInUse();
65+
66+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.HomekitAccessory;
8+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
9+
import com.beowulfe.hap.Service;
10+
import com.beowulfe.hap.impl.services.SwitchService;
11+
12+
/**
13+
* A simple switch with a binary state.
14+
*
15+
* @author Andy Lintner
16+
*/
17+
public interface Switch extends HomekitAccessory {
18+
19+
/**
20+
* Retrieves the current binary state of the switch.
21+
* @return a future that will contain the binary state
22+
*/
23+
CompletableFuture<Boolean> getSwitchState();
24+
25+
/**
26+
* Sets the binary state of the switch
27+
* @param state the binary state to set
28+
* @return a future that completes when the change is made
29+
* @throws Exception when the change cannot be made
30+
*/
31+
CompletableFuture<Void> setSwitchState(boolean state) throws Exception;
32+
33+
@Override
34+
default public Collection<Service> getServices() {
35+
return Collections.singleton(new SwitchService(this));
36+
}
37+
38+
/**
39+
* Subscribes to changes in the binary state of the switch.
40+
* @param callback the function to call when the state changes.
41+
*/
42+
void subscribeSwitchState(HomekitCharacteristicChangeCallback callback);
43+
44+
/**
45+
* Unsubscribes from changes in the binary state of the switch.
46+
*/
47+
void unsubscribeSwitchState();
48+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
public enum DoorState {
8+
9+
OPEN(0),
10+
CLOSED(1),
11+
OPENING(2),
12+
CLOSING(3),
13+
STOPPED(4);
14+
15+
16+
private final static Map<Integer, DoorState> reverse;
17+
static {
18+
reverse = Arrays.stream(DoorState.values()).collect(Collectors.toMap(t -> t.getCode(), t -> t));
19+
}
20+
21+
public static DoorState fromCode(Integer code) {
22+
return reverse.get(code);
23+
}
24+
25+
private final int code;
26+
27+
private DoorState(int code) {
28+
this.code = code;
29+
}
30+
31+
public int getCode() {
32+
return code;
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
public enum RotationDirection {
8+
CLOCKWISE(0),
9+
COUNTER_CLOCKWISE(1)
10+
;
11+
12+
private final static Map<Integer, RotationDirection> reverse;
13+
static {
14+
reverse = Arrays.stream(RotationDirection.values()).collect(Collectors.toMap(t -> t.getCode(), t -> t));
15+
}
16+
17+
public static RotationDirection fromCode(Integer code) {
18+
return reverse.get(code);
19+
}
20+
21+
private final int code;
22+
23+
private RotationDirection(int code) {
24+
this.code = code;
25+
}
26+
27+
public int getCode() {
28+
return code;
29+
}
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.beowulfe.hap.impl;
2+
3+
public interface ExceptionalConsumer<T> {
4+
void accept(T t) throws Exception;
5+
}

0 commit comments

Comments
 (0)