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.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 SinopeDeviceReportAnswer.
25 * @author Pascal Larin - Initial contribution
27 public class SinopeDeviceReportAnswer extends SinopeAnswer {
29 /** The Constant STATUS_SIZE. */
30 protected static final int STATUS_SIZE = 1;
32 /** The Constant DEVICE_ID_SIZE. */
33 protected static final int DEVICE_ID_SIZE = 4;
36 * Instantiates a new sinope device report answer.
39 * @throws IOException Signals that an I/O exception has occurred.
41 public SinopeDeviceReportAnswer(InputStream r) throws IOException {
46 * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#getCommand()
49 protected byte[] getCommand() {
50 return new byte[] { 0x01, 0x16 };
58 public byte getStatus() {
59 byte[] b = this.getFrameData();
66 * @return the device id
68 public byte[] getDeviceId() {
69 byte[] b = this.getFrameData();
70 b = Arrays.copyOfRange(b, STATUS_SIZE, STATUS_SIZE + DEVICE_ID_SIZE);
71 return ByteUtil.reverse(b);
75 * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#toString()
78 public String toString() {
79 StringBuilder sb = new StringBuilder();
80 sb.append(super.toString());
81 sb.append(String.format("\nStatus: 0x%02X ", getStatus()));
82 sb.append(String.format("\n\tDeviceId: %s", ByteUtil.toString(getDeviceId())));