diff --git a/src/main/java/com/beowulfe/hap/HomekitRoot.java b/src/main/java/com/beowulfe/hap/HomekitRoot.java index da96062a2..b9d954d0d 100644 --- a/src/main/java/com/beowulfe/hap/HomekitRoot.java +++ b/src/main/java/com/beowulfe/hap/HomekitRoot.java @@ -1,17 +1,16 @@ package com.beowulfe.hap; -import java.io.IOException; -import java.net.InetAddress; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.beowulfe.hap.impl.HomekitRegistry; import com.beowulfe.hap.impl.HomekitWebHandler; import com.beowulfe.hap.impl.accessories.Bridge; import com.beowulfe.hap.impl.connections.HomekitClientConnectionFactoryImpl; import com.beowulfe.hap.impl.connections.SubscriptionManager; import com.beowulfe.hap.impl.jmdns.JmdnsHomekitAdvertiser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetAddress; /** * Provides advertising and handling for Homekit accessories. This class handles the advertising of Homekit accessories and @@ -69,7 +68,7 @@ public void addAccessory(HomekitAccessory accessory) { */ void addAccessorySkipRangeCheck(HomekitAccessory accessory) { this.registry.add(accessory); - logger.info("Added accessory "+accessory.getLabel()); + logger.info("Added accessory " + accessory.getLabel()); if (started) { registry.reset(); webHandler.resetConnections(); @@ -84,6 +83,7 @@ void addAccessorySkipRangeCheck(HomekitAccessory accessory) { */ public void removeAccessory(HomekitAccessory accessory) { this.registry.remove(accessory); + logger.info("Removed accessory " + accessory.getLabel()); if (started) { registry.reset(); webHandler.resetConnections(); diff --git a/src/main/java/com/beowulfe/hap/accessories/LightSensor.java b/src/main/java/com/beowulfe/hap/accessories/LightSensor.java new file mode 100644 index 000000000..d9f7f5c65 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/accessories/LightSensor.java @@ -0,0 +1,42 @@ +package com.beowulfe.hap.accessories; + +import com.beowulfe.hap.HomekitAccessory; +import com.beowulfe.hap.HomekitCharacteristicChangeCallback; +import com.beowulfe.hap.Service; +import com.beowulfe.hap.impl.services.LightSensorService; + +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.CompletableFuture; + +/** + * A light sensor that reports current ambient light level. + * + * @author Gaston Dombiak + */ +public interface LightSensor extends HomekitAccessory { + + /** + * Retrieves the current ambient light level. + * + * @return a future that will contain the luminance level expressed in LUX. + */ + CompletableFuture getCurrentAmbientLightLevel(); + + @Override + default Collection getServices() { + return Collections.singleton(new LightSensorService(this)); + } + + /** + * Subscribes to changes in the current ambient light level. + * + * @param callback the function to call when the state changes. + */ + void subscribeCurrentAmbientLightLevel(HomekitCharacteristicChangeCallback callback); + + /** + * Unsubscribes from changes in the current ambient light level. + */ + void unsubscribeCurrentAmbientLightLevel(); +} diff --git a/src/main/java/com/beowulfe/hap/impl/HomekitRegistry.java b/src/main/java/com/beowulfe/hap/impl/HomekitRegistry.java index 74647fb20..b784cae63 100644 --- a/src/main/java/com/beowulfe/hap/impl/HomekitRegistry.java +++ b/src/main/java/com/beowulfe/hap/impl/HomekitRegistry.java @@ -1,20 +1,14 @@ package com.beowulfe.hap.impl; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.beowulfe.hap.HomekitAccessory; import com.beowulfe.hap.Service; import com.beowulfe.hap.characteristics.Characteristic; import com.beowulfe.hap.impl.services.AccessoryInformationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; public class HomekitRegistry { @@ -72,7 +66,11 @@ public List getServices(Integer aid) { } public Map getCharacteristics(Integer aid) { - return Collections.unmodifiableMap(characteristics.get(accessories.get(aid))); + Map characteristics = this.characteristics.get(accessories.get(aid)); + if (characteristics == null) { + return Collections.emptyMap(); + } + return Collections.unmodifiableMap(characteristics); } public void add(HomekitAccessory accessory) { diff --git a/src/main/java/com/beowulfe/hap/impl/characteristics/common/Name.java b/src/main/java/com/beowulfe/hap/impl/characteristics/common/Name.java index c4d9024a4..a80c1941b 100644 --- a/src/main/java/com/beowulfe/hap/impl/characteristics/common/Name.java +++ b/src/main/java/com/beowulfe/hap/impl/characteristics/common/Name.java @@ -1,13 +1,12 @@ package com.beowulfe.hap.impl.characteristics.common; -import com.beowulfe.hap.HomekitAccessory; import com.beowulfe.hap.characteristics.StaticStringCharacteristic; public class Name extends StaticStringCharacteristic { - public Name(HomekitAccessory accessory) { + public Name(String label) { super("00000023-0000-1000-8000-0026BB765291", "Name of the accessory", - accessory.getLabel()); + label); } } diff --git a/src/main/java/com/beowulfe/hap/impl/characteristics/light/AmbientLightLevelCharacteristic.java b/src/main/java/com/beowulfe/hap/impl/characteristics/light/AmbientLightLevelCharacteristic.java new file mode 100644 index 000000000..32797ca83 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/impl/characteristics/light/AmbientLightLevelCharacteristic.java @@ -0,0 +1,39 @@ +package com.beowulfe.hap.impl.characteristics.light; + +import com.beowulfe.hap.HomekitCharacteristicChangeCallback; +import com.beowulfe.hap.accessories.LightSensor; +import com.beowulfe.hap.characteristics.EventableCharacteristic; +import com.beowulfe.hap.characteristics.FloatCharacteristic; + +import java.util.concurrent.CompletableFuture; + +public class AmbientLightLevelCharacteristic extends FloatCharacteristic implements EventableCharacteristic { + + private final LightSensor lightSensor; + + public AmbientLightLevelCharacteristic(LightSensor lightSensor) { + super("0000006B-0000-1000-8000-0026BB765291", false, true, "Current ambient light level", 0.0001, 100000, + 0.0001, "lux"); + this.lightSensor = lightSensor; + } + + @Override + protected void setValue(Double value) throws Exception { + //Read Only + } + + @Override + public void subscribe(HomekitCharacteristicChangeCallback callback) { + lightSensor.subscribeCurrentAmbientLightLevel(callback); + } + + @Override + public void unsubscribe() { + lightSensor.unsubscribeCurrentAmbientLightLevel(); + } + + @Override + protected CompletableFuture getDoubleValue() { + return lightSensor.getCurrentAmbientLightLevel(); + } +} diff --git a/src/main/java/com/beowulfe/hap/impl/http/impl/AccessoryHandler.java b/src/main/java/com/beowulfe/hap/impl/http/impl/AccessoryHandler.java index fc1aa813e..2a3e3715c 100644 --- a/src/main/java/com/beowulfe/hap/impl/http/impl/AccessoryHandler.java +++ b/src/main/java/com/beowulfe/hap/impl/http/impl/AccessoryHandler.java @@ -87,11 +87,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - boolean errorLevel = true; - if (cause instanceof IOException) { - // Decide level of logging based on exception - errorLevel = !"Connection timed out".equals(cause.getMessage()); - } + boolean errorLevel = !(cause instanceof IOException); if (errorLevel) { LOGGER.error("Exception caught in web handler", cause); } else { diff --git a/src/main/java/com/beowulfe/hap/impl/http/impl/BinaryHandler.java b/src/main/java/com/beowulfe/hap/impl/http/impl/BinaryHandler.java index 225576bee..4e75f592d 100644 --- a/src/main/java/com/beowulfe/hap/impl/http/impl/BinaryHandler.java +++ b/src/main/java/com/beowulfe/hap/impl/http/impl/BinaryHandler.java @@ -52,11 +52,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - boolean errorLevel = true; - if (cause instanceof IOException) { - // Decide level of logging based on exception - errorLevel = !"Connection timed out".equals(cause.getMessage()); - } + boolean errorLevel = !(cause instanceof IOException); if (errorLevel) { logger.error("Exception in binary handler", cause); } else { diff --git a/src/main/java/com/beowulfe/hap/impl/json/CharacteristicsController.java b/src/main/java/com/beowulfe/hap/impl/json/CharacteristicsController.java index 0bbdfee47..343ddd0fa 100644 --- a/src/main/java/com/beowulfe/hap/impl/json/CharacteristicsController.java +++ b/src/main/java/com/beowulfe/hap/impl/json/CharacteristicsController.java @@ -1,18 +1,5 @@ package com.beowulfe.hap.impl.json; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; - -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonValue; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.beowulfe.hap.characteristics.Characteristic; import com.beowulfe.hap.characteristics.EventableCharacteristic; import com.beowulfe.hap.impl.HomekitRegistry; @@ -21,6 +8,13 @@ import com.beowulfe.hap.impl.http.HttpRequest; import com.beowulfe.hap.impl.http.HttpResponse; import com.beowulfe.hap.impl.responses.NotFoundResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.json.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.Map; public class CharacteristicsController { @@ -49,9 +43,19 @@ public HttpResponse get(HttpRequest request) throws Exception { int aid = Integer.parseInt(parts[0]); int iid = Integer.parseInt(parts[1]); JsonObjectBuilder characteristic = Json.createObjectBuilder(); - registry.getCharacteristics(aid).get(iid).supplyValue(characteristic); + Map characteristicMap = registry.getCharacteristics(aid); + if (!characteristicMap.isEmpty()) { + Characteristic targetCharacteristic = characteristicMap.get(iid); + if (targetCharacteristic != null) { + targetCharacteristic.supplyValue(characteristic); - characteristics.add(characteristic.add("aid", aid).add("iid", iid).build()); + characteristics.add(characteristic.add("aid", aid).add("iid", iid).build()); + } else { + logger.warn("Accessory " + aid + " does not have characteristic " + iid + "Request: " + uri); + } + } else { + logger.warn("Accessory " + aid + " has no characteristics or does not exist. Request: " + uri); + } } try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) { Json.createWriter(baos).write(Json.createObjectBuilder().add("characteristics", characteristics.build()).build()); diff --git a/src/main/java/com/beowulfe/hap/impl/services/AbstractServiceImpl.java b/src/main/java/com/beowulfe/hap/impl/services/AbstractServiceImpl.java index 64f9f690b..21bebcec8 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/AbstractServiceImpl.java +++ b/src/main/java/com/beowulfe/hap/impl/services/AbstractServiceImpl.java @@ -17,15 +17,16 @@ abstract class AbstractServiceImpl implements Service { private final List characteristics = new LinkedList<>(); /** - * This constructor has been deprecated and replaced with {@link #AbstractServiceImpl(String, HomekitAccessory)}. - * Usages of this constructor will need to manually configure {@link Name} characteristic and - * {@link BatteryLevelCharacteristic} if needed. + * This constructor has been deprecated and replaced with + * {@link #AbstractServiceImpl(String, HomekitAccessory, String)}. Usages of + * this constructor will need to manually configure {@link Name} characteristic + * and {@link BatteryLevelCharacteristic} if needed. * * @param type unique UUID of the service. This information can be obtained from HomeKit Accessory Simulator. - */ + */ @Deprecated public AbstractServiceImpl(String type) { - this(type, null); + this(type, null, null); } /** @@ -39,13 +40,14 @@ public AbstractServiceImpl(String type) { * * @param type unique UUID of the service. This information can be obtained from HomeKit Accessory Simulator. * @param accessory HomeKit accessory exposed as a service. + * @param serviceName name of the service. This information is usually the name of the accessory. */ - public AbstractServiceImpl(String type, HomekitAccessory accessory) { + public AbstractServiceImpl(String type, HomekitAccessory accessory, String serviceName) { this.type = type; if (accessory != null) { // Add name characteristic - addCharacteristic(new Name(accessory)); + addCharacteristic(new Name(serviceName)); // If battery operated accessory then add BatteryLevelCharacteristic if (accessory instanceof BatteryAccessory) { diff --git a/src/main/java/com/beowulfe/hap/impl/services/AccessoryInformationService.java b/src/main/java/com/beowulfe/hap/impl/services/AccessoryInformationService.java index 46b6b6d43..b821f769d 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/AccessoryInformationService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/AccessoryInformationService.java @@ -9,7 +9,11 @@ public class AccessoryInformationService extends AbstractServiceImpl { public AccessoryInformationService(HomekitAccessory accessory) throws Exception { - super("0000003E-0000-1000-8000-0026BB765291", accessory); + this(accessory, accessory.getLabel()); + } + + public AccessoryInformationService(HomekitAccessory accessory, String serviceName) throws Exception { + super("0000003E-0000-1000-8000-0026BB765291", accessory, serviceName); addCharacteristic(new Manufacturer(accessory)); addCharacteristic(new Model(accessory)); addCharacteristic(new SerialNumber(accessory)); diff --git a/src/main/java/com/beowulfe/hap/impl/services/CarbonMonoxideSensorService.java b/src/main/java/com/beowulfe/hap/impl/services/CarbonMonoxideSensorService.java index d1b65fe99..1017a4555 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/CarbonMonoxideSensorService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/CarbonMonoxideSensorService.java @@ -6,7 +6,11 @@ public class CarbonMonoxideSensorService extends AbstractServiceImpl { public CarbonMonoxideSensorService(CarbonMonoxideSensor carbonMonoxideSensor) { - super("0000007F-0000-1000-8000-0026BB765291", carbonMonoxideSensor); + this(carbonMonoxideSensor, carbonMonoxideSensor.getLabel()); + } + + public CarbonMonoxideSensorService(CarbonMonoxideSensor carbonMonoxideSensor, String serviceName) { + super("0000007F-0000-1000-8000-0026BB765291", carbonMonoxideSensor, serviceName); addCharacteristic(new CarbonMonoxideDetectedCharacteristic(carbonMonoxideSensor)); } } diff --git a/src/main/java/com/beowulfe/hap/impl/services/ContactSensorService.java b/src/main/java/com/beowulfe/hap/impl/services/ContactSensorService.java index 25c8bf36c..5f7ff17fa 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/ContactSensorService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/ContactSensorService.java @@ -6,7 +6,11 @@ public class ContactSensorService extends AbstractServiceImpl { public ContactSensorService(ContactSensor contactSensor) { - super("00000080-0000-1000-8000-0026BB765291", contactSensor); + this(contactSensor, contactSensor.getLabel()); + } + + public ContactSensorService(ContactSensor contactSensor, String serviceName) { + super("00000080-0000-1000-8000-0026BB765291", contactSensor, serviceName); addCharacteristic(new ContactSensorStateCharacteristic(contactSensor)); } } diff --git a/src/main/java/com/beowulfe/hap/impl/services/FanService.java b/src/main/java/com/beowulfe/hap/impl/services/FanService.java index 8c64262d8..feb75c1c4 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/FanService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/FanService.java @@ -8,7 +8,11 @@ public class FanService extends AbstractServiceImpl { public FanService(Fan fan) { - super("00000040-0000-1000-8000-0026BB765291", fan); + this(fan, fan.getLabel()); + } + + public FanService(Fan fan, String serviceName) { + super("00000040-0000-1000-8000-0026BB765291", fan, serviceName); addCharacteristic(new PowerStateCharacteristic( () -> fan.getFanPower(), v -> fan.setFanPower(v), diff --git a/src/main/java/com/beowulfe/hap/impl/services/GarageDoorService.java b/src/main/java/com/beowulfe/hap/impl/services/GarageDoorService.java index 7f67926f6..6469a2387 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/GarageDoorService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/GarageDoorService.java @@ -8,7 +8,11 @@ public class GarageDoorService extends AbstractServiceImpl { public GarageDoorService(GarageDoor door) { - super("00000041-0000-1000-8000-0026BB765291", door); + this(door, door.getLabel()); + } + + public GarageDoorService(GarageDoor door, String serviceName) { + super("00000041-0000-1000-8000-0026BB765291", door, serviceName); addCharacteristic(new CurrentDoorStateCharacteristic(door)); addCharacteristic(new TargetDoorStateCharacteristic(door)); addCharacteristic(new ObstructionDetectedCharacteristic(() -> door.getObstructionDetected(), diff --git a/src/main/java/com/beowulfe/hap/impl/services/HumiditySensorService.java b/src/main/java/com/beowulfe/hap/impl/services/HumiditySensorService.java index f38c10a4a..23b3c354e 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/HumiditySensorService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/HumiditySensorService.java @@ -6,7 +6,11 @@ public class HumiditySensorService extends AbstractServiceImpl { public HumiditySensorService(HumiditySensor sensor) { - super("00000082-0000-1000-8000-0026BB765291", sensor); + this(sensor, sensor.getLabel()); + } + + public HumiditySensorService(HumiditySensor sensor, String serviceName) { + super("00000082-0000-1000-8000-0026BB765291", sensor, serviceName); addCharacteristic(new CurrentRelativeHumidityCharacteristic(sensor)); } diff --git a/src/main/java/com/beowulfe/hap/impl/services/LightSensorService.java b/src/main/java/com/beowulfe/hap/impl/services/LightSensorService.java new file mode 100644 index 000000000..b5c1610a3 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/impl/services/LightSensorService.java @@ -0,0 +1,16 @@ +package com.beowulfe.hap.impl.services; + +import com.beowulfe.hap.accessories.LightSensor; +import com.beowulfe.hap.impl.characteristics.light.AmbientLightLevelCharacteristic; + +public class LightSensorService extends AbstractServiceImpl { + + public LightSensorService(LightSensor lightSensor) { + this(lightSensor, lightSensor.getLabel()); + } + + public LightSensorService(LightSensor lightSensor, String serviceName) { + super("00000084-0000-1000-8000-0026BB765291", lightSensor, serviceName); + addCharacteristic(new AmbientLightLevelCharacteristic(lightSensor)); + } +} diff --git a/src/main/java/com/beowulfe/hap/impl/services/LightbulbService.java b/src/main/java/com/beowulfe/hap/impl/services/LightbulbService.java index e7dfd625f..604d7176d 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/LightbulbService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/LightbulbService.java @@ -11,7 +11,11 @@ public class LightbulbService extends AbstractServiceImpl { public LightbulbService(Lightbulb lightbulb) { - super("00000043-0000-1000-8000-0026BB765291", lightbulb); + this(lightbulb, lightbulb.getLabel()); + } + + public LightbulbService(Lightbulb lightbulb, String serviceName) { + super("00000043-0000-1000-8000-0026BB765291", lightbulb, serviceName); addCharacteristic(new PowerStateCharacteristic( () -> lightbulb.getLightbulbPowerState(), v -> lightbulb.setLightbulbPowerState(v), diff --git a/src/main/java/com/beowulfe/hap/impl/services/LockMechanismService.java b/src/main/java/com/beowulfe/hap/impl/services/LockMechanismService.java index acc0eaf9c..e2817c1dc 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/LockMechanismService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/LockMechanismService.java @@ -8,7 +8,11 @@ public class LockMechanismService extends AbstractServiceImpl { public LockMechanismService(LockMechanism lock) { - super("00000045-0000-1000-8000-0026BB765291", lock); + this(lock, lock.getLabel()); + } + + public LockMechanismService(LockMechanism lock, String serviceName) { + super("00000045-0000-1000-8000-0026BB765291", lock, serviceName); addCharacteristic(new CurrentLockMechanismStateCharacteristic(lock)); if (lock instanceof LockableLockMechanism) { diff --git a/src/main/java/com/beowulfe/hap/impl/services/MotionSensorService.java b/src/main/java/com/beowulfe/hap/impl/services/MotionSensorService.java index ba7e198b3..ed2064f4d 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/MotionSensorService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/MotionSensorService.java @@ -6,7 +6,11 @@ public class MotionSensorService extends AbstractServiceImpl { public MotionSensorService(MotionSensor motionSensor) { - super("00000085-0000-1000-8000-0026BB765291", motionSensor); + this(motionSensor, motionSensor.getLabel()); + } + + public MotionSensorService(MotionSensor motionSensor, String serviceName) { + super("00000085-0000-1000-8000-0026BB765291", motionSensor, serviceName); addCharacteristic(new MotionDetectedStateCharacteristic(motionSensor)); } } diff --git a/src/main/java/com/beowulfe/hap/impl/services/OutletService.java b/src/main/java/com/beowulfe/hap/impl/services/OutletService.java index 52b19e593..d7d5a68de 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/OutletService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/OutletService.java @@ -7,7 +7,11 @@ public class OutletService extends AbstractServiceImpl { public OutletService(Outlet outlet) { - super("00000047-0000-1000-8000-0026BB765291", outlet); + this(outlet, outlet.getLabel()); + } + + public OutletService(Outlet outlet, String serviceName) { + super("00000047-0000-1000-8000-0026BB765291", outlet, serviceName); addCharacteristic(new PowerStateCharacteristic( () -> outlet.getPowerState(), v -> outlet.setPowerState(v), diff --git a/src/main/java/com/beowulfe/hap/impl/services/SecuritySystemService.java b/src/main/java/com/beowulfe/hap/impl/services/SecuritySystemService.java index 5fe1da6ff..6d6f9a6bf 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/SecuritySystemService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/SecuritySystemService.java @@ -8,7 +8,11 @@ public class SecuritySystemService extends AbstractServiceImpl { public SecuritySystemService(SecuritySystem securitySystem) { - super("0000007E-0000-1000-8000-0026BB765291", securitySystem); + this(securitySystem, securitySystem.getLabel()); + } + + public SecuritySystemService(SecuritySystem securitySystem, String serviceName) { + super("0000007E-0000-1000-8000-0026BB765291", securitySystem, serviceName); addCharacteristic(new CurrentSecuritySystemStateCharacteristic(securitySystem)); addCharacteristic(new TargetSecuritySystemStateCharacteristic(securitySystem)); addCharacteristic(new SecuritySystemAlarmTypeCharacteristic(securitySystem)); diff --git a/src/main/java/com/beowulfe/hap/impl/services/SmokeSensorService.java b/src/main/java/com/beowulfe/hap/impl/services/SmokeSensorService.java index 16026a2b2..2f5c4e993 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/SmokeSensorService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/SmokeSensorService.java @@ -6,7 +6,11 @@ public class SmokeSensorService extends AbstractServiceImpl { public SmokeSensorService(SmokeSensor smokeSensor) { - super("00000087-0000-1000-8000-0026BB765291", smokeSensor); + this(smokeSensor, smokeSensor.getLabel()); + } + + public SmokeSensorService(SmokeSensor smokeSensor, String serviceName) { + super("00000087-0000-1000-8000-0026BB765291", smokeSensor, serviceName); addCharacteristic(new SmokeDetectedCharacteristic(smokeSensor)); } } diff --git a/src/main/java/com/beowulfe/hap/impl/services/SwitchService.java b/src/main/java/com/beowulfe/hap/impl/services/SwitchService.java index 864b94745..8bdda8989 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/SwitchService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/SwitchService.java @@ -6,7 +6,11 @@ public class SwitchService extends AbstractServiceImpl { public SwitchService(Switch switchAccessory) { - super("00000049-0000-1000-8000-0026BB765291", switchAccessory); + this(switchAccessory, switchAccessory.getLabel()); + } + + public SwitchService(Switch switchAccessory, String serviceName) { + super("00000049-0000-1000-8000-0026BB765291", switchAccessory, serviceName); addCharacteristic(new PowerStateCharacteristic( () -> switchAccessory.getSwitchState(), v -> switchAccessory.setSwitchState(v), diff --git a/src/main/java/com/beowulfe/hap/impl/services/TemperatureSensorService.java b/src/main/java/com/beowulfe/hap/impl/services/TemperatureSensorService.java index 8c5684bda..b29bae501 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/TemperatureSensorService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/TemperatureSensorService.java @@ -6,7 +6,11 @@ public class TemperatureSensorService extends AbstractServiceImpl { public TemperatureSensorService(TemperatureSensor sensor) { - super("0000008A-0000-1000-8000-0026BB765291", sensor); + this(sensor, sensor.getLabel()); + } + + public TemperatureSensorService(TemperatureSensor sensor, String serviceName) { + super("0000008A-0000-1000-8000-0026BB765291", sensor, serviceName); addCharacteristic(new CurrentTemperatureCharacteristic(sensor)); } diff --git a/src/main/java/com/beowulfe/hap/impl/services/ThermostatService.java b/src/main/java/com/beowulfe/hap/impl/services/ThermostatService.java index 55a18773b..564a28aeb 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/ThermostatService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/ThermostatService.java @@ -8,7 +8,11 @@ public class ThermostatService extends AbstractServiceImpl { public ThermostatService(BasicThermostat thermostat) { - super("0000004A-0000-1000-8000-0026BB765291", thermostat); + this(thermostat, thermostat.getLabel()); + } + + public ThermostatService(BasicThermostat thermostat, String serviceName) { + super("0000004A-0000-1000-8000-0026BB765291", thermostat, serviceName); addCharacteristic(new CurrentHeatingCoolingModeCharacteristic(thermostat)); addCharacteristic(new CurrentTemperatureCharacteristic(thermostat)); addCharacteristic(new TargetHeatingCoolingModeCharacteristic(thermostat)); diff --git a/src/main/java/com/beowulfe/hap/impl/services/WindowCoveringService.java b/src/main/java/com/beowulfe/hap/impl/services/WindowCoveringService.java index d9e4b737b..18d6499ba 100644 --- a/src/main/java/com/beowulfe/hap/impl/services/WindowCoveringService.java +++ b/src/main/java/com/beowulfe/hap/impl/services/WindowCoveringService.java @@ -9,7 +9,11 @@ public class WindowCoveringService extends AbstractServiceImpl { public WindowCoveringService(WindowCovering windowCovering) { - super("0000008C-0000-1000-8000-0026BB765291", windowCovering); + this(windowCovering, windowCovering.getLabel()); + } + + public WindowCoveringService(WindowCovering windowCovering, String serviceName) { + super("0000008C-0000-1000-8000-0026BB765291", windowCovering, serviceName); addCharacteristic(new CurrentPositionCharacteristic(windowCovering)); addCharacteristic(new HoldPositionCharacteristic(windowCovering)); addCharacteristic(new PositionStateCharacteristic(windowCovering)); @@ -17,7 +21,7 @@ public WindowCoveringService(WindowCovering windowCovering) { addCharacteristic(new ObstructionDetectedCharacteristic(() -> windowCovering.getObstructionDetected(), c -> windowCovering.subscribeObstructionDetected(c), () -> windowCovering.unsubscribeObstructionDetected())); - + if (windowCovering instanceof HorizontalTiltingWindowCovering) { addCharacteristic(new CurrentHorizontalTiltAngleCharacteristic( (HorizontalTiltingWindowCovering) windowCovering)); @@ -31,5 +35,4 @@ public WindowCoveringService(WindowCovering windowCovering) { (VerticalTiltingWindowCovering) windowCovering)); } } - }