]> git.basschouten.com Git - openhab-addons.git/blob
c8d33111c3aa3ea29cc2b18f93eeee989807eb5b
[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.miele.internal.api.dto;
14
15 import org.openhab.binding.miele.internal.FullyQualifiedApplianceIdentifier;
16 import org.openhab.binding.miele.internal.MieleBindingConstants;
17
18 import com.google.gson.JsonArray;
19 import com.google.gson.JsonElement;
20 import com.google.gson.JsonObject;
21
22 /**
23  * The {@link HomeDevice} class represents the HomeDevice node in the response JSON.
24  *
25  * @author Jacob Laursen - Initial contribution
26  **/
27 public class HomeDevice {
28
29     private static final String MIELE_APPLIANCE_CLASS = "com.miele.xgw3000.gateway.hdm.deviceclasses.MieleAppliance";
30
31     public String Name;
32     public String Status;
33     public String ParentUID;
34     public String ProtocolAdapterName;
35     public String Vendor;
36     public String UID;
37     public String Type;
38     public JsonArray DeviceClasses;
39     public String Version;
40     public String TimestampAdded;
41     public JsonObject Error;
42     public JsonObject Properties;
43
44     public HomeDevice() {
45     }
46
47     public FullyQualifiedApplianceIdentifier getApplianceIdentifier() {
48         return new FullyQualifiedApplianceIdentifier(this.UID);
49     }
50
51     public String getSerialNumber() {
52         return Properties.get("serial.number").getAsString();
53     }
54
55     public String getFirmwareVersion() {
56         return Properties.get("firmware.version").getAsString();
57     }
58
59     public String getRemoteUid() {
60         JsonElement remoteUid = Properties.get("remote.uid");
61         if (remoteUid == null) {
62             // remote.uid and serial.number seems to be the same. If remote.uid
63             // is missing for some reason, it makes sense to provide fallback
64             // to serial number.
65             return getSerialNumber();
66         }
67         return remoteUid.getAsString();
68     }
69
70     public String getConnectionType() {
71         JsonElement connectionType = Properties.get("connection.type");
72         if (connectionType == null) {
73             return null;
74         }
75         return connectionType.getAsString();
76     }
77
78     public String getConnectionBaudRate() {
79         JsonElement baudRate = Properties.get("connection.baud.rate");
80         if (baudRate == null) {
81             return null;
82         }
83         return baudRate.getAsString();
84     }
85
86     public String getApplianceModel() {
87         JsonElement model = Properties.get("miele.model");
88         if (model == null) {
89             return "";
90         }
91         return model.getAsString();
92     }
93
94     public String getDeviceClass() {
95         for (JsonElement dc : DeviceClasses) {
96             String dcStr = dc.getAsString();
97             if (dcStr.contains(MieleBindingConstants.MIELE_CLASS) && !dcStr.equals(MIELE_APPLIANCE_CLASS)) {
98                 return dcStr.substring(MieleBindingConstants.MIELE_CLASS.length());
99             }
100         }
101         return null;
102     }
103 }