/**
 * Copyright (c) 2010-2019 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.binding.rfxcom.internal.messages;

import static org.junit.Assert.assertEquals;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.util.HexUtils;
import org.junit.Test;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.messages.RFXComCurrentMessage.SubType;

/**
 * Test for RFXCom-binding
 *
 * @author Martin van Wingerden - Initial Contribution
 */
@NonNullByDefault
public class RFXComCurrentMessageTest {

    @Test
    public void testSomeMessages() throws RFXComException {
        String message = "0D59010F860004001D0000000049";

        final RFXComCurrentMessage msg = (RFXComCurrentMessage) RFXComMessageFactory
                .createMessage(HexUtils.hexToBytes(message));
        assertEquals("SubType", SubType.ELEC1, msg.subType);
        assertEquals("Seq Number", 15, (short) (msg.seqNbr & 0xFF));
        assertEquals("Sensor Id", "34304", msg.getDeviceId());
        assertEquals("Count", 4, msg.count);
        assertEquals("Channel 1", 2.9d, msg.channel1Amps, 0.01);
        assertEquals("Channel 2", 0d, msg.channel2Amps, 0.01);
        assertEquals("Channel 3", 0d, msg.channel3Amps, 0.01);
        assertEquals("Signal Level", 4, msg.signalLevel);
        assertEquals("Battery Level", 9, msg.batteryLevel);

        byte[] decoded = msg.decodeMessage();

        assertEquals("Message converted back", message, HexUtils.bytesToHex(decoded));
    }
}
