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.homematic.internal.communicator.virtual;
15 import static org.openhab.binding.homematic.internal.misc.HomematicConstants.VIRTUAL_DATAPOINT_NAME_DELETE_DEVICE_MODE;
17 import java.io.IOException;
19 import org.openhab.binding.homematic.internal.misc.HomematicClientException;
20 import org.openhab.binding.homematic.internal.model.HmDatapoint;
21 import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
22 import org.openhab.binding.homematic.internal.model.HmDevice;
23 import org.openhab.binding.homematic.internal.model.HmInterface;
24 import org.openhab.binding.homematic.internal.model.HmValueType;
27 * A virtual enum datapoint which holds the delete flag for deleting a device with the DELETE_DEVICE virtual datapoint.
28 * Falls back to LOCKED after 30 seconds to prevent accidental deletion.
30 * @author Gerhard Riegler - Initial contribution
32 public class DeleteDeviceModeVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
33 protected static final String MODE_LOCKED = "LOCKED";
34 protected static final String MODE_RESET = "RESET";
35 protected static final String MODE_FORCE = "FORCE";
36 protected static final String MODE_DEFER = "DEFER";
37 private static final int DELETE_MODE_DURATION = 30;
40 public String getName() {
41 return VIRTUAL_DATAPOINT_NAME_DELETE_DEVICE_MODE;
45 public void initialize(HmDevice device) {
46 if (!device.isGatewayExtras() && device.getHmInterface() != HmInterface.CUXD) {
47 HmDatapoint dp = addDatapoint(device, 0, getName(), HmValueType.ENUM, 0, false);
48 dp.setOptions(new String[] { MODE_LOCKED, MODE_RESET, MODE_FORCE, MODE_DEFER });
50 dp.setMaxValue(dp.getOptions().length - 1);
55 public boolean canHandleCommand(HmDatapoint dp, Object value) {
56 return getName().equals(dp.getName());
60 public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
61 throws IOException, HomematicClientException {
63 if (!MODE_LOCKED.equals(dp.getOptionValue())) {
64 gateway.disableDatapoint(dp, DELETE_MODE_DURATION);