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.pjlinkdevice.internal.device.command.authentication;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.pjlinkdevice.internal.device.PJLinkDevice;
19 import org.openhab.binding.pjlinkdevice.internal.device.command.AuthenticationException;
20 import org.openhab.binding.pjlinkdevice.internal.device.command.Command;
21 import org.openhab.binding.pjlinkdevice.internal.device.command.Response;
22 import org.openhab.binding.pjlinkdevice.internal.device.command.ResponseException;
25 * This command is used to authenticate to the device after the connection established.
26 * As authentication can only be done in conjunction with a real command, a testCommand must be passed to authenticate.
28 * The authentication procedure is described in
29 * <a href="https://pjlink.jbmia.or.jp/english/data_cl2/PJLink_5-1.pdf">[PJLinkSpec]</a> chapter 5.1. Authentication
32 * @author Nils Schnabel - Initial contribution
35 public class AuthenticationCommand<ResponseType extends Response<?>> implements Command<ResponseType> {
37 private String challenge;
38 private Command<ResponseType> testCommand;
39 private PJLinkDevice device;
41 public AuthenticationCommand(PJLinkDevice pjLinkDevice, String challenge, Command<ResponseType> testCommand) {
42 this.device = pjLinkDevice;
43 this.challenge = challenge;
44 this.testCommand = testCommand;
48 public ResponseType execute() throws ResponseException, IOException, AuthenticationException {
49 this.device.addPrefixToNextCommand(createRequest().getRequestString());
50 return this.testCommand.execute();
53 protected AuthenticationRequest<ResponseType> createRequest() {
54 return new AuthenticationRequest<>(this);
57 public String getChallenge() {
58 return this.challenge;
61 public PJLinkDevice getDevice() {