]> git.basschouten.com Git - openhab-addons.git/blob
3636e40a92231c5029e6eaa0d1a30b7d12e70c5e
[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.lutron.internal.protocol.leap.dto;
14
15 import java.util.LinkedList;
16 import java.util.List;
17 import java.util.regex.Pattern;
18
19 import org.openhab.binding.lutron.internal.protocol.leap.AbstractMessageBody;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * LEAP ButtonGroup Object
25  *
26  * @author Bob Adair - Initial contribution
27  */
28 public class ButtonGroup extends AbstractMessageBody {
29     public static final Pattern BUTTONGROUP_HREF_PATTERN = Pattern.compile("/buttongroup/([0-9]+)");
30     public static final Pattern BUTTON_HREF_PATTERN = Pattern.compile("/button/([0-9]+)");
31
32     @SerializedName("href")
33     public String href;
34     @SerializedName("Parent") // device href
35     public Href parent = new Href();
36     @SerializedName("Buttons")
37     public Href[] buttons;
38     @SerializedName("AffectedZones")
39     public AffectedZone[] affectedZones;
40     @SerializedName("SortOrder")
41     public Integer sortOrder;
42     @SerializedName("StopIfMoving")
43     public String stopIfMoving; // Enabled or Disabled
44     @SerializedName("ProgrammingType")
45     public String programmingType; // Column
46
47     public ButtonGroup() {
48     }
49
50     public int getButtonGroup() {
51         return hrefNumber(BUTTONGROUP_HREF_PATTERN, href);
52     }
53
54     public int getParentDevice() {
55         if (parent != null && parent.href != null) {
56             return hrefNumber(Device.DEVICE_HREF_PATTERN, parent.href);
57         } else {
58             return 0;
59         }
60     }
61
62     public List<Integer> getButtonList() {
63         LinkedList<Integer> buttonNumList = new LinkedList<>();
64         for (Href button : buttons) {
65             int buttonNum = hrefNumber(BUTTON_HREF_PATTERN, button.href);
66             buttonNumList.add(buttonNum);
67         }
68         return buttonNumList;
69     }
70 }