]> git.basschouten.com Git - openhab-addons.git/blob
a8fe068033acf23cccdcab6765ef872cd26b31a8
[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.CURRENT_SLAT_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.SlatAccessory;
27 import io.github.hapjava.characteristics.Characteristic;
28 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
29 import io.github.hapjava.characteristics.impl.slat.CurrentSlatStateEnum;
30 import io.github.hapjava.characteristics.impl.slat.SlatTypeEnum;
31 import io.github.hapjava.services.impl.SlatService;
32
33 /**
34  *
35  * @author Eugen Freiter - Initial contribution
36  */
37 public class HomekitSlatImpl extends AbstractHomekitAccessoryImpl implements SlatAccessory {
38     private static final String CONFIG_TYPE = "type";
39     private final Map<CurrentSlatStateEnum, String> currentSlatStateMapping;
40     private final SlatTypeEnum slatType;
41
42     public HomekitSlatImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
43             List<Characteristic> mandatoryRawCharacteristics, HomekitAccessoryUpdater updater,
44             HomekitSettings settings) {
45         super(taggedItem, mandatoryCharacteristics, mandatoryRawCharacteristics, updater, settings);
46         final String slatTypeConfig = getAccessoryConfiguration(CONFIG_TYPE, "horizontal");
47         slatType = "horizontal".equalsIgnoreCase(slatTypeConfig) ? SlatTypeEnum.HORIZONTAL : SlatTypeEnum.VERTICAL;
48         currentSlatStateMapping = createMapping(CURRENT_SLAT_STATE, CurrentSlatStateEnum.class);
49     }
50
51     @Override
52     public void init() throws HomekitException {
53         super.init();
54         addService(new SlatService(this));
55     }
56
57     @Override
58     public CompletableFuture<CurrentSlatStateEnum> getSlatState() {
59         return CompletableFuture.completedFuture(
60                 getKeyFromMapping(CURRENT_SLAT_STATE, currentSlatStateMapping, CurrentSlatStateEnum.FIXED));
61     }
62
63     @Override
64     public void subscribeSlatState(final HomekitCharacteristicChangeCallback callback) {
65         subscribe(CURRENT_SLAT_STATE, callback);
66     }
67
68     @Override
69     public void unsubscribeSlatState() {
70         unsubscribe(CURRENT_SLAT_STATE);
71     }
72
73     @Override
74     public CompletableFuture<SlatTypeEnum> getSlatType() {
75         return CompletableFuture.completedFuture(slatType);
76     }
77 }