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.openhab.io.homekit.internal.HomekitAccessoryUpdater;
19 import org.openhab.io.homekit.internal.HomekitCharacteristicType;
20 import org.openhab.io.homekit.internal.HomekitException;
21 import org.openhab.io.homekit.internal.HomekitSettings;
22 import org.openhab.io.homekit.internal.HomekitTaggedItem;
24 import io.github.hapjava.accessories.SpeakerAccessory;
25 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
26 import io.github.hapjava.services.impl.SpeakerService;
29 * Implements Speaker using an Item that provides an On/Off state for Mute.
31 * @author Eugen Freiter - Initial contribution
33 public class HomekitSpeakerImpl extends AbstractHomekitAccessoryImpl implements SpeakerAccessory {
34 private final BooleanItemReader muteReader;
36 public HomekitSpeakerImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
37 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
38 super(taggedItem, mandatoryCharacteristics, updater, settings);
39 muteReader = createBooleanReader(HomekitCharacteristicType.MUTE);
43 public void init() throws HomekitException {
45 getServices().add(new SpeakerService(this));
49 public CompletableFuture<Boolean> isMuted() {
50 return CompletableFuture.completedFuture(muteReader.getValue());
54 public CompletableFuture<Void> setMute(boolean state) {
55 muteReader.setValue(state);
56 return CompletableFuture.completedFuture(null);
60 public void subscribeMuteState(HomekitCharacteristicChangeCallback callback) {
61 subscribe(HomekitCharacteristicType.MUTE, callback);
65 public void unsubscribeMuteState() {
66 unsubscribe(HomekitCharacteristicType.MUTE);