]> git.basschouten.com Git - openhab-addons.git/blob
646b0b3df30dc991ed9957dcacf11cb7870ff2fb
[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.regex.Pattern;
16
17 import org.openhab.binding.lutron.internal.protocol.leap.AbstractMessageBody;
18
19 import com.google.gson.annotations.SerializedName;
20
21 /**
22  * LEAP Device Object
23  *
24  * @author Bob Adair - Initial contribution
25  */
26 public class Device extends AbstractMessageBody {
27     public static final Pattern DEVICE_HREF_PATTERN = Pattern.compile("/device/([0-9]+)");
28     private static final Pattern ZONE_HREF_PATTERN = Pattern.compile("/zone/([0-9]+)");
29
30     @SerializedName("href")
31     public String href;
32
33     @SerializedName("Name")
34     public String name;
35
36     @SerializedName("FullyQualifiedName")
37     public String[] fullyQualifiedName;
38
39     @SerializedName("Parent")
40     public Href parent = new Href();
41
42     @SerializedName("SerialNumber")
43     public String serialNumber;
44
45     @SerializedName("ModelNumber")
46     public String modelNumber;
47
48     @SerializedName("DeviceType")
49     public String deviceType;
50
51     @SerializedName("LocalZones")
52     public Href[] localZones;
53
54     @SerializedName("AssociatedArea")
55     public Href associatedArea = new Href();
56
57     @SerializedName("OccupancySensors")
58     public Href[] occupancySensors;
59
60     @SerializedName("LinkNodes")
61     public Href[] linkNodes;
62
63     @SerializedName("DeviceRules")
64     public Href[] deviceRules;
65
66     @SerializedName("RepeaterProperties")
67     public RepeaterProperties repeaterProperties;
68
69     @SerializedName("FirmwareImage")
70     public FirmwareImage firmwareImage;
71
72     public class FirmwareImage {
73         @SerializedName("Firmware")
74         public Firmware firmware;
75         @SerializedName("Installed")
76         public Installed installed;
77     }
78
79     public class Firmware {
80         @SerializedName("DisplayName")
81         public String displayName;
82     }
83
84     public class Installed {
85         @SerializedName("Year")
86         public int year;
87         @SerializedName("Month")
88         public int month;
89         @SerializedName("Day")
90         public int day;
91         @SerializedName("Hour")
92         public int hour;
93         @SerializedName("Minute")
94         public int minute;
95         @SerializedName("Second")
96         public int second;
97         @SerializedName("Utc")
98         public String utc;
99     }
100
101     public class RepeaterProperties {
102         @SerializedName("IsRepeater")
103         public boolean isRepeater;
104     }
105
106     public Device() {
107     }
108
109     public int getDevice() {
110         return hrefNumber(DEVICE_HREF_PATTERN, href);
111     }
112
113     /**
114      * Returns the zone number of the first zone listed in LocalZones.
115      * Currently devices should only have one zone listed.
116      */
117     public int getZone() {
118         if (localZones != null && localZones.length > 0) {
119             return hrefNumber(ZONE_HREF_PATTERN, localZones[0].href);
120         } else {
121             return 0;
122         }
123     }
124
125     public String getFullyQualifiedName() {
126         if (fullyQualifiedName != null && fullyQualifiedName.length > 0) {
127             return String.join(" ", fullyQualifiedName);
128         } else {
129             return "";
130         }
131     }
132 }