]> git.basschouten.com Git - openhab-addons.git/blob
1dde132c4cfb3e7267538f3a7b4aeab1a804a39d
[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.liquidcheck.internal.json;
14
15 import static org.openhab.binding.liquidcheck.internal.LiquidCheckBindingConstants.PROPERTY_HOSTNAME;
16 import static org.openhab.binding.liquidcheck.internal.LiquidCheckBindingConstants.PROPERTY_IP;
17 import static org.openhab.binding.liquidcheck.internal.LiquidCheckBindingConstants.PROPERTY_NAME;
18 import static org.openhab.binding.liquidcheck.internal.LiquidCheckBindingConstants.PROPERTY_SECURITY_CODE;
19 import static org.openhab.binding.liquidcheck.internal.LiquidCheckBindingConstants.PROPERTY_SSID;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.openhab.core.thing.Thing;
26
27 /**
28  * The {@link CommData} is used for serializing and deserializing of JSONs.
29  * It contains the complete communication data with header and payload or context.
30  *
31  * @author Marcel Goerentz - Initial contribution
32  */
33
34 @NonNullByDefault
35 public class CommData {
36
37     public Header header = new Header();
38     public Payload payload = new Payload();
39     public Context context = new Context();
40
41     public Map<String, String> createPropertyMap() {
42         Map<String, String> properties = new HashMap<>();
43         properties.put(Thing.PROPERTY_FIRMWARE_VERSION, payload.device.firmware);
44         properties.put(Thing.PROPERTY_HARDWARE_VERSION, payload.device.hardware);
45         properties.put(PROPERTY_NAME, payload.device.name);
46         properties.put(Thing.PROPERTY_VENDOR, payload.device.manufacturer);
47         properties.put(Thing.PROPERTY_SERIAL_NUMBER, payload.device.uuid);
48         properties.put(PROPERTY_SECURITY_CODE, payload.device.security.code);
49         properties.put(PROPERTY_IP, payload.wifi.station.ip);
50         properties.put(Thing.PROPERTY_MAC_ADDRESS, payload.wifi.station.mac);
51         properties.put(PROPERTY_SSID, payload.wifi.accessPoint.ssid);
52         return properties;
53     }
54
55     public Map<String, Object> createPropertyMap(boolean isHostname) {
56         Map<String, Object> properties = new HashMap<>(createPropertyMap());
57         if (isHostname) {
58             properties.put(PROPERTY_HOSTNAME, payload.wifi.station.hostname);
59         } else {
60             properties.put(PROPERTY_HOSTNAME, payload.wifi.station.ip);
61         }
62         return properties;
63     }
64 }