Skip to content

Commit 0db27e8

Browse files
author
Eugen Freiter
committed
add service label service and hap protocol version service. fix Mute characteristic
Signed-off-by: Eugen Freiter <freiter@gmx.de>
1 parent 110a359 commit 0db27e8

File tree

9 files changed

+60
-63
lines changed

9 files changed

+60
-63
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This library would not have been possible without [Tian Zhang](https://github.co
99
Usage
1010
=========
1111
Include HAP-Java in your project using maven:
12+
1213
```
1314
<dependency>
1415
<groupId>io.github.hap-java</groupId>
@@ -23,9 +24,9 @@ Supported HomeKit Accessories
2324
=========
2425

2526
Current implementation is based on HAP specification Release R2 (published 2019-07-26) and
26-
fully supports 31 out of 48 HomeKit accessories defined there.
27+
fully supports 33 out of 45 HomeKit accessory services defined there.
2728

28-
| HomeKit Accessory | Supported by Java-HAP |
29+
| HomeKit Accessory & Service type | Supported by Java-HAP |
2930
|--------------------|--------------------|
3031
| Accessory Information | :white_check_mark: |
3132
| Air Purifier | :white_check_mark: |
@@ -43,7 +44,7 @@ fully supports 31 out of 48 HomeKit accessories defined there.
4344
| Faucet | :x: |
4445
| Filter Maintenance | :x: |
4546
| Garage Door Opener | :white_check_mark: |
46-
| HAP Protocol Information | :x: |
47+
| HAP Protocol Information | :white_check_mark: |
4748
| Heater Cooler | :x: |
4849
| Humidifier Dehumidifier | :x: |
4950
| Humidity Sensor | :white_check_mark: |
@@ -58,7 +59,7 @@ fully supports 31 out of 48 HomeKit accessories defined there.
5859
| Occupancy Sensor | :white_check_mark: |
5960
| Outlet | :white_check_mark: |
6061
| Security System | :white_check_mark: |
61-
| Service Label | :x: |
62+
| Service Label | :white_check_mark: |
6263
| Siri | :x: |
6364
| Slat | :white_check_mark: |
6465
| Smoke Sensor | :white_check_mark: |
@@ -69,6 +70,6 @@ fully supports 31 out of 48 HomeKit accessories defined there.
6970
| Target Control Management | :x: |
7071
| Temperature Sensor | :white_check_mark: |
7172
| Thermostat | :white_check_mark: |
72-
| Valve | :white_check_mark: |
73-
| Window | :white_check_mark: |
74-
| Window Covering | :white_check_mark: |
73+
| Valve | :white_check_mark: |
74+
| Window | :white_check_mark: |
75+
| Window Covering | :white_check_mark: |

src/main/java/io/github/hapjava/characteristics/impl/audio/MuteCharacteristic.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@
22

33
import io.github.hapjava.characteristics.ExceptionalConsumer;
44
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
5-
import io.github.hapjava.characteristics.impl.base.EnumCharacteristic;
5+
import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic;
66
import java.util.Optional;
77
import java.util.concurrent.CompletableFuture;
88
import java.util.function.Consumer;
99
import java.util.function.Supplier;
1010

1111
/** A Mute characteristic allows the control of audio input or output accessory respectively. */
12-
public class MuteCharacteristic extends EnumCharacteristic<MuteEnum> {
12+
public class MuteCharacteristic extends BooleanCharacteristic {
1313
public MuteCharacteristic(
14-
Supplier<CompletableFuture<MuteEnum>> getter,
15-
ExceptionalConsumer<MuteEnum> setter,
14+
Supplier<CompletableFuture<Boolean>> getter,
15+
ExceptionalConsumer<Boolean> setter,
1616
Consumer<HomekitCharacteristicChangeCallback> subscriber,
1717
Runnable unsubscriber) {
1818
super(
1919
"0000011A-0000-1000-8000-0026BB765291",
2020
"Mute",
21-
1,
2221
Optional.of(getter),
2322
Optional.of(setter),
2423
Optional.of(subscriber),

src/main/java/io/github/hapjava/characteristics/impl/audio/MuteEnum.java

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.hapjava.characteristics.impl.common;
2+
3+
import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic;
4+
import java.util.Optional;
5+
import java.util.concurrent.CompletableFuture;
6+
import java.util.function.Supplier;
7+
8+
/** This characteristic describes a name and must not be a null value. */
9+
public class VersionCharacteristic extends StaticStringCharacteristic {
10+
11+
public VersionCharacteristic(Supplier<CompletableFuture<String>> getter) {
12+
super(
13+
"00000023-0000-1000-8000-0026BB765291",
14+
"HAP version",
15+
Optional.of(getter),
16+
Optional.empty(),
17+
Optional.empty());
18+
}
19+
}

src/main/java/io/github/hapjava/server/impl/http/impl/BinaryHandler.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.netty.channel.ChannelHandlerContext;
77
import io.netty.handler.codec.ByteToMessageCodec;
88
import java.io.IOException;
9-
import java.nio.charset.StandardCharsets;
109
import java.util.List;
1110
import org.slf4j.Logger;
1211
import org.slf4j.LoggerFactory;
@@ -25,7 +24,6 @@ public BinaryHandler(HomekitClientConnection connection) {
2524
@Override
2625
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
2726
if (started) {
28-
debugData("Sending data", msg, ctx);
2927
byte[] b = new byte[msg.readableBytes()];
3028
msg.readBytes(b);
3129
out.writeBytes(connection.encryptResponse(b));
@@ -40,7 +38,6 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
4038
in.readBytes(b);
4139
byte[] decrypted = connection.decryptRequest(b);
4240
ByteBuf outBuf = Unpooled.copiedBuffer(decrypted);
43-
debugData("Received data", outBuf, ctx);
4441
out.add(outBuf);
4542
started = true;
4643
}
@@ -55,13 +52,4 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
5552
}
5653
super.exceptionCaught(ctx, cause);
5754
}
58-
59-
private void debugData(String msg, ByteBuf b, ChannelHandlerContext ctx) throws Exception {
60-
if (logger.isTraceEnabled()) {
61-
logger.trace(
62-
String.format(
63-
"%s [%s]:%n%s",
64-
msg, ctx.channel().remoteAddress().toString(), b.toString(StandardCharsets.UTF_8)));
65-
}
66-
}
6755
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.github.hapjava.services.impl;
2+
3+
import io.github.hapjava.characteristics.impl.common.VersionCharacteristic;
4+
5+
/** This service describes label scheme. */
6+
public class HAPProtocolInformationService extends AbstractServiceImpl {
7+
8+
public HAPProtocolInformationService(VersionCharacteristic versionCharacteristic) {
9+
super("000000A2-0000-1000-8000-0026BB765291");
10+
addCharacteristic(versionCharacteristic);
11+
}
12+
}

src/main/java/io/github/hapjava/services/impl/MicrophoneService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName;
55
import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume;
66
import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic;
7-
import io.github.hapjava.characteristics.impl.audio.MuteEnum;
87
import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic;
98
import io.github.hapjava.characteristics.impl.common.NameCharacteristic;
109

@@ -22,8 +21,8 @@ public MicrophoneService(MuteCharacteristic muteCharacteristic) {
2221
public MicrophoneService(MicrophoneAccessory accessory) {
2322
this(
2423
new MuteCharacteristic(
25-
() -> accessory.isMuted().thenApply(s -> s ? MuteEnum.ON : MuteEnum.OFF),
26-
(v) -> accessory.setMute(v == MuteEnum.ON),
24+
accessory::isMuted,
25+
accessory::setMute,
2726
accessory::subscribeMuteState,
2827
accessory::unsubscribeMuteState));
2928
if (accessory instanceof AccessoryWithName) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.github.hapjava.services.impl;
2+
3+
import io.github.hapjava.characteristics.impl.common.ServiceLabelNamespaceCharacteristic;
4+
5+
/** This service describes label scheme. */
6+
public class ServiceLabelService extends AbstractServiceImpl {
7+
8+
public ServiceLabelService(
9+
ServiceLabelNamespaceCharacteristic serviceLabelNamespaceCharacteristic) {
10+
super("000000CC-0000-1000-8000-0026BB765291");
11+
addCharacteristic(serviceLabelNamespaceCharacteristic);
12+
}
13+
}

src/main/java/io/github/hapjava/services/impl/SpeakerService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName;
55
import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume;
66
import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic;
7-
import io.github.hapjava.characteristics.impl.audio.MuteEnum;
87
import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic;
98
import io.github.hapjava.characteristics.impl.common.NameCharacteristic;
109

@@ -19,8 +18,8 @@ public SpeakerService(MuteCharacteristic muteCharacteristic) {
1918
public SpeakerService(SpeakerAccessory accessory) {
2019
this(
2120
new MuteCharacteristic(
22-
() -> accessory.isMuted().thenApply(s -> s ? MuteEnum.ON : MuteEnum.OFF),
23-
(v) -> accessory.setMute(v == MuteEnum.ON),
21+
accessory::isMuted,
22+
accessory::setMute,
2423
accessory::subscribeMuteState,
2524
accessory::unsubscribeMuteState));
2625
if (accessory instanceof AccessoryWithName) {

0 commit comments

Comments
 (0)