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.binding.boschshc.internal.devices.motiondetector;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_LATEST_MOTION;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.boschshc.internal.devices.BoschSHCHandler;
20 import org.openhab.binding.boschshc.internal.devices.motiondetector.dto.LatestMotionState;
21 import org.openhab.core.library.types.DateTimeType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.RefreshType;
27 import com.google.gson.JsonElement;
30 * MotionDetectorHandler
32 * @author Stefan Kästle - Initial contribution
35 public class MotionDetectorHandler extends BoschSHCHandler {
37 public MotionDetectorHandler(Thing thing) {
42 public void handleCommand(ChannelUID channelUID, Command command) {
43 logger.debug("Handle command for: {} - {}", channelUID.getThingUID(), command);
45 if (CHANNEL_LATEST_MOTION.equals(channelUID.getId())) {
46 if (command instanceof RefreshType) {
47 LatestMotionState state = this.getState("LatestMotion", LatestMotionState.class);
49 updateLatestMotionState(state);
55 void updateLatestMotionState(LatestMotionState state) {
56 DateTimeType date = new DateTimeType(state.latestMotionDetected);
57 updateState(CHANNEL_LATEST_MOTION, date);
61 public void processUpdate(String id, JsonElement state) {
62 logger.debug("Motion detector: received update: {} {}", id, state);
65 LatestMotionState latestMotionState = GSON.fromJson(state, LatestMotionState.class);
66 if (latestMotionState == null) {
67 logger.warn("Received unknown update in in-wall switch: {}", state);
70 updateLatestMotionState(latestMotionState);