]> git.basschouten.com Git - openhab-addons.git/blob
e059e19be1e2a4f8e5cc58f1ae163e5bce0906fd
[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.LEAK_DETECTED_STATE;
16
17 import java.util.List;
18 import java.util.Map;
19 import java.util.concurrent.CompletableFuture;
20
21 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
22 import org.openhab.io.homekit.internal.HomekitException;
23 import org.openhab.io.homekit.internal.HomekitSettings;
24 import org.openhab.io.homekit.internal.HomekitTaggedItem;
25
26 import io.github.hapjava.accessories.LeakSensorAccessory;
27 import io.github.hapjava.characteristics.Characteristic;
28 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
29 import io.github.hapjava.characteristics.impl.leaksensor.LeakDetectedStateEnum;
30 import io.github.hapjava.services.impl.LeakSensorService;
31
32 /**
33  *
34  * @author Tim Harper - Initial contribution
35  */
36 public class HomekitLeakSensorImpl extends AbstractHomekitAccessoryImpl implements LeakSensorAccessory {
37     private final Map<LeakDetectedStateEnum, String> mapping;
38
39     public HomekitLeakSensorImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
40             List<Characteristic> mandatoryRawCharacteristics, HomekitAccessoryUpdater updater, HomekitSettings settings)
41             throws IncompleteAccessoryException {
42         super(taggedItem, mandatoryCharacteristics, mandatoryRawCharacteristics, updater, settings);
43         mapping = createMapping(LEAK_DETECTED_STATE, LeakDetectedStateEnum.class);
44     }
45
46     @Override
47     public void init() throws HomekitException {
48         super.init();
49         addService(new LeakSensorService(this));
50     }
51
52     @Override
53     public CompletableFuture<LeakDetectedStateEnum> getLeakDetected() {
54         return CompletableFuture.completedFuture(
55                 getKeyFromMapping(LEAK_DETECTED_STATE, mapping, LeakDetectedStateEnum.LEAK_NOT_DETECTED));
56     }
57
58     @Override
59     public void subscribeLeakDetected(HomekitCharacteristicChangeCallback callback) {
60         subscribe(LEAK_DETECTED_STATE, callback);
61     }
62
63     @Override
64     public void unsubscribeLeakDetected() {
65         unsubscribe(LEAK_DETECTED_STATE);
66     }
67 }