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