]> git.basschouten.com Git - openhab-addons.git/blob
7ec1f56ce8bf6adfdaac12e3568c538ad325210e
[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_LATEST_MOTION;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandler;
21 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22 import org.openhab.binding.boschshc.internal.services.latestmotion.LatestMotionService;
23 import org.openhab.binding.boschshc.internal.services.latestmotion.dto.LatestMotionServiceState;
24 import org.openhab.core.library.types.DateTimeType;
25 import org.openhab.core.thing.Thing;
26
27 /**
28  * Detects every movement through an intelligent combination of passive infra-red technology and an additional
29  * temperature sensor.
30  *
31  * @author Stefan Kästle - Initial contribution
32  * @author Christian Oeing - Use service instead of custom logic
33  */
34 @NonNullByDefault
35 public class MotionDetectorHandler extends AbstractBatteryPoweredDeviceHandler {
36
37     public MotionDetectorHandler(Thing thing) {
38         super(thing);
39     }
40
41     @Override
42     protected void initializeServices() throws BoschSHCException {
43         super.initializeServices();
44
45         this.createService(LatestMotionService::new, this::updateChannels, List.of(CHANNEL_LATEST_MOTION));
46     }
47
48     private void updateChannels(LatestMotionServiceState state) {
49         DateTimeType date = new DateTimeType(state.latestMotionDetected);
50         updateState(CHANNEL_LATEST_MOTION, date);
51     }
52 }