2 * Copyright (c) 2010-2024 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 java.util.List;
16 import java.util.concurrent.CompletableFuture;
18 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
19 import org.openhab.io.homekit.internal.HomekitCharacteristicType;
20 import org.openhab.io.homekit.internal.HomekitSettings;
21 import org.openhab.io.homekit.internal.HomekitTaggedItem;
23 import io.github.hapjava.accessories.MotionSensorAccessory;
24 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
25 import io.github.hapjava.services.impl.MotionSensorService;
29 * @author Tim Harper - Initial contribution
31 public class HomekitMotionSensorImpl extends AbstractHomekitAccessoryImpl implements MotionSensorAccessory {
32 private final BooleanItemReader motionSensedReader;
34 public HomekitMotionSensorImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
35 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
36 super(taggedItem, mandatoryCharacteristics, updater, settings);
37 motionSensedReader = createBooleanReader(HomekitCharacteristicType.MOTION_DETECTED_STATE);
38 getServices().add(new MotionSensorService(this));
42 public CompletableFuture<Boolean> getMotionDetected() {
43 return CompletableFuture.completedFuture(motionSensedReader.getValue());
47 public void subscribeMotionDetected(HomekitCharacteristicChangeCallback callback) {
48 subscribe(HomekitCharacteristicType.MOTION_DETECTED_STATE, callback);
52 public void unsubscribeMotionDetected() {
53 unsubscribe(HomekitCharacteristicType.MOTION_DETECTED_STATE);