2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.homekit.internal.accessories;
15 import static org.openhab.io.homekit.internal.HomekitCharacteristicType.CURRENT_SLAT_STATE;
17 import java.util.EnumMap;
18 import java.util.List;
20 import java.util.concurrent.CompletableFuture;
22 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
23 import org.openhab.io.homekit.internal.HomekitSettings;
24 import org.openhab.io.homekit.internal.HomekitTaggedItem;
26 import io.github.hapjava.accessories.SlatAccessory;
27 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
28 import io.github.hapjava.characteristics.impl.slat.CurrentSlatStateEnum;
29 import io.github.hapjava.characteristics.impl.slat.SlatTypeEnum;
30 import io.github.hapjava.services.impl.SlatService;
34 * @author Eugen Freiter - Initial contribution
36 public class HomekitSlatImpl extends AbstractHomekitAccessoryImpl implements SlatAccessory {
37 private static final String CONFIG_TYPE = "type";
38 private final Map<CurrentSlatStateEnum, String> currentSlatStateMapping;
39 private final SlatTypeEnum slatType;
41 public HomekitSlatImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
42 HomekitAccessoryUpdater updater, HomekitSettings settings) {
43 super(taggedItem, mandatoryCharacteristics, updater, settings);
44 final String slatTypeConfig = getAccessoryConfiguration(CONFIG_TYPE, "horizontal");
45 slatType = "horizontal".equalsIgnoreCase(slatTypeConfig) ? SlatTypeEnum.HORIZONTAL : SlatTypeEnum.VERTICAL;
46 currentSlatStateMapping = new EnumMap<>(CurrentSlatStateEnum.class);
47 currentSlatStateMapping.put(CurrentSlatStateEnum.FIXED, "FIXED");
48 currentSlatStateMapping.put(CurrentSlatStateEnum.SWINGING, "SWINGING");
49 currentSlatStateMapping.put(CurrentSlatStateEnum.JAMMED, "JAMMED");
50 updateMapping(CURRENT_SLAT_STATE, currentSlatStateMapping);
51 getServices().add(new SlatService(this));
55 public CompletableFuture<CurrentSlatStateEnum> getSlatState() {
56 return CompletableFuture.completedFuture(
57 getKeyFromMapping(CURRENT_SLAT_STATE, currentSlatStateMapping, CurrentSlatStateEnum.FIXED));
61 public void subscribeSlatState(final HomekitCharacteristicChangeCallback callback) {
62 subscribe(CURRENT_SLAT_STATE, callback);
66 public void unsubscribeSlatState() {
67 unsubscribe(CURRENT_SLAT_STATE);
71 public CompletableFuture<SlatTypeEnum> getSlatType() {
72 return CompletableFuture.completedFuture(slatType);