]> git.basschouten.com Git - openhab-addons.git/blob
a2ea89e7f43cea9f64bb2cdd003b2e93ea3e46e8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.homekit.internal.accessories;
14
15 import static org.openhab.io.homekit.internal.HomekitCharacteristicType.ACTIVE;
16
17 import java.util.List;
18 import java.util.concurrent.CompletableFuture;
19
20 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
21 import org.openhab.io.homekit.internal.HomekitSettings;
22 import org.openhab.io.homekit.internal.HomekitTaggedItem;
23
24 import io.github.hapjava.accessories.FaucetAccessory;
25 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
26 import io.github.hapjava.services.impl.FaucetService;
27
28 /**
29  * Implements Faucet using an Item that provides an On/Off state
30  *
31  * @author Eugen Freiter - Initial contribution
32  */
33 class HomekitFaucetImpl extends AbstractHomekitAccessoryImpl implements FaucetAccessory {
34     private final BooleanItemReader activeReader;
35
36     public HomekitFaucetImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
37             HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
38         super(taggedItem, mandatoryCharacteristics, updater, settings);
39         activeReader = createBooleanReader(ACTIVE);
40         this.getServices().add(new FaucetService(this));
41     }
42
43     @Override
44     public CompletableFuture<Boolean> isActive() {
45         return CompletableFuture.completedFuture(activeReader.getValue());
46     }
47
48     @Override
49     public CompletableFuture<Void> setActive(boolean state) {
50         activeReader.setValue(state);
51         return CompletableFuture.completedFuture(null);
52     }
53
54     @Override
55     public void subscribeActive(HomekitCharacteristicChangeCallback callback) {
56         subscribe(ACTIVE, callback);
57     }
58
59     @Override
60     public void unsubscribeActive() {
61         unsubscribe(ACTIVE);
62     }
63 }