]> git.basschouten.com Git - openhab-addons.git/blob
3449f2fc38b85038dfcd93bde01df7848de4c9fb
[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_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.HmDatapoint;
23 import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
24 import org.openhab.binding.homematic.internal.model.HmDevice;
25 import org.openhab.binding.homematic.internal.model.HmValueType;
26
27 /**
28  * A virtual Switch datapoint which reloads all device values from the gateway.
29  *
30  * @author Gerhard Riegler - Initial contribution
31  */
32 public class ReloadFromGatewayVirtualDatapointHandler extends AbstractVirtualDatapointHandler {
33     @Override
34     public String getName() {
35         return VIRTUAL_DATAPOINT_NAME_RELOAD_FROM_GATEWAY;
36     }
37
38     @Override
39     public void initialize(HmDevice device) {
40         addDatapoint(device, 0, getName(), HmValueType.BOOL, Boolean.FALSE, false);
41     }
42
43     @Override
44     public boolean canHandleCommand(HmDatapoint dp, Object value) {
45         return getName().equals(dp.getName());
46     }
47
48     @Override
49     public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
50             throws IOException, HomematicClientException {
51         dp.setValue(value);
52         if (MiscUtils.isTrueValue(dp.getValue())) {
53             try {
54                 gateway.triggerDeviceValuesReload(dp.getChannel().getDevice());
55             } finally {
56                 gateway.disableDatapoint(dp, AbstractHomematicGateway.DEFAULT_DISABLE_DELAY);
57             }
58         }
59     }
60 }