2 * Copyright (c) 2010-2022 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.sinope.internal.core;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.util.Arrays;
19 import org.openhab.binding.sinope.internal.core.base.SinopeAnswer;
20 import org.openhab.binding.sinope.internal.util.ByteUtil;
23 * The Class SinopeAuthenticationKeyAnswer.
25 * @author Pascal Larin - Initial contribution
27 public class SinopeAuthenticationKeyAnswer extends SinopeAnswer {
29 /** The Constant STATUS_SIZE. */
30 protected static final int STATUS_SIZE = 1;
32 /** The Constant BACKOFF_SIZE. */
33 protected static final int BACKOFF_SIZE = 2;
35 /** The Constant API_KEY_SIZE. */
36 protected static final int API_KEY_SIZE = 8;
39 * Instantiates a new sinope authentication key answer.
42 * @throws IOException Signals that an I/O exception has occurred.
44 public SinopeAuthenticationKeyAnswer(InputStream r) throws IOException {
49 * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#getCommand()
52 protected byte[] getCommand() {
53 return new byte[] { 0x01, 0x11 };
61 public int getStatus() {
62 byte[] b = this.getFrameData();
71 public byte[] getBackoff() {
72 byte[] b = this.getFrameData();
73 b = Arrays.copyOfRange(b, STATUS_SIZE, STATUS_SIZE + BACKOFF_SIZE);
82 public byte[] getApiKey() {
83 byte[] b = this.getFrameData();
84 b = Arrays.copyOfRange(b, STATUS_SIZE + BACKOFF_SIZE, STATUS_SIZE + BACKOFF_SIZE + API_KEY_SIZE);
85 return ByteUtil.reverse(b);
89 * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#toString()
92 public String toString() {
93 StringBuilder sb = new StringBuilder();
94 sb.append(super.toString());
95 sb.append(String.format("\nData: %s", ByteUtil.toString(getFrameData())));
96 sb.append(String.format("\n\tStatus: 0x%02X ", getStatus()));
97 sb.append(String.format("\n\tApi Key: %s", ByteUtil.toString(getApiKey())));
98 sb.append(String.format("\n\tBackoff: %s", ByteUtil.toString(getBackoff())));