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.dlinksmarthome.internal.handler;
15 import static org.openhab.binding.dlinksmarthome.internal.DLinkSmartHomeBindingConstants.MOTION;
17 import org.openhab.binding.dlinksmarthome.internal.motionsensor.DLinkMotionSensorCommunication;
18 import org.openhab.binding.dlinksmarthome.internal.motionsensor.DLinkMotionSensorCommunication.DeviceStatus;
19 import org.openhab.binding.dlinksmarthome.internal.motionsensor.DLinkMotionSensorConfig;
20 import org.openhab.binding.dlinksmarthome.internal.motionsensor.DLinkMotionSensorListener;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.ThingStatus;
24 import org.openhab.core.thing.ThingStatusDetail;
25 import org.openhab.core.thing.binding.BaseThingHandler;
26 import org.openhab.core.types.Command;
29 * The {@link DLinkMotionSensorHandler} is responsible for handling commands, which are
30 * sent to one of the channels.
32 * @author Mike Major - Initial contribution
34 public class DLinkMotionSensorHandler extends BaseThingHandler implements DLinkMotionSensorListener {
36 private DLinkMotionSensorCommunication motionSensor;
38 private final ChannelUID motionChannel;
40 public DLinkMotionSensorHandler(final Thing thing) {
42 motionChannel = new ChannelUID(getThing().getUID(), MOTION);
46 public void handleCommand(final ChannelUID channelUID, final Command command) {
47 // Does not support commands
51 public void initialize() {
52 final DLinkMotionSensorConfig config = getConfigAs(DLinkMotionSensorConfig.class);
53 motionSensor = new DLinkMotionSensorCommunication(config, this, scheduler);
57 public void motionDetected() {
58 triggerChannel(motionChannel);
62 public void sensorStatus(final DeviceStatus status) {
65 updateStatus(ThingStatus.ONLINE);
67 case COMMUNICATION_ERROR:
68 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
71 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Invalid pin code");
74 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "System error");
76 case UNSUPPORTED_FIRMWARE:
77 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Unsupported firmware");
85 public void dispose() {
86 if (motionSensor != null) {
87 motionSensor.dispose();