]> git.basschouten.com Git - openhab-addons.git/blob
2e432ba821259f507ecbc1c5b1783ce78d2aac25
[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.mynice.internal.xml.dto;
14
15 import java.util.List;
16 import java.util.stream.Stream;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * This enum lists all handled T4 commands
22  *
23  * @author GaĆ«l L'hopital - Initial contribution
24  */
25 @NonNullByDefault
26 public enum T4Command {
27     MDAx(1),
28     MDAy(2),
29     MDAz(3),
30     MDA0(4),
31     MDA1(5),
32     MDA2(6),
33     MDA3(7),
34     MDBi(11),
35     MDBj(12),
36     MDBk(13),
37     MDBl(14),
38     MDBm(15),
39     MDEw(16),
40     MDEx(17),
41     MDEy(18),
42     MDEz(19),
43     MDE0(20),
44     MDE1(21),
45     MDE2(22),
46     MDE3(23),
47     MDE4(24),
48     MDE5(25),
49     MDFh(26);
50
51     private int bitPosition;
52
53     private T4Command(int bitPosition) {
54         this.bitPosition = bitPosition;
55     }
56
57     public static T4Command fromCode(String commandCode) {
58         return Stream.of(T4Command.values()).filter(command -> command.name().equalsIgnoreCase(commandCode)).findFirst()
59                 .orElseThrow(() -> new IllegalArgumentException("Unknown T4 command code (%s)".formatted(commandCode)));
60     }
61
62     public static List<T4Command> fromBitmask(int bitmask) {
63         return Stream.of(T4Command.values()).filter(command -> ((1 << command.bitPosition) & bitmask) != 0).toList();
64     }
65 }