2 * Copyright (c) 2010-2021 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.LIGHT_LEVEL;
17 import java.util.List;
18 import java.util.concurrent.CompletableFuture;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.library.types.DecimalType;
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.LightSensorAccessory;
27 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
28 import io.github.hapjava.services.impl.LightSensorService;
31 * HomeKit light sensor implementation.
33 * @author Eugen Freiter - Initial contribution
35 public class HomekitLightSensorImpl extends AbstractHomekitAccessoryImpl implements LightSensorAccessory {
37 public HomekitLightSensorImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
38 HomekitAccessoryUpdater updater, HomekitSettings settings) {
39 super(taggedItem, mandatoryCharacteristics, updater, settings);
40 getServices().add(new LightSensorService(this));
44 public CompletableFuture<Double> getCurrentAmbientLightLevel() {
45 final @Nullable DecimalType state = getStateAs(LIGHT_LEVEL, DecimalType.class);
46 return CompletableFuture.completedFuture(state != null ? state.doubleValue() : 0.0);
50 public void subscribeCurrentAmbientLightLevel(HomekitCharacteristicChangeCallback callback) {
51 subscribe(LIGHT_LEVEL, callback);
55 public void unsubscribeCurrentAmbientLightLevel() {
56 unsubscribe(LIGHT_LEVEL);