2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.homekit.internal.accessories;
15 import java.util.List;
16 import java.util.concurrent.CompletableFuture;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
20 import org.openhab.io.homekit.internal.HomekitCharacteristicType;
21 import org.openhab.io.homekit.internal.HomekitException;
22 import org.openhab.io.homekit.internal.HomekitSettings;
23 import org.openhab.io.homekit.internal.HomekitTaggedItem;
25 import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic;
26 import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic;
27 import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeControlTypeCharacteristic;
28 import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeControlTypeEnum;
29 import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeSelectorCharacteristic;
30 import io.github.hapjava.services.impl.TelevisionSpeakerService;
33 * Implements Television Speaker
35 * This is a little different in that we don't implement the accessory interface.
36 * This is because several of the "mandatory" characteristics we don't require,
37 * and wait until all optional attributes are added and if they don't exist
38 * it will create "default" values for them.
40 * @author Cody Cutrer - Initial contribution
43 public class HomekitTelevisionSpeakerImpl extends AbstractHomekitAccessoryImpl {
45 public HomekitTelevisionSpeakerImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
46 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
47 super(taggedItem, mandatoryCharacteristics, updater, settings);
51 public void init() throws HomekitException {
54 var muteCharacteristic = (MuteCharacteristic) HomekitCharacteristicFactory
55 .createCharacteristic(getCharacteristic(HomekitCharacteristicType.MUTE).get(), getUpdater());
56 // this characteristic is technically optional, but we provide a default implementation if it's not provided
57 var volumeControlTypeCharacteristic = getCharacteristic(VolumeControlTypeCharacteristic.class);
58 // optional characteristics
59 var volumeCharacteristic = getCharacteristic(VolumeCharacteristic.class);
60 var volumeSelectorCharacteristic = getCharacteristic(VolumeSelectorCharacteristic.class);
62 var service = new TelevisionSpeakerService(muteCharacteristic);
64 if (volumeControlTypeCharacteristic.isEmpty()) {
65 VolumeControlTypeEnum type;
66 if (volumeCharacteristic.isPresent()) {
67 type = VolumeControlTypeEnum.ABSOLUTE;
68 } else if (volumeSelectorCharacteristic.isPresent()) {
69 type = VolumeControlTypeEnum.RELATIVE;
71 type = VolumeControlTypeEnum.NONE;
73 service.addOptionalCharacteristic(
74 new VolumeControlTypeCharacteristic(() -> CompletableFuture.completedFuture(type), v -> {