]> git.basschouten.com Git - openhab-addons.git/blob
4c1c3d43e7401c8e01f87aaf0bc657d1449d14de
[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     @SerializedName("IsThisDevice")
73     public boolean isThisDevice;
74
75     public class FirmwareImage {
76         @SerializedName("Firmware")
77         public Firmware firmware;
78         @SerializedName("Installed")
79         public ProjectTimestamp installed;
80     }
81
82     public class Firmware {
83         @SerializedName("DisplayName")
84         public String displayName;
85     }
86
87     public class RepeaterProperties {
88         @SerializedName("IsRepeater")
89         public boolean isRepeater;
90     }
91
92     public Device() {
93     }
94
95     public int getDevice() {
96         return hrefNumber(DEVICE_HREF_PATTERN, href);
97     }
98
99     /**
100      * Returns the zone number of the first zone listed in LocalZones.
101      * Currently devices should only have one zone listed.
102      */
103     public int getZone() {
104         if (localZones != null && localZones.length > 0) {
105             return hrefNumber(ZONE_HREF_PATTERN, localZones[0].href);
106         } else {
107             return 0;
108         }
109     }
110
111     public String getFullyQualifiedName() {
112         if (fullyQualifiedName != null && fullyQualifiedName.length > 0) {
113             return String.join(" ", fullyQualifiedName);
114         } else {
115             return "";
116         }
117     }
118 }