2 * Copyright (c) 2010-2023 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.binding.boschshc.internal.devices.motiondetector;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_ILLUMINANCE;
16 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_LATEST_MOTION;
18 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandler;
22 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
23 import org.openhab.binding.boschshc.internal.services.illuminance.IlluminanceService;
24 import org.openhab.binding.boschshc.internal.services.illuminance.dto.IlluminanceServiceState;
25 import org.openhab.binding.boschshc.internal.services.latestmotion.LatestMotionService;
26 import org.openhab.binding.boschshc.internal.services.latestmotion.dto.LatestMotionServiceState;
27 import org.openhab.core.library.types.DateTimeType;
28 import org.openhab.core.library.types.DecimalType;
29 import org.openhab.core.thing.Thing;
32 * Detects every movement through an intelligent combination of passive infra-red technology and an additional
35 * @author Stefan Kästle - Initial contribution
36 * @author Christian Oeing - Use service instead of custom logic
37 * @author David Pace - Added illuminance channel
40 public class MotionDetectorHandler extends AbstractBatteryPoweredDeviceHandler {
42 public MotionDetectorHandler(Thing thing) {
47 protected void initializeServices() throws BoschSHCException {
48 super.initializeServices();
50 this.createService(LatestMotionService::new, this::updateChannels, List.of(CHANNEL_LATEST_MOTION));
51 this.createService(IlluminanceService::new, this::updateChannels, List.of(CHANNEL_ILLUMINANCE), true);
54 private void updateChannels(LatestMotionServiceState state) {
55 DateTimeType date = new DateTimeType(state.latestMotionDetected);
56 updateState(CHANNEL_LATEST_MOTION, date);
59 private void updateChannels(IlluminanceServiceState state) {
60 DecimalType illuminance = new DecimalType(state.illuminance);
61 updateState(CHANNEL_ILLUMINANCE, illuminance);