Skip to content

Commit c640cdb

Browse files
author
Eugen Freiter
committed
Add Doorbell, Microphone, Slat, Speaker, StatelessProgrammableSwitch accessories
Signed-off-by: Eugen Freiter <freiter@gmx.de>
1 parent 5f404f8 commit c640cdb

25 files changed

+971
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.github.hapjava.accessories;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import io.github.hapjava.characteristics.impl.common.ProgrammableSwitchEnum;
5+
import io.github.hapjava.services.Service;
6+
import io.github.hapjava.services.impl.DoorbellService;
7+
import java.util.Collection;
8+
import java.util.Collections;
9+
import java.util.concurrent.CompletableFuture;
10+
11+
/**
12+
* The Doorbell accessory describes a doorbell.
13+
*
14+
* @author Eugen Freiter
15+
*/
16+
public interface DoorbellAccessory extends HomekitAccessory {
17+
18+
/**
19+
* Retrieves the last states of the doorbell. Bluetooth device should return the last event, the
20+
* IP device should always return null
21+
*
22+
* @return state of the door bell event
23+
*/
24+
CompletableFuture<ProgrammableSwitchEnum> getSwitchEvent();
25+
26+
/**
27+
* Subscribes to changes in doorbell switch event, i.e. pressing on the door bell button.
28+
*
29+
* @param callback the function to call when the state changes.
30+
*/
31+
void subscribeSwitchEvent(HomekitCharacteristicChangeCallback callback);
32+
33+
/** Unsubscribes from changes in doorbell switch event. */
34+
void unsubscribeSwitchEvent();
35+
36+
@Override
37+
default Collection<Service> getServices() {
38+
return Collections.singleton(new DoorbellService(this));
39+
}
40+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.github.hapjava.accessories;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import io.github.hapjava.services.Service;
5+
import io.github.hapjava.services.impl.MicrophoneService;
6+
import java.util.Collection;
7+
import java.util.Collections;
8+
import java.util.concurrent.CompletableFuture;
9+
10+
/**
11+
* Microphone accessory.
12+
*
13+
* @author Eugen Freiter
14+
*/
15+
public interface MicrophoneAccessory extends HomekitAccessory {
16+
17+
/**
18+
* Retrieves mute status.
19+
*
20+
* @return true if accessory is muted
21+
*/
22+
CompletableFuture<Boolean> isMuted();
23+
24+
/**
25+
* Sets the mute status
26+
*
27+
* @param mute true if accessory should be muted
28+
* @return a future that completes when the change is made
29+
* @throws Exception when the change cannot be made
30+
*/
31+
CompletableFuture<Void> setMute(boolean mute) throws Exception;
32+
33+
/**
34+
* Subscribes to changes in mute state.
35+
*
36+
* @param callback the function to call when the state changes.
37+
*/
38+
void subscribeMuteState(HomekitCharacteristicChangeCallback callback);
39+
40+
/** Unsubscribes from changes in the mute state. */
41+
void unsubscribeMuteState();
42+
43+
@Override
44+
default Collection<Service> getServices() {
45+
return Collections.singleton(new MicrophoneService(this));
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.github.hapjava.accessories;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import io.github.hapjava.characteristics.impl.slat.CurrentSlatStateEnum;
5+
import io.github.hapjava.characteristics.impl.slat.SlatTypeEnum;
6+
import io.github.hapjava.services.Service;
7+
import io.github.hapjava.services.impl.SlatService;
8+
import java.util.Collection;
9+
import java.util.Collections;
10+
import java.util.concurrent.CompletableFuture;
11+
12+
/**
13+
* A slat which tilts on a vertical or a horizontal axis.
14+
*
15+
* @author Eugen Freiter
16+
*/
17+
public interface SlatAccessory extends HomekitAccessory {
18+
19+
/**
20+
* Retrieves the current state of the slat
21+
*
22+
* @return a future that will contain the state
23+
*/
24+
CompletableFuture<CurrentSlatStateEnum> getSlatState();
25+
26+
/**
27+
* Subscribes to changes in the state of the slat.
28+
*
29+
* @param callback the function to call when the state changes.
30+
*/
31+
void subscribeSlatState(HomekitCharacteristicChangeCallback callback);
32+
33+
/** Unsubscribes from changes in the state of the slat. */
34+
void unsubscribeSlatState();
35+
36+
/**
37+
* Retrieves the slat type.
38+
*
39+
* @return a future that will slat type.
40+
*/
41+
CompletableFuture<SlatTypeEnum> getSlatType();
42+
43+
@Override
44+
default Collection<Service> getServices() {
45+
return Collections.singleton(new SlatService(this));
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.github.hapjava.accessories;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import io.github.hapjava.services.Service;
5+
import io.github.hapjava.services.impl.SpeakerService;
6+
import java.util.Collection;
7+
import java.util.Collections;
8+
import java.util.concurrent.CompletableFuture;
9+
10+
/**
11+
* Speaker accessory.
12+
*
13+
* @author Eugen Freiter
14+
*/
15+
public interface SpeakerAccessory extends HomekitAccessory {
16+
17+
/**
18+
* Retrieves mute status.
19+
*
20+
* @return true if accessory is muted
21+
*/
22+
CompletableFuture<Boolean> isMuted();
23+
24+
/**
25+
* Sets the mute status
26+
*
27+
* @param mute true if accessory should be muted
28+
* @return a future that completes when the change is made
29+
* @throws Exception when the change cannot be made
30+
*/
31+
CompletableFuture<Void> setMute(boolean mute) throws Exception;
32+
33+
/**
34+
* Subscribes to changes in mute state.
35+
*
36+
* @param callback the function to call when the state changes.
37+
*/
38+
void subscribeMuteState(HomekitCharacteristicChangeCallback callback);
39+
40+
/** Unsubscribes from changes in the mute state. */
41+
void unsubscribeMuteState();
42+
43+
@Override
44+
default Collection<Service> getServices() {
45+
return Collections.singleton(new SpeakerService(this));
46+
}
47+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.github.hapjava.accessories;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import io.github.hapjava.characteristics.impl.common.ProgrammableSwitchEnum;
5+
import io.github.hapjava.services.Service;
6+
import io.github.hapjava.services.impl.StatelessProgrammableSwitchService;
7+
import java.util.Collection;
8+
import java.util.Collections;
9+
import java.util.concurrent.CompletableFuture;
10+
11+
/**
12+
* The Stateless Programmable Switch accessory describes a stateless programmable switch..
13+
*
14+
* @author Eugen Freiter
15+
*/
16+
public interface StatelessProgrammableSwitchAccessory extends HomekitAccessory {
17+
18+
/**
19+
* Retrieves the last states of the switch. Bluetooth device should return the last event, the IP
20+
* device should always return null
21+
*
22+
* @return state of the switch event
23+
*/
24+
CompletableFuture<ProgrammableSwitchEnum> getSwitchEvent();
25+
26+
/**
27+
* Subscribes to changes in switch event, i.e. pressing on the button.
28+
*
29+
* @param callback the function to call when the state changes.
30+
*/
31+
void subscribeSwitchEvent(HomekitCharacteristicChangeCallback callback);
32+
33+
/** Unsubscribes from changes in switch event. */
34+
void unsubscribeSwitchEvent();
35+
36+
@Override
37+
default Collection<Service> getServices() {
38+
return Collections.singleton(new StatelessProgrammableSwitchService(this));
39+
}
40+
}

src/main/java/io/github/hapjava/accessories/ValveAccessory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public interface ValveAccessory extends HomekitAccessory {
7070
/**
7171
* Retrieves the valve type.
7272
*
73-
* <p>To communicate water is flowing through a valve, inUse should be used.
74-
*
75-
* @return a future that will contain the binary state
73+
* @return a future that will contain the valve type.
7674
*/
7775
CompletableFuture<ValveTypeEnum> getValveType();
7876

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.hapjava.accessories.optionalcharacteristic;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Accessory with current tilting characteristic.
8+
*
9+
* @author Eugen Freiter
10+
*/
11+
public interface AccessoryWithCurrentTilting {
12+
13+
/**
14+
* Retrieves the current tilt angle
15+
*
16+
* @return a future that will contain the position as a value between -90 and 90
17+
*/
18+
CompletableFuture<Integer> getCurrentTiltAngle();
19+
20+
/**
21+
* Subscribes to changes in the current tilt angle.
22+
*
23+
* @param callback the function to call when the state changes.
24+
*/
25+
void subscribeCurrentTiltAngle(HomekitCharacteristicChangeCallback callback);
26+
27+
/** Unsubscribes from changes in the current tilt angle */
28+
void unsubscribeCurrentTiltAngle();
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.github.hapjava.accessories.optionalcharacteristic;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Accessory with target tilting characteristic.
8+
*
9+
* @author Eugen Freiter
10+
*/
11+
public interface AccessoryWithTargetTilting {
12+
13+
/**
14+
* Retrieves the target tilt angle
15+
*
16+
* @return a future that will contain the target position as a value between -90 and 90
17+
*/
18+
CompletableFuture<Integer> getTargetTiltAngle();
19+
20+
/**
21+
* Sets the target tilt angle
22+
*
23+
* @param angle the target angle to set, as a value between -90 and 90
24+
* @return a future that completes when the change is made
25+
* @throws Exception when the change cannot be made
26+
*/
27+
CompletableFuture<Void> setTargetTiltAngle(int angle) throws Exception;
28+
29+
/**
30+
* Subscribes to changes in the target tilt angle.
31+
*
32+
* @param callback the function to call when the state changes.
33+
*/
34+
void subscribeTargetTiltAngle(HomekitCharacteristicChangeCallback callback);
35+
36+
/** Unsubscribes from changes in the target tilt angle */
37+
void unsubscribeTargetTiltAngle();
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.github.hapjava.accessories.optionalcharacteristic;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Accessory with volume values.
8+
*
9+
* @author Eugen Freiter
10+
*/
11+
public interface AccessoryWithVolume {
12+
13+
/**
14+
* Retrieves the current volume
15+
*
16+
* @return a future that will contain the volume, expressed as an integer between 0 and 100.
17+
*/
18+
CompletableFuture<Integer> getVolume();
19+
20+
/**
21+
* Sets the current volume
22+
*
23+
* @param value the volume, on a scale of 0 to 100, to set
24+
* @return a future that completes when the volume is changed
25+
* @throws Exception when the volume cannot be set
26+
*/
27+
CompletableFuture<Void> setVolume(Integer value) throws Exception;
28+
29+
/**
30+
* Subscribes to changes in the volume.
31+
*
32+
* @param callback the function to call when the state changes.
33+
*/
34+
void subscribeVolume(HomekitCharacteristicChangeCallback callback);
35+
36+
/** Unsubscribes from changes in the volume. */
37+
void unsubscribeVolume();
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.github.hapjava.characteristics.impl.audio;
2+
3+
import io.github.hapjava.characteristics.ExceptionalConsumer;
4+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
5+
import io.github.hapjava.characteristics.impl.base.EnumCharacteristic;
6+
import java.util.Optional;
7+
import java.util.concurrent.CompletableFuture;
8+
import java.util.function.Consumer;
9+
import java.util.function.Supplier;
10+
11+
/** A Mute characteristic allows the control of audio input or output accessory respectively. */
12+
public class MuteCharacteristic extends EnumCharacteristic<MuteEnum> {
13+
public MuteCharacteristic(
14+
Supplier<CompletableFuture<MuteEnum>> getter,
15+
ExceptionalConsumer<MuteEnum> setter,
16+
Consumer<HomekitCharacteristicChangeCallback> subscriber,
17+
Runnable unsubscriber) {
18+
super(
19+
"0000011A-0000-1000-8000-0026BB765291",
20+
"Mute",
21+
1,
22+
Optional.of(getter),
23+
Optional.of(setter),
24+
Optional.of(subscriber),
25+
Optional.of(unsubscriber));
26+
}
27+
}

0 commit comments

Comments
 (0)