2 * Copyright (c) 2010-2023 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 static org.openhab.io.homekit.internal.HomekitCharacteristicType.ACTIVE_STATUS;
17 import java.util.List;
18 import java.util.concurrent.CompletableFuture;
20 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
21 import org.openhab.io.homekit.internal.HomekitSettings;
22 import org.openhab.io.homekit.internal.HomekitTaggedItem;
24 import io.github.hapjava.accessories.FanAccessory;
25 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
26 import io.github.hapjava.services.impl.FanService;
29 * Implements Fan using an Item that provides an On/Off state
31 * @author Eugen Freiter - Initial contribution
33 class HomekitFanImpl extends AbstractHomekitAccessoryImpl implements FanAccessory {
34 private final BooleanItemReader activeReader;
36 public HomekitFanImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
37 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
38 super(taggedItem, mandatoryCharacteristics, updater, settings);
39 activeReader = createBooleanReader(ACTIVE_STATUS);
40 this.getServices().add(new FanService(this));
44 public CompletableFuture<Boolean> isActive() {
45 return CompletableFuture.completedFuture(activeReader.getValue());
49 public CompletableFuture<Void> setActive(boolean state) {
50 activeReader.setValue(state);
51 return CompletableFuture.completedFuture(null);
55 public void subscribeActive(HomekitCharacteristicChangeCallback callback) {
56 subscribe(ACTIVE_STATUS, callback);
60 public void unsubscribeActive() {
61 unsubscribe(ACTIVE_STATUS);