Skip to content

Commit 8d692a1

Browse files
author
Eugen Freiter
committed
add humidifier dehumidifier accessory
Signed-off-by: Eugen Freiter <freiter@gmx.de>
1 parent 12e3b45 commit 8d692a1

22 files changed

+667
-75
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
HAP-Java
22
=========
3-
HAP-Java is a Java implementation of the Homekit Accessory Protocol.
3+
HAP-Java is a Java implementation of the HomeKit Accessory Protocol.
44

5-
Using this library, you can create your own Homekit Accessory or Homekit Accessory Bridge.
5+
Using this library, you can create your own HomeKit Accessory or HomeKit Accessory Bridge.
66

77
This library would not have been possible without [Tian Zhang](https://github.com/KhaosT) who did a lot of the hard work of figuring out how the protocol works in his NodeJS implementation.
88

@@ -18,13 +18,13 @@ Include HAP-Java in your project using maven:
1818
</dependency>
1919
```
2020

21-
After that, read the [Javadoc](http://beowulfe.github.io/HAP-Java/apidocs/) and check out the [Sample](https://github.com/beowulfe/HAP-Java/tree/sample).
21+
After that, check out the [Sample](https://github.com/hap-java/HAP-Java/tree/sample).
2222

2323
Supported HomeKit Accessories
2424
=========
2525

2626
Current implementation is based on HAP specification Release R2 (published 2019-07-26) and
27-
fully supports 35 out of 45 HomeKit accessory services defined there.
27+
fully supports 36 out of 45 HomeKit accessory services defined there.
2828

2929
| HomeKit Accessory & Service type | Supported by Java-HAP |
3030
|--------------------|--------------------|
@@ -46,7 +46,7 @@ fully supports 35 out of 45 HomeKit accessory services defined there.
4646
| Garage Door Opener | :white_check_mark: |
4747
| HAP Protocol Information | :white_check_mark: |
4848
| Heater Cooler | :white_check_mark: |
49-
| Humidifier Dehumidifier | :x: |
49+
| Humidifier Dehumidifier | :white_check_mark: |
5050
| Humidity Sensor | :white_check_mark: |
5151
| Irrigation System | :x: |
5252
| Leak Sensor | :white_check_mark: |

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package io.github.hapjava.accessories;
22

3-
import java.util.Collection;
4-
import java.util.Collections;
5-
import java.util.concurrent.CompletableFuture;
6-
import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithFanState;
73
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
84
import io.github.hapjava.services.Service;
9-
import io.github.hapjava.services.impl.FanService;
105
import io.github.hapjava.services.impl.FaucetService;
6+
import java.util.Collection;
7+
import java.util.Collections;
8+
import java.util.concurrent.CompletableFuture;
119

1210
/**
1311
* This service describes accessories like faucets or shower heads.

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.github.hapjava.accessories;
22

3-
import java.util.Collection;
4-
import java.util.Collections;
5-
import java.util.concurrent.CompletableFuture;
63
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
74
import io.github.hapjava.characteristics.impl.heatercooler.CurrentHeaterCoolerStateEnum;
85
import io.github.hapjava.characteristics.impl.heatercooler.TargetHeaterCoolerStateEnum;
96
import io.github.hapjava.services.Service;
107
import io.github.hapjava.services.impl.HeaterCoolerService;
8+
import java.util.Collection;
9+
import java.util.Collections;
10+
import java.util.concurrent.CompletableFuture;
1111

1212
/**
1313
* Heater Cooler accessory
@@ -22,16 +22,15 @@ public interface HeaterCoolerAccessory extends HomekitAccessory {
2222
*/
2323
CompletableFuture<Double> getCurrentTemperature();
2424

25-
2625
/**
27-
* Mandatory: Retrieves the current active state of the fan'.
26+
* Mandatory: Retrieves the current active state of the Heater Cooler.
2827
*
2928
* @return a future that will contain the binary state
3029
*/
3130
CompletableFuture<Boolean> isActive();
3231

3332
/**
34-
* Sets the active state of the fan
33+
* Sets the active state of the Heater Cooler
3534
*
3635
* @param state the binary state to set
3736
* @return a future that completes when the change is made
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package io.github.hapjava.accessories;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import io.github.hapjava.characteristics.impl.humidifier.CurrentHumidifierDehumidifierStateEnum;
5+
import io.github.hapjava.characteristics.impl.humidifier.TargetHumidifierDehumidifierStateEnum;
6+
import io.github.hapjava.services.Service;
7+
import io.github.hapjava.services.impl.HumidifierDehumidifierService;
8+
import java.util.Collection;
9+
import java.util.Collections;
10+
import java.util.concurrent.CompletableFuture;
11+
12+
/**
13+
* Humidifier/Dehumidifier accessory
14+
*
15+
* @author Eugen Freiter
16+
*/
17+
public interface HumidifierDehumidifierAccessory extends HomekitAccessory {
18+
/**
19+
* Retrieves the current relative humidity.
20+
*
21+
* @return a future that will contain the humidity as a value between 0 and 100.
22+
*/
23+
CompletableFuture<Double> getCurrentHumidity();
24+
25+
/**
26+
* Mandatory: Retrieves the current active state of the humidifier/dehumidifier.
27+
*
28+
* @return a future that will contain the binary state
29+
*/
30+
CompletableFuture<Boolean> isActive();
31+
32+
/**
33+
* Sets the active state of the humidifier/dehumidifier
34+
*
35+
* @param state the binary state to set
36+
* @return a future that completes when the change is made
37+
* @throws Exception when the change cannot be made
38+
*/
39+
CompletableFuture<Void> setActive(boolean state) throws Exception;
40+
41+
/**
42+
* Retrieves the humidifier/dehumidifier current state.
43+
*
44+
* @return a future that will contain the humidifier/dehumidifier current state .
45+
*/
46+
CompletableFuture<CurrentHumidifierDehumidifierStateEnum> getCurrentHumidifierDehumidifierState();
47+
48+
/**
49+
* Retrieves the humidifier/dehumidifier target state.
50+
*
51+
* @return a future that will contain the humidifier/dehumidifier target state .
52+
*/
53+
CompletableFuture<TargetHumidifierDehumidifierStateEnum> getTargetHumidifierDehumidifierState();
54+
55+
/**
56+
* set humidifier/dehumidifier target state the lock target state.
57+
*
58+
* @param state humidifier/dehumidifier target state
59+
* @return a future that completes when the change is made
60+
*/
61+
CompletableFuture<Void> setTargetHumidifierDehumidifierState(
62+
TargetHumidifierDehumidifierStateEnum state);
63+
64+
/**
65+
* Subscribes to changes in the humidifier/dehumidifier current state.
66+
*
67+
* @param callback the function to call when the state changes.
68+
*/
69+
void subscribeCurrentHumidifierDehumidifierState(HomekitCharacteristicChangeCallback callback);
70+
71+
/** Unsubscribes from changes in humidifier/dehumidifier current state. */
72+
void unsubscribeCurrentHumidifierDehumidifierState();
73+
74+
/**
75+
* Subscribes to changes in the humidifier/dehumidifier target state.
76+
*
77+
* @param callback the function to call when the state changes.
78+
*/
79+
void subscribeTargetHumidifierDehumidifierState(HomekitCharacteristicChangeCallback callback);
80+
81+
/** Unsubscribes from changes in humidifier/dehumidifier target state. */
82+
void unsubscribeTargetHumidifierDehumidifierState();
83+
84+
/**
85+
* Subscribes to changes in the active state of the humidifier/dehumidifier .
86+
*
87+
* @param callback the function to call when the active state changes.
88+
*/
89+
void subscribeActive(HomekitCharacteristicChangeCallback callback);
90+
91+
/** Unsubscribes from changes in the active state of the humidifier/dehumidifier . */
92+
void unsubscribeActive();
93+
94+
/**
95+
* Subscribes to changes in the current humidity.
96+
*
97+
* @param callback the function to call when the state changes.
98+
*/
99+
void subscribeCurrentHumidity(HomekitCharacteristicChangeCallback callback);
100+
101+
/** Unsubscribes from changes in the current humidity. */
102+
void unsubscribeCurrentHumidity();
103+
104+
@Override
105+
default Collection<Service> getServices() {
106+
return Collections.singleton(new HumidifierDehumidifierService(this));
107+
}
108+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.github.hapjava.accessories.optionalcharacteristic;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Dehumidifier with humidity threshold.
8+
*
9+
* @author Eugen Freiter
10+
*/
11+
public interface AccessoryWithHumidityDehumidifierThreshold {
12+
13+
/**
14+
* Retrieves the humidity threshold.
15+
*
16+
* @return a future that will contain the humidity threshold.
17+
*/
18+
CompletableFuture<Double> getHumidityThreshold();
19+
20+
/**
21+
* Sets the humidity threshold above which the dehumidifier should be turned on.
22+
*
23+
* @param value the humidity threshold, in celsius degrees.
24+
* @throws Exception when the threshold cannot be changed.
25+
*/
26+
void setHumidityThreshold(Double value) throws Exception;
27+
28+
/**
29+
* Subscribes to changes in the humidity threshold.
30+
*
31+
* @param callback the function to call when the state changes.
32+
*/
33+
void subscribeHumidityThreshold(HomekitCharacteristicChangeCallback callback);
34+
35+
/** Unsubscribes from changes in the humidity threshold. */
36+
void unsubscribeHumidityThreshold();
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.github.hapjava.accessories.optionalcharacteristic;
2+
3+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Humidifier with humidity threshold.
8+
*
9+
* @author Eugen Freiter
10+
*/
11+
public interface AccessoryWithHumidityHumidifierThreshold {
12+
13+
/**
14+
* Retrieves the humidity threshold.
15+
*
16+
* @return a future that will contain the humidity threshold.
17+
*/
18+
CompletableFuture<Double> getHumidityThreshold();
19+
20+
/**
21+
* Sets the humidity threshold above which the humidifier should be turned on.
22+
*
23+
* @param value the humidity threshold, in celsius degrees.
24+
* @throws Exception when the threshold cannot be changed.
25+
*/
26+
void setHumidityThreshold(Double value) throws Exception;
27+
28+
/**
29+
* Subscribes to changes in the humidity threshold.
30+
*
31+
* @param callback the function to call when the state changes.
32+
*/
33+
void subscribeHumidityThreshold(HomekitCharacteristicChangeCallback callback);
34+
35+
/** Unsubscribes from changes in the humidity threshold. */
36+
void unsubscribeHumidityThreshold();
37+
}

src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTemperatureDisplayUnits.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package io.github.hapjava.accessories.optionalcharacteristic;
22

3-
import java.util.concurrent.CompletableFuture;
43
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
54
import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitEnum;
5+
import java.util.concurrent.CompletableFuture;
66

7-
/** Accessory with characteristic that describes units of temperature used for presentation purposes (e.g. the units of temperature displayed on the
8-
screen). */
7+
/**
8+
* Accessory with characteristic that describes units of temperature used for presentation purposes
9+
* (e.g. the units of temperature displayed on the screen).
10+
*/
911
public interface AccessoryWithTemperatureDisplayUnits {
1012

1113
/**
@@ -15,15 +17,15 @@ public interface AccessoryWithTemperatureDisplayUnits {
1517
*/
1618
CompletableFuture<TemperatureDisplayUnitEnum> getTemperatureDisplayUnits();
1719

18-
1920
/**
2021
* Sets the temperature display units
2122
*
2223
* @param units the target temperature display units
2324
* @return a future that completes when the change is made
2425
* @throws Exception when the change cannot be made
2526
*/
26-
CompletableFuture<Void> setTemperatureDisplayUnits(TemperatureDisplayUnitEnum units) throws Exception;
27+
CompletableFuture<Void> setTemperatureDisplayUnits(TemperatureDisplayUnitEnum units)
28+
throws Exception;
2729

2830
/**
2931
* Subscribes to changes in the temperature display units
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 water level.
8+
*
9+
* @author Eugen Freiter
10+
*/
11+
public interface AccessoryWithWaterLevel {
12+
13+
/**
14+
* Retrieves the water level in percent.
15+
*
16+
* @return a future that will contain the water level, expressed as an double between 0 and 100.
17+
*/
18+
CompletableFuture<Double> getWaterLevel();
19+
20+
/**
21+
* Subscribes to changes in the water level.
22+
*
23+
* @param callback the function to call when the state changes.
24+
*/
25+
void subscribeWaterLevel(HomekitCharacteristicChangeCallback callback);
26+
27+
/** Unsubscribes from changes in the water level. */
28+
void unsubscribeWaterLevel();
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.github.hapjava.characteristics.impl.common;
2+
3+
import io.github.hapjava.characteristics.EventableCharacteristic;
4+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
5+
import io.github.hapjava.characteristics.impl.base.FloatCharacteristic;
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+
/** This characteristic describes the current water level. */
12+
public class WaterLavelCharacteristic extends FloatCharacteristic
13+
implements EventableCharacteristic {
14+
15+
public WaterLavelCharacteristic(
16+
Supplier<CompletableFuture<Double>> getter,
17+
Consumer<HomekitCharacteristicChangeCallback> subscriber,
18+
Runnable unsubscriber) {
19+
super(
20+
"000000B5-0000-1000-8000-0026BB765291",
21+
"water level",
22+
0,
23+
100,
24+
1,
25+
"%",
26+
Optional.of(getter),
27+
Optional.empty(),
28+
Optional.of(subscriber),
29+
Optional.of(unsubscriber));
30+
}
31+
}

src/main/java/io/github/hapjava/characteristics/impl/heatercooler/CurrentHeaterCoolerStateCharacteristic.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package io.github.hapjava.characteristics.impl.heatercooler;
22

3+
import io.github.hapjava.characteristics.EventableCharacteristic;
4+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
5+
import io.github.hapjava.characteristics.impl.base.EnumCharacteristic;
36
import java.util.Optional;
47
import java.util.concurrent.CompletableFuture;
58
import java.util.function.Consumer;
69
import java.util.function.Supplier;
7-
import io.github.hapjava.characteristics.EventableCharacteristic;
8-
import io.github.hapjava.characteristics.ExceptionalConsumer;
9-
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
10-
import io.github.hapjava.characteristics.impl.base.EnumCharacteristic;
1110

12-
/**
13-
* This characteristic describes the current state of a heater cooler.
14-
*/
15-
public class CurrentHeaterCoolerStateCharacteristic extends EnumCharacteristic<CurrentHeaterCoolerStateEnum>
16-
implements EventableCharacteristic {
11+
/** This characteristic describes the current state of a heater cooler. */
12+
public class CurrentHeaterCoolerStateCharacteristic
13+
extends EnumCharacteristic<CurrentHeaterCoolerStateEnum> implements EventableCharacteristic {
1714

1815
public CurrentHeaterCoolerStateCharacteristic(
1916
Supplier<CompletableFuture<CurrentHeaterCoolerStateEnum>> getter,

0 commit comments

Comments
 (0)