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.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 switch (messageType) {
29 case ACKNOWLEDGEMENT_V1:
30 case ACKNOWLEDGEMENT_V2:
31 return new AcknowledgementMessage(messageType, sequenceNumber, payload);
32 case ANNOUNCE_AWAKE_REQUEST:
33 return new AnnounceAwakeRequestMessage(sequenceNumber, payload);
34 case BROADCAST_GROUP_SWITCH_RESPONSE:
35 return new BroadcastGroupSwitchResponseMessage(sequenceNumber, payload);
36 case CLOCK_GET_RESPONSE:
37 return new ClockGetResponseMessage(sequenceNumber, payload);
38 case DEVICE_INFORMATION_RESPONSE:
39 return new InformationResponseMessage(sequenceNumber, payload);
40 case DEVICE_ROLE_CALL_RESPONSE:
41 return new RoleCallResponseMessage(sequenceNumber, payload);
42 case MODULE_JOINED_NETWORK_REQUEST:
43 return new ModuleJoinedNetworkRequestMessage(sequenceNumber, payload);
44 case NETWORK_STATUS_RESPONSE:
45 return new NetworkStatusResponseMessage(sequenceNumber, payload);
47 return new NodeAvailableMessage(sequenceNumber, payload);
49 return new PingResponseMessage(sequenceNumber, payload);
50 case POWER_BUFFER_RESPONSE:
51 return new PowerBufferResponseMessage(sequenceNumber, payload);
52 case POWER_CALIBRATION_RESPONSE:
53 return new PowerCalibrationResponseMessage(sequenceNumber, payload);
54 case POWER_INFORMATION_RESPONSE:
55 return new PowerInformationResponseMessage(sequenceNumber, payload);
56 case REAL_TIME_CLOCK_GET_RESPONSE:
57 return new RealTimeClockGetResponseMessage(sequenceNumber, payload);
58 case SENSE_REPORT_REQUEST:
59 return new SenseReportRequestMessage(sequenceNumber, payload);
61 throw new IllegalArgumentException("Unsupported message type: " + messageType);