Skip to content

Commit 310c8d9

Browse files
committed
It is now possible to specify service name.
1 parent d6bd09b commit 310c8d9

18 files changed

+86
-35
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.beowulfe.hap.impl.characteristics.common;
22

3-
import com.beowulfe.hap.HomekitAccessory;
43
import com.beowulfe.hap.characteristics.StaticStringCharacteristic;
54

65
public class Name extends StaticStringCharacteristic {
76

8-
public Name(HomekitAccessory accessory) {
7+
public Name(String label) {
98
super("00000023-0000-1000-8000-0026BB765291",
109
"Name of the accessory",
11-
accessory.getLabel());
10+
label);
1211
}
1312
}

src/main/java/com/beowulfe/hap/impl/services/AbstractServiceImpl.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ abstract class AbstractServiceImpl implements Service {
1616
private final String type;
1717
private final List<Characteristic> characteristics = new LinkedList<>();
1818

19-
/**
20-
* This constructor has been deprecated and replaced with {@link #AbstractServiceImpl(String, HomekitAccessory)}.
21-
* Usages of this constructor will need to manually configure {@link Name} characteristic and
22-
* {@link BatteryLevelCharacteristic} if needed.
23-
*
24-
* @param type unique UUID of the service. This information can be obtained from HomeKit Accessory Simulator.
25-
*/
26-
@Deprecated
27-
public AbstractServiceImpl(String type) {
28-
this(type, null);
29-
}
30-
3119
/**
3220
* <p>Creates a new instance of this class with the specified UUID and {@link HomekitAccessory}.
3321
* Download and install <i>HomeKit Accessory Simulator</i> to discover the corresponding UUID for
@@ -39,13 +27,14 @@ public AbstractServiceImpl(String type) {
3927
*
4028
* @param type unique UUID of the service. This information can be obtained from HomeKit Accessory Simulator.
4129
* @param accessory HomeKit accessory exposed as a service.
30+
* @param serviceName name of the service. This information is usually the name of the accessory.
4231
*/
43-
public AbstractServiceImpl(String type, HomekitAccessory accessory) {
32+
public AbstractServiceImpl(String type, HomekitAccessory accessory, String serviceName) {
4433
this.type = type;
4534

4635
if (accessory != null) {
4736
// Add name characteristic
48-
addCharacteristic(new Name(accessory));
37+
addCharacteristic(new Name(serviceName));
4938

5039
// If battery operated accessory then add BatteryLevelCharacteristic
5140
if (accessory instanceof BatteryAccessory) {

src/main/java/com/beowulfe/hap/impl/services/AccessoryInformationService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
public class AccessoryInformationService extends AbstractServiceImpl {
1010

1111
public AccessoryInformationService(HomekitAccessory accessory) throws Exception {
12-
super("0000003E-0000-1000-8000-0026BB765291", accessory);
12+
this(accessory, accessory.getLabel());
13+
}
14+
15+
public AccessoryInformationService(HomekitAccessory accessory, String serviceName) throws Exception {
16+
super("0000003E-0000-1000-8000-0026BB765291", accessory, serviceName);
1317
addCharacteristic(new Manufacturer(accessory));
1418
addCharacteristic(new Model(accessory));
1519
addCharacteristic(new SerialNumber(accessory));

src/main/java/com/beowulfe/hap/impl/services/CarbonMonoxideSensorService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
public class CarbonMonoxideSensorService extends AbstractServiceImpl {
77

88
public CarbonMonoxideSensorService(CarbonMonoxideSensor carbonMonoxideSensor) {
9-
super("0000007F-0000-1000-8000-0026BB765291", carbonMonoxideSensor);
9+
this(carbonMonoxideSensor, carbonMonoxideSensor.getLabel());
10+
}
11+
12+
public CarbonMonoxideSensorService(CarbonMonoxideSensor carbonMonoxideSensor, String serviceName) {
13+
super("0000007F-0000-1000-8000-0026BB765291", carbonMonoxideSensor, serviceName);
1014
addCharacteristic(new CarbonMonoxideDetectedCharacteristic(carbonMonoxideSensor));
1115
}
1216
}

src/main/java/com/beowulfe/hap/impl/services/ContactSensorService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
public class ContactSensorService extends AbstractServiceImpl {
77

88
public ContactSensorService(ContactSensor contactSensor) {
9-
super("00000080-0000-1000-8000-0026BB765291", contactSensor);
9+
this(contactSensor, contactSensor.getLabel());
10+
}
11+
12+
public ContactSensorService(ContactSensor contactSensor, String serviceName) {
13+
super("00000080-0000-1000-8000-0026BB765291", contactSensor, serviceName);
1014
addCharacteristic(new ContactSensorStateCharacteristic(contactSensor));
1115
}
1216
}

src/main/java/com/beowulfe/hap/impl/services/FanService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
public class FanService extends AbstractServiceImpl {
99

1010
public FanService(Fan fan) {
11-
super("00000040-0000-1000-8000-0026BB765291", fan);
11+
this(fan, fan.getLabel());
12+
}
13+
14+
public FanService(Fan fan, String serviceName) {
15+
super("00000040-0000-1000-8000-0026BB765291", fan, serviceName);
1216
addCharacteristic(new PowerStateCharacteristic(
1317
() -> fan.getFanPower(),
1418
v -> fan.setFanPower(v),

src/main/java/com/beowulfe/hap/impl/services/GarageDoorService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
public class GarageDoorService extends AbstractServiceImpl {
99

1010
public GarageDoorService(GarageDoor door) {
11-
super("00000041-0000-1000-8000-0026BB765291", door);
11+
this(door, door.getLabel());
12+
}
13+
14+
public GarageDoorService(GarageDoor door, String serviceName) {
15+
super("00000041-0000-1000-8000-0026BB765291", door, serviceName);
1216
addCharacteristic(new CurrentDoorStateCharacteristic(door));
1317
addCharacteristic(new TargetDoorStateCharacteristic(door));
1418
addCharacteristic(new ObstructionDetectedCharacteristic(() -> door.getObstructionDetected(),

src/main/java/com/beowulfe/hap/impl/services/HumiditySensorService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
public class HumiditySensorService extends AbstractServiceImpl {
77

88
public HumiditySensorService(HumiditySensor sensor) {
9-
super("00000082-0000-1000-8000-0026BB765291", sensor);
9+
this(sensor, sensor.getLabel());
10+
}
11+
12+
public HumiditySensorService(HumiditySensor sensor, String serviceName) {
13+
super("00000082-0000-1000-8000-0026BB765291", sensor, serviceName);
1014
addCharacteristic(new CurrentRelativeHumidityCharacteristic(sensor));
1115
}
1216

src/main/java/com/beowulfe/hap/impl/services/LightbulbService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
public class LightbulbService extends AbstractServiceImpl {
1212

1313
public LightbulbService(Lightbulb lightbulb) {
14-
super("00000043-0000-1000-8000-0026BB765291", lightbulb);
14+
this(lightbulb, lightbulb.getLabel());
15+
}
16+
17+
public LightbulbService(Lightbulb lightbulb, String serviceName) {
18+
super("00000043-0000-1000-8000-0026BB765291", lightbulb, serviceName);
1519
addCharacteristic(new PowerStateCharacteristic(
1620
() -> lightbulb.getLightbulbPowerState(),
1721
v -> lightbulb.setLightbulbPowerState(v),

src/main/java/com/beowulfe/hap/impl/services/LockMechanismService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
public class LockMechanismService extends AbstractServiceImpl {
99

1010
public LockMechanismService(LockMechanism lock) {
11-
super("00000045-0000-1000-8000-0026BB765291", lock);
11+
this(lock, lock.getLabel());
12+
}
13+
14+
public LockMechanismService(LockMechanism lock, String serviceName) {
15+
super("00000045-0000-1000-8000-0026BB765291", lock, serviceName);
1216
addCharacteristic(new CurrentLockMechanismStateCharacteristic(lock));
1317

1418
if (lock instanceof LockableLockMechanism) {

0 commit comments

Comments
 (0)