2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.tplinksmarthome.internal;
15 import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.*;
18 import java.util.TreeMap;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType.DeviceType;
23 import org.openhab.binding.tplinksmarthome.internal.model.Sysinfo;
27 * @author Hilbrand Bouwkamp - Initial contribution
30 public final class PropertiesCollector {
32 private PropertiesCollector() {
37 * Collect all properties of the thing from the {@link Sysinfo} object.
39 * @param thingType thing to get the properties for
40 * @param ipAddress ip address of the device
41 * @param sysinfo system info data returned from the device
42 * @return map of properties
44 public static Map<String, Object> collectProperties(TPLinkSmartHomeThingType thingType, String ipAddress,
46 final Map<String, Object> properties = new TreeMap<>();
48 putNonNull(properties, CONFIG_IP, ipAddress);
49 if (thingType.getDeviceType() == DeviceType.RANGE_EXTENDER) {
50 collectPropertiesRangeExtender(properties, sysinfo);
52 collectProperties(properties, sysinfo);
53 if (thingType.getDeviceType() == DeviceType.BULB) {
54 collectPropertiesBulb(properties, sysinfo);
56 collectPropertiesOther(properties, sysinfo);
63 * Collect generic properties.
65 * @param properties properties object to store properties in
66 * @param sysinfo system info data returned from the device
68 private static void collectProperties(Map<String, Object> properties, Sysinfo sysinfo) {
69 putNonNull(properties, CONFIG_DEVICE_ID, sysinfo.getDeviceId());
70 putNonNull(properties, PROPERTY_MODEL, sysinfo.getModel());
71 putNonNull(properties, PROPERTY_HARDWARE_VERSION, sysinfo.getHwVer());
72 putNonNull(properties, PROPERTY_SOFWARE_VERSION, sysinfo.getSwVer());
73 putNonNull(properties, PROPERTY_HARDWARE_ID, sysinfo.getHwId());
74 putNonNull(properties, PROPERTY_OEM_ID, sysinfo.getOemId());
78 * Collect Smart Bulb specific properties.
80 * @param properties properties object to store properties in
81 * @param sysinfo system info data returned from the device
83 private static void collectPropertiesBulb(Map<String, Object> properties, Sysinfo sysinfo) {
84 putNonNull(properties, PROPERTY_TYPE, sysinfo.getType());
85 putNonNull(properties, PROPERTY_MAC, sysinfo.getMac());
86 putNonNull(properties, PROPERTY_PROTOCOL_NAME, sysinfo.getProtocolName());
87 putNonNull(properties, PROPERTY_PROTOCOL_VERSION, sysinfo.getProtocolVersion());
91 * Collect Smart Range Extender specific properties.
93 * @param properties properties object to store properties in
94 * @param sysinfo system info data returned from the device
96 private static void collectPropertiesRangeExtender(Map<String, Object> properties, Sysinfo sysinfo) {
97 final Sysinfo system = sysinfo.getSystem();
98 collectProperties(properties, system);
99 putNonNull(properties, PROPERTY_TYPE, system.getType());
100 putNonNull(properties, PROPERTY_MAC, system.getMac());
101 putNonNull(properties, PROPERTY_DEVICE_NAME, system.getDevName());
102 putNonNull(properties, PROPERTY_FEATURE, sysinfo.getPlug().getFeature());
106 * Collect Smart Switch specific properties.
108 * @param properties properties object to store properties in
109 * @param sysinfo system info data returned from the device
111 private static void collectPropertiesOther(Map<String, Object> properties, Sysinfo sysinfo) {
112 putNonNull(properties, PROPERTY_TYPE, sysinfo.getType());
113 putNonNull(properties, PROPERTY_MAC, sysinfo.getMac());
114 putNonNull(properties, PROPERTY_DEVICE_NAME, sysinfo.getDevName());
115 putNonNull(properties, PROPERTY_FIRMWARE_ID, sysinfo.getFwId());
116 putNonNull(properties, PROPERTY_FEATURE, sysinfo.getFeature());
119 private static void putNonNull(Map<String, Object> properties, String key, @Nullable String value) {
121 properties.put(key, value);