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;
}
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new AirQualityService(this));
+ addService(new AirQualityService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- this.getServices().add(new BasicFanService(this));
+ addService(new BasicFanService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new BatteryService(this));
+ addService(new BatteryService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new CarbonDioxideSensorService(this));
+ addService(new CarbonDioxideSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new CarbonMonoxideSensorService(this));
+ addService(new CarbonMonoxideSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new ContactSensorService(this));
+ addService(new ContactSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new DoorService(this));
+ addService(new DoorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- this.getServices().add(new FanService(this));
+ addService(new FanService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- this.getServices().add(new FaucetService(this));
+ addService(new FaucetService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new FilterMaintenanceService(this));
+ addService(new FilterMaintenanceService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new GarageDoorOpenerService(this));
+ addService(new GarageDoorOpenerService(this));
}
@Override
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
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new HumiditySensorService(this));
+ addService(new HumiditySensorService(this));
}
@Override
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;
/**
() -> 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
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
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
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new LeakSensorService(this));
+ addService(new LeakSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new LightSensorService(this));
+ addService(new LightSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new LightbulbService(this));
+ addService(new LightbulbService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new LockMechanismService(this));
+ addService(new LockMechanismService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new MicrophoneService(this));
+ addService(new MicrophoneService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new MotionSensorService(this));
+ addService(new MotionSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new OccupancySensorService(this));
+ addService(new OccupancySensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new OutletService(this));
+ addService(new OutletService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new SecuritySystemService(this));
+ addService(new SecuritySystemService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new SlatService(this));
+ addService(new SlatService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new SmartSpeakerService(this));
+ addService(new SmartSpeakerService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- this.getServices().add(new SmokeSensorService(this));
+ addService(new SmokeSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new SpeakerService(this));
+ addService(new SpeakerService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new SwitchService(this));
+ addService(new SwitchService(this));
}
@Override
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;
/**
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);
}
}
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;
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;
var volumeCharacteristic = getCharacteristic(VolumeCharacteristic.class);
var volumeSelectorCharacteristic = getCharacteristic(VolumeSelectorCharacteristic.class);
+ var service = new TelevisionSpeakerService(muteCharacteristic);
+
if (volumeControlTypeCharacteristic.isEmpty()) {
VolumeControlTypeEnum type;
if (volumeCharacteristic.isPresent()) {
} 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);
}
}
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new TemperatureSensorService(this));
+ addService(new TemperatureSensorService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- this.getServices().add(new ThermostatService(this));
+ addService(new ThermostatService(this));
}
@Override
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");
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new WindowCoveringService(this));
+ addService(new WindowCoveringService(this));
}
@Override
@Override
public void init() throws HomekitException {
super.init();
- getServices().add(new WindowService(this));
+ addService(new WindowService(this));
}
@Override