]> git.basschouten.com Git - openhab-addons.git/blob
0aa78d6d9aac941e95f10d5cbe62e769c0611df0
[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.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         datetime_
41     }
42
43     public String name = "";
44
45     /**
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)
52      */
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 = "";
58
59     @Override
60     public Object getFieldsOf() {
61         return this;
62     }
63
64     /**
65      * Return a map with all field values.
66      */
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());
75         return properties;
76     }
77 }