diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/AbstractHomekitAccessoryImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/AbstractHomekitAccessoryImpl.java index 228de13211e..36836a01b6c 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/AbstractHomekitAccessoryImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/AbstractHomekitAccessoryImpl.java @@ -228,6 +228,25 @@ public abstract class AbstractHomekitAccessoryImpl implements HomekitAccessory { return this.services; } + public void addService(Service service) { + services.add(service); + + var serviceClass = service.getClass(); + rawCharacteristics.values().forEach(characteristic -> { + // belongs on the accessory information service + if (characteristic.getClass() == NameCharacteristic.class) { + return; + } + try { + // if the service supports adding this characteristic as optional, add it! + serviceClass.getMethod("addOptionalCharacteristic", characteristic.getClass()).invoke(service, + characteristic); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + // the service doesn't support this optional characteristic; ignore it + } + }); + } + protected HomekitAccessoryUpdater getUpdater() { return updater; } diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAirQualitySensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAirQualitySensorImpl.java index 36607ffd154..73b0646d29c 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAirQualitySensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAirQualitySensorImpl.java @@ -45,7 +45,7 @@ public class HomekitAirQualitySensorImpl extends AbstractHomekitAccessoryImpl im @Override public void init() throws HomekitException { super.init(); - getServices().add(new AirQualityService(this)); + addService(new AirQualityService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java index a8b33ca0f8c..5e4066894a6 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java @@ -45,7 +45,7 @@ class HomekitBasicFanImpl extends AbstractHomekitAccessoryImpl implements BasicF @Override public void init() throws HomekitException { super.init(); - this.getServices().add(new BasicFanService(this)); + addService(new BasicFanService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBatteryImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBatteryImpl.java index 4c9529fd3ce..3ca666afd3d 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBatteryImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBatteryImpl.java @@ -62,7 +62,7 @@ public class HomekitBatteryImpl extends AbstractHomekitAccessoryImpl implements @Override public void init() throws HomekitException { super.init(); - getServices().add(new BatteryService(this)); + addService(new BatteryService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonDioxideSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonDioxideSensorImpl.java index 44b18ad4c21..adfe18314ec 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonDioxideSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonDioxideSensorImpl.java @@ -46,7 +46,7 @@ public class HomekitCarbonDioxideSensorImpl extends AbstractHomekitAccessoryImpl @Override public void init() throws HomekitException { super.init(); - getServices().add(new CarbonDioxideSensorService(this)); + addService(new CarbonDioxideSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonMonoxideSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonMonoxideSensorImpl.java index f1235a4c0fe..29693a6baf8 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonMonoxideSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCarbonMonoxideSensorImpl.java @@ -46,7 +46,7 @@ public class HomekitCarbonMonoxideSensorImpl extends AbstractHomekitAccessoryImp @Override public void init() throws HomekitException { super.init(); - getServices().add(new CarbonMonoxideSensorService(this)); + addService(new CarbonMonoxideSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitContactSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitContactSensorImpl.java index 3ff7c9a1916..bb6cc5f6148 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitContactSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitContactSensorImpl.java @@ -44,7 +44,7 @@ public class HomekitContactSensorImpl extends AbstractHomekitAccessoryImpl imple @Override public void init() throws HomekitException { super.init(); - getServices().add(new ContactSensorService(this)); + addService(new ContactSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorImpl.java index 021663004ef..7e51d3f7f9f 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorImpl.java @@ -41,7 +41,7 @@ public class HomekitDoorImpl extends AbstractHomekitPositionAccessoryImpl implem @Override public void init() throws HomekitException { super.init(); - getServices().add(new DoorService(this)); + addService(new DoorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFanImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFanImpl.java index 8fadfe9d734..416fa6e31be 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFanImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFanImpl.java @@ -43,7 +43,7 @@ class HomekitFanImpl extends AbstractHomekitAccessoryImpl implements FanAccessor @Override public void init() throws HomekitException { super.init(); - this.getServices().add(new FanService(this)); + addService(new FanService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFaucetImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFaucetImpl.java index beeab761801..a2fb8248422 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFaucetImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFaucetImpl.java @@ -43,7 +43,7 @@ class HomekitFaucetImpl extends AbstractHomekitAccessoryImpl implements FaucetAc @Override public void init() throws HomekitException { super.init(); - this.getServices().add(new FaucetService(this)); + addService(new FaucetService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFilterMaintenanceImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFilterMaintenanceImpl.java index 5918da1dca9..792922ee5ff 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFilterMaintenanceImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitFilterMaintenanceImpl.java @@ -45,7 +45,7 @@ public class HomekitFilterMaintenanceImpl extends AbstractHomekitAccessoryImpl i @Override public void init() throws HomekitException { super.init(); - getServices().add(new FilterMaintenanceService(this)); + addService(new FilterMaintenanceService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitGarageDoorOpenerImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitGarageDoorOpenerImpl.java index 4284cbccd38..b217f3e1f99 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitGarageDoorOpenerImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitGarageDoorOpenerImpl.java @@ -55,7 +55,7 @@ public class HomekitGarageDoorOpenerImpl extends AbstractHomekitAccessoryImpl im @Override public void init() throws HomekitException { super.init(); - getServices().add(new GarageDoorOpenerService(this)); + addService(new GarageDoorOpenerService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHeaterCoolerImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHeaterCoolerImpl.java index 840e6ed0bd5..c85286ce68d 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHeaterCoolerImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHeaterCoolerImpl.java @@ -73,10 +73,10 @@ public class HomekitHeaterCoolerImpl extends AbstractHomekitAccessoryImpl implem public void init() throws HomekitException { super.init(); final HeaterCoolerService service = new HeaterCoolerService(this); + addService(service); service.addOptionalCharacteristic(new TemperatureDisplayUnitCharacteristic(this::getTemperatureDisplayUnit, this::setTemperatureDisplayUnit, this::subscribeTemperatureDisplayUnit, this::unsubscribeTemperatureDisplayUnit)); - getServices().add(service); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHumiditySensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHumiditySensorImpl.java index abd24f9bd31..cb3c38e6c3d 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHumiditySensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitHumiditySensorImpl.java @@ -43,7 +43,7 @@ public class HomekitHumiditySensorImpl extends AbstractHomekitAccessoryImpl impl @Override public void init() throws HomekitException { super.init(); - getServices().add(new HumiditySensorService(this)); + addService(new HumiditySensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitInputSourceImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitInputSourceImpl.java index e3895545c82..dcca031e0c9 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitInputSourceImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitInputSourceImpl.java @@ -28,10 +28,8 @@ import io.github.hapjava.characteristics.impl.common.IsConfiguredCharacteristic; import io.github.hapjava.characteristics.impl.common.IsConfiguredEnum; import io.github.hapjava.characteristics.impl.inputsource.CurrentVisibilityStateCharacteristic; import io.github.hapjava.characteristics.impl.inputsource.CurrentVisibilityStateEnum; -import io.github.hapjava.characteristics.impl.inputsource.InputDeviceTypeCharacteristic; import io.github.hapjava.characteristics.impl.inputsource.InputSourceTypeCharacteristic; import io.github.hapjava.characteristics.impl.inputsource.InputSourceTypeEnum; -import io.github.hapjava.characteristics.impl.inputsource.TargetVisibilityStateCharacteristic; import io.github.hapjava.services.impl.InputSourceService; /** @@ -78,18 +76,16 @@ public class HomekitInputSourceImpl extends AbstractHomekitAccessoryImpl { () -> CompletableFuture.completedFuture(CurrentVisibilityStateEnum.SHOWN), v -> { }, () -> { })); - var identifierCharacteristic = getCharacteristic(IdentifierCharacteristic.class) - .orElseGet(() -> new IdentifierCharacteristic(() -> CompletableFuture.completedFuture(1))); var service = new InputSourceService(configuredNameCharacteristic, inputSourceTypeCharacteristic, isConfiguredCharacteristic, currentVisibilityStateCharacteristic); - service.addOptionalCharacteristic(identifierCharacteristic); - getCharacteristic(InputDeviceTypeCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - getCharacteristic(TargetVisibilityStateCharacteristic.class) - .ifPresent(c -> service.addOptionalCharacteristic(c)); + var identifierCharacteristic = getCharacteristic(IdentifierCharacteristic.class); + if (identifierCharacteristic.isEmpty()) { + service.addOptionalCharacteristic(new IdentifierCharacteristic(() -> CompletableFuture.completedFuture(1))); + } - getServices().add(service); + addService(service); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitIrrigationSystemImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitIrrigationSystemImpl.java index efc31cf0e4d..b24b762ad63 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitIrrigationSystemImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitIrrigationSystemImpl.java @@ -55,7 +55,7 @@ public class HomekitIrrigationSystemImpl extends AbstractHomekitAccessoryImpl im inUseMapping = createMapping(HomekitCharacteristicType.INUSE_STATUS, InUseEnum.class); programModeMap = HomekitCharacteristicFactory .createMapping(getCharacteristic(HomekitCharacteristicType.PROGRAM_MODE).get(), ProgramModeEnum.class); - getServices().add(new IrrigationSystemService(this)); + addService(new IrrigationSystemService(this)); } @Override @@ -73,7 +73,7 @@ public class HomekitIrrigationSystemImpl extends AbstractHomekitAccessoryImpl im final var finalEnum = serviceLabelEnum; var serviceLabelNamespace = getCharacteristic(ServiceLabelNamespaceCharacteristic.class).orElseGet( () -> new ServiceLabelNamespaceCharacteristic(() -> CompletableFuture.completedFuture(finalEnum))); - getServices().add(new ServiceLabelService(serviceLabelNamespace)); + addService(new ServiceLabelService(serviceLabelNamespace)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLeakSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLeakSensorImpl.java index 577fa9b577f..5f59cd76141 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLeakSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLeakSensorImpl.java @@ -44,7 +44,7 @@ public class HomekitLeakSensorImpl extends AbstractHomekitAccessoryImpl implemen @Override public void init() throws HomekitException { super.init(); - getServices().add(new LeakSensorService(this)); + addService(new LeakSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java index 491733e78d3..19397072582 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java @@ -46,7 +46,7 @@ public class HomekitLightSensorImpl extends AbstractHomekitAccessoryImpl impleme @Override public void init() throws HomekitException { super.init(); - getServices().add(new LightSensorService(this)); + addService(new LightSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightbulbImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightbulbImpl.java index b769c9c018a..b1c63c1383b 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightbulbImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightbulbImpl.java @@ -44,7 +44,7 @@ class HomekitLightbulbImpl extends AbstractHomekitAccessoryImpl implements Light @Override public void init() throws HomekitException { super.init(); - getServices().add(new LightbulbService(this)); + addService(new LightbulbService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLockImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLockImpl.java index 80736a73c21..bec2026480e 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLockImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLockImpl.java @@ -49,7 +49,7 @@ public class HomekitLockImpl extends AbstractHomekitAccessoryImpl implements Loc @Override public void init() throws HomekitException { super.init(); - getServices().add(new LockMechanismService(this)); + addService(new LockMechanismService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMicrophoneImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMicrophoneImpl.java index 81c9ce05dab..d1bcfb65c94 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMicrophoneImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMicrophoneImpl.java @@ -42,7 +42,7 @@ public class HomekitMicrophoneImpl extends AbstractHomekitAccessoryImpl implemen @Override public void init() throws HomekitException { super.init(); - getServices().add(new MicrophoneService(this)); + addService(new MicrophoneService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMotionSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMotionSensorImpl.java index 174bb81866a..9503c29c097 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMotionSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMotionSensorImpl.java @@ -41,7 +41,7 @@ public class HomekitMotionSensorImpl extends AbstractHomekitAccessoryImpl implem @Override public void init() throws HomekitException { super.init(); - getServices().add(new MotionSensorService(this)); + addService(new MotionSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOccupancySensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOccupancySensorImpl.java index 59d3aebbcbb..ae821158b97 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOccupancySensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOccupancySensorImpl.java @@ -44,7 +44,7 @@ public class HomekitOccupancySensorImpl extends AbstractHomekitAccessoryImpl imp @Override public void init() throws HomekitException { super.init(); - getServices().add(new OccupancySensorService(this)); + addService(new OccupancySensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOutletImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOutletImpl.java index b7d32a3b014..4e8dc1c9212 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOutletImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitOutletImpl.java @@ -43,7 +43,7 @@ public class HomekitOutletImpl extends AbstractHomekitAccessoryImpl implements O @Override public void init() throws HomekitException { super.init(); - getServices().add(new OutletService(this)); + addService(new OutletService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSecuritySystemImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSecuritySystemImpl.java index 7b21582cdea..23d83b1e84d 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSecuritySystemImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSecuritySystemImpl.java @@ -59,7 +59,7 @@ public class HomekitSecuritySystemImpl extends AbstractHomekitAccessoryImpl impl @Override public void init() throws HomekitException { super.init(); - getServices().add(new SecuritySystemService(this)); + addService(new SecuritySystemService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSlatImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSlatImpl.java index f39a17b2c59..6d5c3790396 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSlatImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSlatImpl.java @@ -49,7 +49,7 @@ public class HomekitSlatImpl extends AbstractHomekitAccessoryImpl implements Sla @Override public void init() throws HomekitException { super.init(); - getServices().add(new SlatService(this)); + addService(new SlatService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmartSpeakerImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmartSpeakerImpl.java index ae1704f099b..8cbbf588e2f 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmartSpeakerImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmartSpeakerImpl.java @@ -48,7 +48,7 @@ public class HomekitSmartSpeakerImpl extends AbstractHomekitAccessoryImpl implem @Override public void init() throws HomekitException { super.init(); - getServices().add(new SmartSpeakerService(this)); + addService(new SmartSpeakerService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmokeSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmokeSensorImpl.java index bf4a0661c0a..e1295e6e13e 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmokeSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSmokeSensorImpl.java @@ -44,7 +44,7 @@ public class HomekitSmokeSensorImpl extends AbstractHomekitAccessoryImpl impleme @Override public void init() throws HomekitException { super.init(); - this.getServices().add(new SmokeSensorService(this)); + addService(new SmokeSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSpeakerImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSpeakerImpl.java index 98732de9016..2a0d9eb95c5 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSpeakerImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSpeakerImpl.java @@ -42,7 +42,7 @@ public class HomekitSpeakerImpl extends AbstractHomekitAccessoryImpl implements @Override public void init() throws HomekitException { super.init(); - getServices().add(new SpeakerService(this)); + addService(new SpeakerService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSwitchImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSwitchImpl.java index 9e7ab5d157f..6dbc1f68084 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSwitchImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitSwitchImpl.java @@ -43,7 +43,7 @@ public class HomekitSwitchImpl extends AbstractHomekitAccessoryImpl implements S @Override public void init() throws HomekitException { super.init(); - getServices().add(new SwitchService(this)); + addService(new SwitchService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionImpl.java index 10ce819421d..433a36f85e8 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionImpl.java @@ -24,15 +24,9 @@ import org.openhab.io.homekit.internal.HomekitTaggedItem; import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; import io.github.hapjava.characteristics.impl.common.ActiveIdentifierCharacteristic; import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic; -import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic; -import io.github.hapjava.characteristics.impl.television.ClosedCaptionsCharacteristic; -import io.github.hapjava.characteristics.impl.television.CurrentMediaStateCharacteristic; -import io.github.hapjava.characteristics.impl.television.PictureModeCharacteristic; -import io.github.hapjava.characteristics.impl.television.PowerModeCharacteristic; import io.github.hapjava.characteristics.impl.television.RemoteKeyCharacteristic; import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeCharacteristic; import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeEnum; -import io.github.hapjava.characteristics.impl.television.TargetMediaStateCharacteristic; import io.github.hapjava.services.impl.TelevisionService; /** @@ -81,13 +75,6 @@ public class HomekitTelevisionImpl extends AbstractHomekitAccessoryImpl { activeIdentifierCharacteristic, configuredNameCharacteristic, remoteKeyCharacteristic, sleepDiscoveryModeCharacteristic); - getCharacteristic(BrightnessCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - getCharacteristic(PowerModeCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - getCharacteristic(ClosedCaptionsCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - getCharacteristic(CurrentMediaStateCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - getCharacteristic(TargetMediaStateCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - getCharacteristic(PictureModeCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - - getServices().add(service); + addService(service); } } diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionSpeakerImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionSpeakerImpl.java index 5df1bb3463c..f3cbd23645f 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionSpeakerImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTelevisionSpeakerImpl.java @@ -13,7 +13,6 @@ package org.openhab.io.homekit.internal.accessories; import java.util.List; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -25,7 +24,6 @@ import org.openhab.io.homekit.internal.HomekitTaggedItem; import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic; import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeControlTypeCharacteristic; import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeControlTypeEnum; import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeSelectorCharacteristic; @@ -61,6 +59,8 @@ public class HomekitTelevisionSpeakerImpl extends AbstractHomekitAccessoryImpl { var volumeCharacteristic = getCharacteristic(VolumeCharacteristic.class); var volumeSelectorCharacteristic = getCharacteristic(VolumeSelectorCharacteristic.class); + var service = new TelevisionSpeakerService(muteCharacteristic); + if (volumeControlTypeCharacteristic.isEmpty()) { VolumeControlTypeEnum type; if (volumeCharacteristic.isPresent()) { @@ -70,18 +70,12 @@ public class HomekitTelevisionSpeakerImpl extends AbstractHomekitAccessoryImpl { } else { type = VolumeControlTypeEnum.NONE; } - volumeControlTypeCharacteristic = Optional - .of(new VolumeControlTypeCharacteristic(() -> CompletableFuture.completedFuture(type), v -> { + service.addOptionalCharacteristic( + new VolumeControlTypeCharacteristic(() -> CompletableFuture.completedFuture(type), v -> { }, () -> { })); } - var service = new TelevisionSpeakerService(muteCharacteristic); - - getCharacteristic(ActiveCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c)); - volumeCharacteristic.ifPresent(c -> service.addOptionalCharacteristic(c)); - service.addOptionalCharacteristic(volumeControlTypeCharacteristic.get()); - - getServices().add(service); + addService(service); } } diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTemperatureSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTemperatureSensorImpl.java index bf024b57e2b..84e0da9428f 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTemperatureSensorImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitTemperatureSensorImpl.java @@ -44,7 +44,7 @@ class HomekitTemperatureSensorImpl extends AbstractHomekitAccessoryImpl implemen @Override public void init() throws HomekitException { super.init(); - getServices().add(new TemperatureSensorService(this)); + addService(new TemperatureSensorService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java index c851570316e..fab0d0ce5a2 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java @@ -73,7 +73,7 @@ class HomekitThermostatImpl extends AbstractHomekitAccessoryImpl implements Ther @Override public void init() throws HomekitException { super.init(); - this.getServices().add(new ThermostatService(this)); + addService(new ThermostatService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitValveImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitValveImpl.java index 479f9a12961..aede260fa6a 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitValveImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitValveImpl.java @@ -87,8 +87,11 @@ public class HomekitValveImpl extends AbstractHomekitAccessoryImpl implements Va public void init() throws HomekitException { super.init(); ValveService service = new ValveService(this); - getServices().add(service); - if (homekitTimer) { + addService(service); + + var remainingDurationCharacteristic = getCharacteristic(RemainingDurationCharacteristic.class); + + if (homekitTimer && remainingDurationCharacteristic.isEmpty()) { addRemainingDurationCharacteristic(getRootAccessory(), getUpdater(), service); } String valveTypeConfig = getAccessoryConfiguration(CONFIG_VALVE_TYPE, "GENERIC"); diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowCoveringImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowCoveringImpl.java index dfe1b6ac519..b4a3440819c 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowCoveringImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowCoveringImpl.java @@ -41,7 +41,7 @@ public class HomekitWindowCoveringImpl extends AbstractHomekitPositionAccessoryI @Override public void init() throws HomekitException { super.init(); - getServices().add(new WindowCoveringService(this)); + addService(new WindowCoveringService(this)); } @Override diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowImpl.java index 21bf0e44e7e..87c8d360b45 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitWindowImpl.java @@ -41,7 +41,7 @@ public class HomekitWindowImpl extends AbstractHomekitPositionAccessoryImpl impl @Override public void init() throws HomekitException { super.init(); - getServices().add(new WindowService(this)); + addService(new WindowService(this)); } @Override