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_RELOAD_ALL_FROM_GATEWAY;
17 import java.io.IOException;
19 import org.openhab.binding.homematic.internal.communicator.AbstractHomematicGateway;
20 import org.openhab.binding.homematic.internal.misc.HomematicClientException;
21 import org.openhab.binding.homematic.internal.misc.MiscUtils;
22 import org.openhab.binding.homematic.internal.model.HmChannel;
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.HmDevice;
26 import org.openhab.binding.homematic.internal.model.HmValueType;
29 * A virtual Switch datapoint which reloads all device values from the gateway.
31 * @author Gerhard Riegler - Initial contribution
33 public class ReloadAllFromGatewayVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
35 public String getName() {
36 return VIRTUAL_DATAPOINT_NAME_RELOAD_ALL_FROM_GATEWAY;
40 public void initialize(HmDevice device) {
41 if (device.isGatewayExtras()) {
42 addDatapoint(device, HmChannel.CHANNEL_NUMBER_EXTRAS, getName(), HmValueType.BOOL, Boolean.FALSE, false);
47 public boolean canHandleCommand(HmDatapoint dp, Object value) {
48 return getName().equals(dp.getName());
52 public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
53 throws IOException, HomematicClientException {
55 if (MiscUtils.isTrueValue(dp.getValue())) {
57 gateway.getGatewayAdapter().reloadAllDeviceValues();
59 gateway.disableDatapoint(dp, AbstractHomematicGateway.DEFAULT_DISABLE_DELAY);