]> git.basschouten.com Git - openhab-addons.git/blob
5d5d0f20cf8be1cefde05bbc21614e99d9d77e76
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.plugwise.internal.protocol;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.plugwise.internal.protocol.field.MessageType;
17
18 /**
19  * Creates instances of messages received from the Plugwise network.
20  *
21  * @author Wouter Born, Karel Goderis - Initial contribution
22  */
23 @NonNullByDefault
24 public class MessageFactory {
25
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);
46             case NODE_AVAILABLE:
47                 return new NodeAvailableMessage(sequenceNumber, payload);
48             case PING_RESPONSE:
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);
60             default:
61                 throw new IllegalArgumentException("Unsupported message type: " + messageType);
62         }
63     }
64 }