]> git.basschouten.com Git - openhab-addons.git/blob
e1d1dee0c3b7db72b3e5da1212b22aa7d4306cae
[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.lcn.internal.connection;
14
15 import java.util.concurrent.TimeUnit;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.lcn.internal.common.LcnException;
19
20 /**
21  * Base class for sending username or password.
22  *
23  * @author Fabian Wolter - Initial Contribution
24  */
25 @NonNullByDefault
26 public abstract class AbstractConnectionStateSendCredentials extends AbstractConnectionState {
27     private static final int AUTH_TIMEOUT_SEC = 10;
28
29     public AbstractConnectionStateSendCredentials(ConnectionStateMachine context) {
30         super(context);
31     }
32
33     @Override
34     public void startWorking() {
35         addTimer(getScheduler().schedule(() -> nextState(ConnectionStateConnecting::new), AUTH_TIMEOUT_SEC,
36                 TimeUnit.SECONDS));
37     }
38
39     /**
40      * Starts a timeout when the PCK gateway does not answer to the credentials.
41      */
42     protected void startTimeoutTimer() {
43         addTimer(getScheduler().schedule(
44                 () -> handleConnectionFailed(
45                         new LcnException("Network timeout in state " + getClass().getSimpleName())),
46                 connection.getSettings().getTimeout(), TimeUnit.MILLISECONDS));
47     }
48 }