]> git.basschouten.com Git - openhab-addons.git/blob
beeab7618012dcb8b2f4d64c49da7a52d3c3770c
[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.HomekitException;
22 import org.openhab.io.homekit.internal.HomekitSettings;
23 import org.openhab.io.homekit.internal.HomekitTaggedItem;
24
25 import io.github.hapjava.accessories.FaucetAccessory;
26 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
27 import io.github.hapjava.services.impl.FaucetService;
28
29 /**
30  * Implements Faucet using an Item that provides an On/Off state
31  *
32  * @author Eugen Freiter - Initial contribution
33  */
34 class HomekitFaucetImpl extends AbstractHomekitAccessoryImpl implements FaucetAccessory {
35     private final BooleanItemReader activeReader;
36
37     public HomekitFaucetImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
38             HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
39         super(taggedItem, mandatoryCharacteristics, updater, settings);
40         activeReader = createBooleanReader(ACTIVE);
41     }
42
43     @Override
44     public void init() throws HomekitException {
45         super.init();
46         this.getServices().add(new FaucetService(this));
47     }
48
49     @Override
50     public CompletableFuture<Boolean> isActive() {
51         return CompletableFuture.completedFuture(activeReader.getValue());
52     }
53
54     @Override
55     public CompletableFuture<Void> setActive(boolean state) {
56         activeReader.setValue(state);
57         return CompletableFuture.completedFuture(null);
58     }
59
60     @Override
61     public void subscribeActive(HomekitCharacteristicChangeCallback callback) {
62         subscribe(ACTIVE, callback);
63     }
64
65     @Override
66     public void unsubscribeActive() {
67         unsubscribe(ACTIVE);
68     }
69 }