]> git.basschouten.com Git - openhab-addons.git/blob
3027b2131d69899e20ef483787ca5251b362693d
[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.enocean.internal.messages;
14
15 import java.util.stream.Stream;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  *
21  * @author Daniel Weber - Initial contribution
22  */
23 @NonNullByDefault
24 public class EventMessage extends BasePacket {
25
26     public enum EventMessageType {
27         UNKNOWN((byte) 0x00, 1),
28         SA_RECLAIM_NOT_SUCCESSFUL((byte) 0x01, 1),
29         SA_CONFIRM_LEARN((byte) 0x02, 17),
30         SA_LEARN_ACK((byte) 0x03, 4),
31         CO_READY((byte) 0x04, 2),
32         CO_EVENT_SECUREDEVICES((byte) 0x05, 6),
33         CO_DUTYCYCLE_LIMIT((byte) 0x06, 2),
34         CO_TRANSMIT_FAILED((byte) 0x07, 2);
35
36         private byte value;
37         private int dataLength;
38
39         EventMessageType(byte value, int dataLength) {
40             this.value = value;
41             this.dataLength = dataLength;
42         }
43
44         public byte getValue() {
45             return this.value;
46         }
47
48         public int getDataLength() {
49             return dataLength;
50         }
51
52         public static EventMessageType getEventMessageType(byte value) {
53             return Stream.of(EventMessageType.values()).filter(t -> t.value == value).findFirst().orElse(UNKNOWN);
54         }
55     }
56
57     private EventMessageType type;
58
59     EventMessage(int dataLength, int optionalDataLength, byte[] payload) {
60         super(dataLength, optionalDataLength, ESPPacketType.EVENT, payload);
61
62         type = EventMessageType.getEventMessageType(payload[0]);
63     }
64
65     public EventMessageType getEventMessageType() {
66         return type;
67     }
68 }