]> git.basschouten.com Git - openhab-addons.git/blob
53096c078a3ff80545d6d12e80da501fb480df57
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.mqtt.homie.internal.homie300;
14
15 import java.util.Map;
16 import java.util.TreeMap;
17
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;
22
23 /**
24  * Homie 3.x Property attributes
25  *
26  * @author David Graeff - Initial contribution
27  */
28 @NonNullByDefault
29 @TopicPrefix
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 {
33         unknown,
34         integer_,
35         float_,
36         boolean_,
37         string_,
38         enum_,
39         color_
40     }
41
42     public String name = "";
43
44     /**
45      * stateful + non-settable: The node publishes a property state (temperature sensor)
46      * stateful + settable: The node publishes a property state, and can receive commands for the property (by
47      * controller or other party) (lamp power)
48      * stateless + non-settable: The node publishes momentary events (door bell pressed)
49      * stateless + settable: The node publishes momentary events, and can receive commands for the property (by
50      * controller or other party) (brew coffee)
51      */
52     public boolean settable = false;
53     public boolean retained = true;
54     public String unit = "";
55     public @MQTTvalueTransform(suffix = "_") DataTypeEnum datatype = DataTypeEnum.unknown;
56     public String format = "";
57
58     @Override
59     public Object getFieldsOf() {
60         return this;
61     }
62
63     /**
64      * Return a map with all field values.
65      */
66     public Map<String, Object> asMap() {
67         Map<String, Object> properties = new TreeMap<>();
68         properties.put("unit", unit);
69         properties.put("name", name);
70         properties.put("settable", settable ? "true" : "false");
71         properties.put("retained", retained ? "true" : "false");
72         properties.put("format", format);
73         properties.put("datatype", datatype.name());
74         return properties;
75     }
76 }