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.nibeheatpump.internal.message;
15 import org.openhab.binding.nibeheatpump.internal.NibeHeatPumpException;
16 import org.openhab.binding.nibeheatpump.internal.message.NibeHeatPumpBaseMessage.MessageType;
17 import org.openhab.binding.nibeheatpump.internal.protocol.NibeHeatPumpProtocol;
20 * The {@link MessageFactory} implements factory class to create Nibe protocol messages.
23 * @author Pauli Anttila - Initial contribution
25 public class MessageFactory {
27 public static NibeHeatPumpMessage getMessage(byte[] message) throws NibeHeatPumpException {
28 if (message != null) {
29 byte messageTypeByte = NibeHeatPumpProtocol.getMessageType(message);
30 MessageType messageType = NibeHeatPumpBaseMessage.getMessageType(messageTypeByte);
32 switch (messageType) {
33 case MODBUS_DATA_READ_OUT_MSG:
34 return new ModbusDataReadOutMessage(message);
35 case MODBUS_READ_REQUEST_MSG:
36 return new ModbusReadRequestMessage(message);
37 case MODBUS_READ_RESPONSE_MSG:
38 return new ModbusReadResponseMessage(message);
39 case MODBUS_WRITE_REQUEST_MSG:
40 return new ModbusWriteRequestMessage(message);
41 case MODBUS_WRITE_RESPONSE_MSG:
42 return new ModbusWriteResponseMessage(message);
48 throw new NibeHeatPumpException("Illegal message (null)");