]> git.basschouten.com Git - openhab-addons.git/blob
2855ba05aed6742ec3f3dabf1edd4aa0023a570d
[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.souliss.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.souliss.internal.protocol.CommonCommands;
18 import org.openhab.core.thing.Bridge;
19
20 /**
21  * @author Tonino Fazio - Initial contribution
22  * @author Luca Calcaterra - Refactor for OH3
23  */
24
25 @NonNullByDefault
26 public class SoulissGatewayJobPing implements Runnable {
27
28     private @Nullable SoulissGatewayHandler gwHandler;
29
30     private final CommonCommands commonCommands = new CommonCommands();
31
32     public SoulissGatewayJobPing(Bridge bridge) {
33         var bridgeHandler = bridge.getHandler();
34         if (bridgeHandler != null) {
35             gwHandler = (SoulissGatewayHandler) bridgeHandler;
36         }
37     }
38
39     @Override
40     public void run() {
41         SoulissGatewayHandler localGwHandler = this.gwHandler;
42         if (localGwHandler != null) {
43             sendPing(localGwHandler);
44
45             localGwHandler.pingSent();
46         }
47     }
48
49     private void sendPing(SoulissGatewayHandler soulissGwHandler) {
50         // sending ping packet
51
52         if (soulissGwHandler.getGwConfig().gatewayLanAddress.length() > 0) {
53             commonCommands.sendPing(soulissGwHandler.getGwConfig());
54             // ping packet sent
55         }
56     }
57 }