2 * Copyright (c) 2010-2021 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.core.library.types.OnOffType;
21 import org.openhab.core.library.types.OpenClosedType;
22 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
23 import org.openhab.io.homekit.internal.HomekitSettings;
24 import org.openhab.io.homekit.internal.HomekitTaggedItem;
26 import io.github.hapjava.accessories.FanAccessory;
27 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
28 import io.github.hapjava.services.impl.FanService;
31 * Implements Fan using an Item that provides an On/Off state
33 * @author Eugen Freiter - Initial contribution
35 class HomekitFanImpl extends AbstractHomekitAccessoryImpl implements FanAccessory {
36 private final BooleanItemReader activeReader;
38 public HomekitFanImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
39 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
40 super(taggedItem, mandatoryCharacteristics, updater, settings);
41 activeReader = createBooleanReader(ACTIVE_STATUS, OnOffType.ON, OpenClosedType.OPEN);
42 this.getServices().add(new FanService(this));
46 public CompletableFuture<Boolean> isActive() {
47 return CompletableFuture.completedFuture(activeReader.getValue());
51 public CompletableFuture<Void> setActive(boolean state) {
52 activeReader.setValue(state);
53 return CompletableFuture.completedFuture(null);
57 public void subscribeActive(HomekitCharacteristicChangeCallback callback) {
58 subscribe(ACTIVE_STATUS, callback);
62 public void unsubscribeActive() {
63 unsubscribe(ACTIVE_STATUS);