]> git.basschouten.com Git - openhab-addons.git/blob
2f6cfeb7e99cfd8b4b4d9ea6eb14a620a315d434
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.homematic.internal.communicator.virtual;
14
15 import static org.openhab.binding.homematic.internal.misc.HomematicConstants.VIRTUAL_DATAPOINT_NAME_RELOAD_ALL_FROM_GATEWAY;
16
17 import java.io.IOException;
18
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;
27
28 /**
29  * A virtual Switch datapoint which reloads all device values from the gateway.
30  *
31  * @author Gerhard Riegler - Initial contribution
32  */
33 public class ReloadAllFromGatewayVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
34     @Override
35     public String getName() {
36         return VIRTUAL_DATAPOINT_NAME_RELOAD_ALL_FROM_GATEWAY;
37     }
38
39     @Override
40     public void initialize(HmDevice device) {
41         if (device.isGatewayExtras()) {
42             addDatapoint(device, HmChannel.CHANNEL_NUMBER_EXTRAS, getName(), HmValueType.BOOL, Boolean.FALSE, false);
43         }
44     }
45
46     @Override
47     public boolean canHandleCommand(HmDatapoint dp, Object value) {
48         return getName().equals(dp.getName());
49     }
50
51     @Override
52     public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
53             throws IOException, HomematicClientException {
54         dp.setValue(value);
55         if (MiscUtils.isTrueValue(dp.getValue())) {
56             try {
57                 gateway.getGatewayAdapter().reloadAllDeviceValues();
58             } finally {
59                 gateway.disableDatapoint(dp, AbstractHomematicGateway.DEFAULT_DISABLE_DELAY);
60             }
61         }
62     }
63 }