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