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.mqtt.homie.internal.homie300;
16 import java.util.TreeMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.mqtt.generic.mapping.AbstractMqttAttributeClass;
20 import org.openhab.binding.mqtt.generic.mapping.MQTTvalueTransform;
21 import org.openhab.binding.mqtt.generic.mapping.TopicPrefix;
24 * Homie 3.x Property attributes
26 * @author David Graeff - Initial contribution
30 public class PropertyAttributes extends AbstractMqttAttributeClass {
31 // Lower-case enum value names required. Those are identifiers for the MQTT/homie protocol.
32 public enum DataTypeEnum {
43 public String name = "";
46 * stateful + non-settable: The node publishes a property state (temperature sensor)
47 * stateful + settable: The node publishes a property state, and can receive commands for the property (by
48 * controller or other party) (lamp power)
49 * stateless + non-settable: The node publishes momentary events (door bell pressed)
50 * stateless + settable: The node publishes momentary events, and can receive commands for the property (by
51 * controller or other party) (brew coffee)
53 public boolean settable = false;
54 public boolean retained = true;
55 public String unit = "";
56 public @MQTTvalueTransform(suffix = "_") DataTypeEnum datatype = DataTypeEnum.unknown;
57 public String format = "";
60 public Object getFieldsOf() {
65 * Return a map with all field values.
67 public Map<String, Object> asMap() {
68 Map<String, Object> properties = new TreeMap<>();
69 properties.put("unit", unit);
70 properties.put("name", name);
71 properties.put("settable", settable ? "true" : "false");
72 properties.put("retained", retained ? "true" : "false");
73 properties.put("format", format);
74 properties.put("datatype", datatype.name());