]> git.basschouten.com Git - openhab-addons.git/blob
f828e067f0b6a1bb25032c0c52c108288f86da1e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.binding.boschshc.internal.devices.motiondetector;
14
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;
17
18 import java.util.List;
19
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;
30
31 /**
32  * Detects every movement through an intelligent combination of passive infra-red technology and an additional
33  * temperature sensor.
34  *
35  * @author Stefan Kästle - Initial contribution
36  * @author Christian Oeing - Use service instead of custom logic
37  * @author David Pace - Added illuminance channel
38  */
39 @NonNullByDefault
40 public class MotionDetectorHandler extends AbstractBatteryPoweredDeviceHandler {
41
42     public MotionDetectorHandler(Thing thing) {
43         super(thing);
44     }
45
46     @Override
47     protected void initializeServices() throws BoschSHCException {
48         super.initializeServices();
49
50         this.createService(LatestMotionService::new, this::updateChannels, List.of(CHANNEL_LATEST_MOTION));
51         this.createService(IlluminanceService::new, this::updateChannels, List.of(CHANNEL_ILLUMINANCE), true);
52     }
53
54     private void updateChannels(LatestMotionServiceState state) {
55         DateTimeType date = new DateTimeType(state.latestMotionDetected);
56         updateState(CHANNEL_LATEST_MOTION, date);
57     }
58
59     private void updateChannels(IlluminanceServiceState state) {
60         DecimalType illuminance = new DecimalType(state.illuminance);
61         updateState(CHANNEL_ILLUMINANCE, illuminance);
62     }
63 }