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