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.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler.*;
16 import static org.openhab.binding.homematic.internal.misc.HomematicConstants.*;
18 import java.io.IOException;
20 import org.openhab.binding.homematic.internal.communicator.AbstractHomematicGateway;
21 import org.openhab.binding.homematic.internal.misc.HomematicClientException;
22 import org.openhab.binding.homematic.internal.misc.MiscUtils;
23 import org.openhab.binding.homematic.internal.model.HmDatapoint;
24 import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
25 import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
26 import org.openhab.binding.homematic.internal.model.HmDevice;
27 import org.openhab.binding.homematic.internal.model.HmInterface;
28 import org.openhab.binding.homematic.internal.model.HmValueType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * A virtual boolean datapoint which locks the device so it can not be accidentally removed from the gateway.
35 * @author Gerhard Riegler - Initial contribution
37 public class DeleteDeviceVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
38 private final Logger logger = LoggerFactory.getLogger(DeleteDeviceVirtualDatapointHandler.class);
41 public String getName() {
42 return VIRTUAL_DATAPOINT_NAME_DELETE_DEVICE;
46 public void initialize(HmDevice device) {
47 if (!device.isGatewayExtras() && !(device.getHmInterface() == HmInterface.CUXD)) {
48 addDatapoint(device, 0, getName(), HmValueType.BOOL, Boolean.FALSE, false);
53 public boolean canHandleCommand(HmDatapoint dp, Object value) {
54 return getName().equals(dp.getName());
58 public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
59 throws IOException, HomematicClientException {
61 if (MiscUtils.isTrueValue(dp.getValue())) {
63 HmDatapoint deleteMode = dp.getChannel().getDatapoint(
64 HmDatapointInfo.createValuesInfo(dp.getChannel(), VIRTUAL_DATAPOINT_NAME_DELETE_DEVICE_MODE));
65 HmDevice device = dp.getChannel().getDevice();
67 switch (deleteMode.getOptionValue()) {
78 logger.info("Can't delete device '{}' from gateway '{}', DELETE_MODE is LOCKED",
79 device.getAddress(), gateway.getId());
81 gateway.getRpcClient(device.getHmInterface()).deleteDevice(device, flag);
84 gateway.disableDatapoint(dp, AbstractHomematicGateway.DEFAULT_DISABLE_DELAY);