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.plugwise.internal.protocol;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.plugwise.internal.protocol.field.MessageType;
19 * Creates instances of messages received from the Plugwise network.
21 * @author Wouter Born, Karel Goderis - Initial contribution
24 public class MessageFactory {
26 public Message createMessage(MessageType messageType, int sequenceNumber, String payload)
27 throws IllegalArgumentException {
28 return switch (messageType) {
29 case ACKNOWLEDGEMENT_V1, ACKNOWLEDGEMENT_V2 ->
30 new AcknowledgementMessage(messageType, sequenceNumber, payload);
31 case ANNOUNCE_AWAKE_REQUEST -> new AnnounceAwakeRequestMessage(sequenceNumber, payload);
32 case BROADCAST_GROUP_SWITCH_RESPONSE -> new BroadcastGroupSwitchResponseMessage(sequenceNumber, payload);
33 case CLOCK_GET_RESPONSE -> new ClockGetResponseMessage(sequenceNumber, payload);
34 case DEVICE_INFORMATION_RESPONSE -> new InformationResponseMessage(sequenceNumber, payload);
35 case DEVICE_ROLE_CALL_RESPONSE -> new RoleCallResponseMessage(sequenceNumber, payload);
36 case MODULE_JOINED_NETWORK_REQUEST -> new ModuleJoinedNetworkRequestMessage(sequenceNumber, payload);
37 case NETWORK_STATUS_RESPONSE -> new NetworkStatusResponseMessage(sequenceNumber, payload);
38 case NODE_AVAILABLE -> new NodeAvailableMessage(sequenceNumber, payload);
39 case PING_RESPONSE -> new PingResponseMessage(sequenceNumber, payload);
40 case POWER_BUFFER_RESPONSE -> new PowerBufferResponseMessage(sequenceNumber, payload);
41 case POWER_CALIBRATION_RESPONSE -> new PowerCalibrationResponseMessage(sequenceNumber, payload);
42 case POWER_INFORMATION_RESPONSE -> new PowerInformationResponseMessage(sequenceNumber, payload);
43 case REAL_TIME_CLOCK_GET_RESPONSE -> new RealTimeClockGetResponseMessage(sequenceNumber, payload);
44 case SENSE_REPORT_REQUEST -> new SenseReportRequestMessage(sequenceNumber, payload);
45 default -> throw new IllegalArgumentException("Unsupported message type: " + messageType);