Skip to content

Commit 12e3b45

Browse files
author
Eugen Freiter
committed
add Faucet and HeaterCooler
Signed-off-by: Eugen Freiter <freiter@gmx.de>
1 parent f9502d2 commit 12e3b45

15 files changed

+557
-13
lines changed

CHANGES.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# HAP-Java 2.0.0
22
* major refactoring to support optional characteristics
3-
* structure and names are adapted to HAP spec structure and naming.
3+
* structure and names adapted to HAP spec structure and naming.
44
* structure is following
55
* `accessory` package include basis accessory as the listed in HAP spec, plus interfaces for optional characteristics. clients should extend the accessory classes. e.g. `WindowCoveringAccessory` or `AccessoryWithBrightness`
66
* `characteristics` package consists of all characteristics, optional and mandatory. e.g. `TargetHorizontalTiltAngleCharacteristic`. The naming is done in accordance to HAP spec.
7-
* `services` package consists of services, which grouping characteristics. e.g. `WindowCoveringService` defines mandatory and optional characteristics for a window covering service as it is defined in HAP spec.
8-
* `server` package consists classes to run homekit server and handle communication
9-
* the process is following: client, e.g. Openhab bindings, extends accessory classes, e.g. `WindowCoveringAccessory` and implements all required methods. WindowCoveringAccessory is linked already to WindowCoveringService, that in turn is link to single characteristics.
7+
* `services` package consists of services, which grouping characteristics. e.g. `WindowCoveringService` defines mandatory and optional characteristics for a window covering service as it is defined in HAP spec.
8+
* `server` package consists classes to run HomeKit server and handle communication
9+
* the process is following: client, e.g. openHAB bindings, extends accessory classes, e.g. `WindowCoveringAccessory` and implements all required methods. WindowCoveringAccessory is linked already to WindowCoveringService, that in turn is link to single characteristics.
1010

1111
# HAP-Java 1.1.5
1212

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Supported HomeKit Accessories
2424
=========
2525

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

2929
| HomeKit Accessory & Service type | Supported by Java-HAP |
3030
|--------------------|--------------------|
@@ -41,11 +41,11 @@ fully supports 33 out of 45 HomeKit accessory services defined there.
4141
| Door | :white_check_mark: |
4242
| Doorbell | :white_check_mark: |
4343
| Fan | :white_check_mark: |
44-
| Faucet | :x: |
44+
| Faucet | :white_check_mark: |
4545
| Filter Maintenance | :x: |
4646
| Garage Door Opener | :white_check_mark: |
4747
| HAP Protocol Information | :white_check_mark: |
48-
| Heater Cooler | :x: |
48+
| Heater Cooler | :white_check_mark: |
4949
| Humidifier Dehumidifier | :x: |
5050
| Humidity Sensor | :white_check_mark: |
5151
| Irrigation System | :x: |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface FanAccessory extends HomekitAccessory {
3434
/**
3535
* Subscribes to changes in the active state of the fan.
3636
*
37-
* @param callback the function to call when the direction changes.
37+
* @param callback the function to call when the active state changes.
3838
*/
3939
void subscribeActive(HomekitCharacteristicChangeCallback callback);
4040

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.github.hapjava.accessories;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.concurrent.CompletableFuture;
6+
import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithFanState;
7+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
8+
import io.github.hapjava.services.Service;
9+
import io.github.hapjava.services.impl.FanService;
10+
import io.github.hapjava.services.impl.FaucetService;
11+
12+
/**
13+
* This service describes accessories like faucets or shower heads.
14+
*
15+
* @author Eugen Freiter
16+
*/
17+
public interface FaucetAccessory extends HomekitAccessory {
18+
/**
19+
* Mandatory: Retrieves the current active state of the faucet.
20+
*
21+
* @return a future that will contain the binary state
22+
*/
23+
CompletableFuture<Boolean> isActive();
24+
25+
/**
26+
* Sets the active state of the faucet
27+
*
28+
* @param state the binary state to set
29+
* @return a future that completes when the change is made
30+
* @throws Exception when the change cannot be made
31+
*/
32+
CompletableFuture<Void> setActive(boolean state) throws Exception;
33+
34+
/**
35+
* Subscribes to changes in the active state of the faucet.
36+
*
37+
* @param callback the function to call when the active state changes.
38+
*/
39+
void subscribeActive(HomekitCharacteristicChangeCallback callback);
40+
41+
/** Unsubscribes from changes in the active state of the faucet. */
42+
void unsubscribeActive();
43+
44+
@Override
45+
default Collection<Service> getServices() {
46+
return Collections.singleton(new FaucetService(this));
47+
}
48+
}
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 java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.concurrent.CompletableFuture;
6+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
7+
import io.github.hapjava.characteristics.impl.heatercooler.CurrentHeaterCoolerStateEnum;
8+
import io.github.hapjava.characteristics.impl.heatercooler.TargetHeaterCoolerStateEnum;
9+
import io.github.hapjava.services.Service;
10+
import io.github.hapjava.services.impl.HeaterCoolerService;
11+
12+
/**
13+
* Heater Cooler accessory
14+
*
15+
* @author Eugen Freiter
16+
*/
17+
public interface HeaterCoolerAccessory extends HomekitAccessory {
18+
/**
19+
* Retrieves the current temperature, in celsius degrees.
20+
*
21+
* @return a future that will contain the temperature.
22+
*/
23+
CompletableFuture<Double> getCurrentTemperature();
24+
25+
26+
/**
27+
* Mandatory: Retrieves the current active state of the fan'.
28+
*
29+
* @return a future that will contain the binary state
30+
*/
31+
CompletableFuture<Boolean> isActive();
32+
33+
/**
34+
* Sets the active state of the fan
35+
*
36+
* @param state the binary state to set
37+
* @return a future that completes when the change is made
38+
* @throws Exception when the change cannot be made
39+
*/
40+
CompletableFuture<Void> setActive(boolean state) throws Exception;
41+
42+
/**
43+
* Retrieves the heater /cooler current state.
44+
*
45+
* @return a future that will contain the heater cooler current state .
46+
*/
47+
CompletableFuture<CurrentHeaterCoolerStateEnum> getCurrentHeaterCoolerState();
48+
49+
/**
50+
* Retrieves the heater cooler target state.
51+
*
52+
* @return a future that will contain the heater cooler target state .
53+
*/
54+
CompletableFuture<TargetHeaterCoolerStateEnum> getTargetHeaterCoolerState();
55+
56+
/**
57+
* set heater cooler target state the lock target state.
58+
*
59+
* @param state heater cooler target state
60+
* @return a future that completes when the change is made
61+
*/
62+
CompletableFuture<Void> setTargetHeaterCoolerState(TargetHeaterCoolerStateEnum state);
63+
64+
/**
65+
* Subscribes to changes in the heater cooler current state.
66+
*
67+
* @param callback the function to call when the state changes.
68+
*/
69+
void subscribeCurrentHeaterCoolerState(HomekitCharacteristicChangeCallback callback);
70+
71+
/** Unsubscribes from changes in heater cooler current state. */
72+
void unsubscribeCurrentHeaterCoolerState();
73+
74+
/**
75+
* Subscribes to changes in the heater cooler target state.
76+
*
77+
* @param callback the function to call when the state changes.
78+
*/
79+
void subscribeTargetHeaterCoolerState(HomekitCharacteristicChangeCallback callback);
80+
81+
/** Unsubscribes from changes in heater cooler target state. */
82+
void unsubscribeTargetHeaterCoolerState();
83+
84+
/**
85+
* Subscribes to changes in the active state of the heater cooler .
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 heater cooler . */
92+
void unsubscribeActive();
93+
94+
/**
95+
* Subscribes to changes in the current temperature.
96+
*
97+
* @param callback the function to call when the state changes.
98+
*/
99+
void subscribeCurrentTemperature(HomekitCharacteristicChangeCallback callback);
100+
101+
/** Unsubscribes from changes in the current temperature. */
102+
void unsubscribeCurrentTemperature();
103+
104+
@Override
105+
default Collection<Service> getServices() {
106+
return Collections.singleton(new HeaterCoolerService(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 java.util.concurrent.CompletableFuture;
4+
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
5+
import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitEnum;
6+
7+
/** Accessory with characteristic that describes units of temperature used for presentation purposes (e.g. the units of temperature displayed on the
8+
screen). */
9+
public interface AccessoryWithTemperatureDisplayUnits {
10+
11+
/**
12+
* Retrieves temperature display units
13+
*
14+
* @return a future that will contain temperature display units
15+
*/
16+
CompletableFuture<TemperatureDisplayUnitEnum> getTemperatureDisplayUnits();
17+
18+
19+
/**
20+
* Sets the temperature display units
21+
*
22+
* @param units the target temperature display units
23+
* @return a future that completes when the change is made
24+
* @throws Exception when the change cannot be made
25+
*/
26+
CompletableFuture<Void> setTemperatureDisplayUnits(TemperatureDisplayUnitEnum units) throws Exception;
27+
28+
/**
29+
* Subscribes to changes in the temperature display units
30+
*
31+
* @param callback the function to call when temperature display units changes.
32+
*/
33+
void subscribeTemperatureDisplayUnits(HomekitCharacteristicChangeCallback callback);
34+
35+
/** Unsubscribes from changes in the temperature display units */
36+
void unsubscribeTemperatureDisplayUnits();
37+
}

src/main/java/io/github/hapjava/characteristics/impl/airquality/AirQualityEnum.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
public enum AirQualityEnum implements CharacteristicEnum {
1010
UNKNOWN(0),
1111
EXCELLENT(1),
12-
GOOD(0),
13-
FAIR(1),
14-
INFERIOR(1),
12+
GOOD(2),
13+
FAIR(3),
14+
INFERIOR(4),
1515
POOR(5);
1616

1717
private static final Map<Integer, AirQualityEnum> reverse;
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.heatercooler;
2+
3+
import java.util.Optional;
4+
import java.util.concurrent.CompletableFuture;
5+
import java.util.function.Consumer;
6+
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;
11+
12+
/**
13+
* This characteristic describes the current state of a heater cooler.
14+
*/
15+
public class CurrentHeaterCoolerStateCharacteristic extends EnumCharacteristic<CurrentHeaterCoolerStateEnum>
16+
implements EventableCharacteristic {
17+
18+
public CurrentHeaterCoolerStateCharacteristic(
19+
Supplier<CompletableFuture<CurrentHeaterCoolerStateEnum>> getter,
20+
Consumer<HomekitCharacteristicChangeCallback> subscriber,
21+
Runnable unsubscriber) {
22+
super(
23+
"000000B1-0000-1000-8000-0026BB765291",
24+
"current heater cooler state",
25+
3,
26+
Optional.of(getter),
27+
Optional.empty(),
28+
Optional.of(subscriber),
29+
Optional.of(unsubscriber));
30+
}
31+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.github.hapjava.characteristics.impl.heatercooler;
2+
3+
import java.util.Arrays;
4+
import java.util.Map;
5+
import java.util.stream.Collectors;
6+
import io.github.hapjava.characteristics.CharacteristicEnum;
7+
8+
/** 0 ”Inactive”
9+
1 ”Idle”
10+
2 ”Heating”
11+
3 ”Cooling” */
12+
public enum CurrentHeaterCoolerStateEnum implements CharacteristicEnum {
13+
INACTIVE(0),
14+
IDLE(1),
15+
HEATING(2),
16+
COOLING(3);
17+
18+
private static final Map<Integer, CurrentHeaterCoolerStateEnum> reverse;
19+
20+
static {
21+
reverse =
22+
Arrays.stream(CurrentHeaterCoolerStateEnum.values())
23+
.collect(Collectors.toMap(CurrentHeaterCoolerStateEnum::getCode, t -> t));
24+
}
25+
26+
public static CurrentHeaterCoolerStateEnum fromCode(Integer code) {
27+
return reverse.get(code);
28+
}
29+
30+
private final int code;
31+
32+
CurrentHeaterCoolerStateEnum(int code) {
33+
this.code = code;
34+
}
35+
36+
@Override
37+
public int getCode() {
38+
return code;
39+
}
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.github.hapjava.characteristics.impl.heatercooler;
2+
3+
import java.util.Optional;
4+
import java.util.concurrent.CompletableFuture;
5+
import java.util.function.Consumer;
6+
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;
11+
import io.github.hapjava.characteristics.impl.thermostat.TargetHeatingCoolingStateEnum;
12+
13+
/**
14+
* This characteristic describes the target state of heater cooler.
15+
*/
16+
public class TargetHeaterCoolerStateCharacteristic extends EnumCharacteristic<TargetHeaterCoolerStateEnum>
17+
implements EventableCharacteristic {
18+
19+
public TargetHeaterCoolerStateCharacteristic(
20+
Supplier<CompletableFuture<TargetHeaterCoolerStateEnum>> getter,
21+
ExceptionalConsumer<TargetHeaterCoolerStateEnum> setter,
22+
Consumer<HomekitCharacteristicChangeCallback> subscriber,
23+
Runnable unsubscriber) {
24+
super(
25+
"000000B2-0000-1000-8000-0026BB765291",
26+
"target heater cooler state",
27+
2,
28+
Optional.of(getter),
29+
Optional.of(setter),
30+
Optional.of(subscriber),
31+
Optional.of(unsubscriber));
32+
}
33+
34+
@Override
35+
protected void setValue(Integer value) throws Exception {
36+
if (!setter.isPresent()) {
37+
return;
38+
}
39+
setter.get().accept(TargetHeaterCoolerStateEnum.fromCode(value));
40+
}
41+
}

0 commit comments

Comments
 (0)