2 * Copyright (c) 2010-2024 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.insteon.internal.device;
15 import java.util.ArrayList;
16 import java.util.HashMap;
18 import java.util.Map.Entry;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
23 * The DeviceType class holds device type definitions that are read from
26 * @author Bernd Pfrommer - Initial contribution
27 * @author Rob Nielsen - Port to openHAB 2 insteon binding
30 public class DeviceType {
31 private String productKey;
32 private String model = "";
33 private String description = "";
34 private Map<String, String> features = new HashMap<>();
35 private Map<String, FeatureGroup> featureGroups = new HashMap<>();
40 * @param aProductKey the product key for this device type
42 public DeviceType(String aProductKey) {
43 productKey = aProductKey;
47 * Get supported features
49 * @return all features that this device type supports
51 public Map<String, String> getFeatures() {
56 * Get all feature groups
58 * @return all feature groups of this device type
60 public Map<String, FeatureGroup> getFeatureGroups() {
65 * Sets the descriptive model string
67 * @param aModel descriptive model string
69 public void setModel(String aModel) {
74 * Sets free text description
76 * @param aDesc free text description
78 public void setDescription(String aDesc) {
83 * Adds feature to this device type
85 * @param aKey the key (e.g. "switch") under which this feature can be referenced in the item binding config
86 * @param aFeatureName the name (e.g. "GenericSwitch") under which the feature has been defined
87 * @return false if feature was already there
89 public boolean addFeature(String aKey, String aFeatureName) {
90 if (features.containsKey(aKey)) {
93 features.put(aKey, aFeatureName);
98 * Adds feature group to device type
100 * @param aKey name of the feature group, which acts as key for lookup later
101 * @param fg feature group to add
102 * @return true if add succeeded, false if group was already there
104 public boolean addFeatureGroup(String aKey, FeatureGroup fg) {
105 if (features.containsKey(aKey)) {
108 featureGroups.put(aKey, fg);
113 public String toString() {
114 String s = "pk:" + productKey + "|model:" + model + "|desc:" + description + "|features";
115 for (Entry<String, String> f : features.entrySet()) {
116 s += ":" + f.getKey() + "=" + f.getValue();
119 for (Entry<String, FeatureGroup> f : featureGroups.entrySet()) {
120 s += ":" + f.getKey() + "=" + f.getValue();
126 * Class that reflects feature group association
128 * @author Bernd Pfrommer - Initial contribution
130 public static class FeatureGroup {
133 private ArrayList<String> fgFeatures = new ArrayList<>();
135 FeatureGroup(String name, String type) {
140 public void addFeature(String f) {
144 public ArrayList<String> getFeatures() {
148 public String getName() {
152 public String getType() {
157 public String toString() {
159 for (String g : fgFeatures) {
162 return (s.replaceAll(",$", ""));