]> git.basschouten.com Git - openhab-addons.git/blob
1d5fccff495bbd417685687a0faad2437df91d13
[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.onewire.internal;
14
15 import java.util.Collections;
16 import java.util.HashSet;
17 import java.util.Map;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.onewire.internal.device.OwChannelConfig;
24 import org.openhab.binding.onewire.internal.device.OwSensorType;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.type.ChannelTypeUID;
27
28 /**
29  * The {@link OneWireBinding} class defines common constants, which are
30  * used across the whole binding.
31  *
32  * @author Jan N. Klug - Initial contribution
33  */
34 @NonNullByDefault
35 public class OwBindingConstants {
36     public static final String BINDING_ID = "onewire";
37
38     // List of all Thing Type UIDs
39     public static final ThingTypeUID THING_TYPE_OWSERVER = new ThingTypeUID(BINDING_ID, "owserver");
40     public static final ThingTypeUID THING_TYPE_MS_TX = new ThingTypeUID(BINDING_ID, "ms-tx");
41     public static final ThingTypeUID THING_TYPE_BMS = new ThingTypeUID(BINDING_ID, "bms");
42     public static final ThingTypeUID THING_TYPE_AMS = new ThingTypeUID(BINDING_ID, "ams");
43     public static final ThingTypeUID THING_TYPE_BASIC = new ThingTypeUID(BINDING_ID, "basic");
44     public static final ThingTypeUID THING_TYPE_EDS_ENV = new ThingTypeUID(BINDING_ID, "edsenv");
45     public static final ThingTypeUID THING_TYPE_BAE091X = new ThingTypeUID(BINDING_ID, "bae091x");
46
47     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections
48             .unmodifiableSet(Stream.of(THING_TYPE_OWSERVER, THING_TYPE_AMS, THING_TYPE_BMS, THING_TYPE_MS_TX,
49                     THING_TYPE_EDS_ENV, THING_TYPE_BASIC, THING_TYPE_BAE091X).collect(Collectors.toSet()));
50
51     // List of all config options
52     public static final String CONFIG_ADDRESS = "network-address";
53     public static final String CONFIG_PORT = "port";
54
55     public static final String CONFIG_ID = "id";
56     public static final String CONFIG_RESOLUTION = "resolution";
57     public static final String CONFIG_IGNORE_POR = "ignorepor";
58     public static final String CONFIG_REFRESH = "refresh";
59     public static final String CONFIG_DIGITALREFRESH = "digitalrefresh";
60     public static final String CONFIG_OFFSET = "offset";
61     public static final String CONFIG_HUMIDITY = "humiditytype";
62     public static final String CONFIG_DIGITAL_MODE = "mode";
63     public static final String CONFIG_DIGITAL_LOGIC = "logic";
64     public static final String CONFIG_TEMPERATURESENSOR = "temperaturesensor";
65     public static final String CONFIG_LIGHTSENSOR = "lightsensor";
66     public static final String CONFIG_BAE_PIN_DISABLED = "disabled";
67     public static final String CONFIG_BAE_PIN_PIO = "pio";
68     public static final String CONFIG_BAE_PIN_COUNTER = "counter";
69     public static final String CONFIG_BAE_PIN_PWM = "pwm";
70     public static final String CONFIG_BAE_PIN_ANALOG = "analog";
71     public static final String CONFIG_BAE_PIN_IN = "input";
72     public static final String CONFIG_BAE_PIN_OUT = "output";
73
74     // list of all properties
75     public static final String PROPERTY_MODELID = "modelId";
76     public static final String PROPERTY_VENDOR = "vendor";
77     public static final String PROPERTY_SENSORCOUNT = "sensorCount";
78     public static final String PROPERTY_PROD_DATE = "prodDate";
79     public static final String PROPERTY_HW_REVISION = "hwRevision";
80
81     // List of all channel ids
82     public static final String CHANNEL_HUMIDITY = "humidity";
83     public static final String CHANNEL_ABSOLUTE_HUMIDITY = "absolutehumidity";
84     public static final String CHANNEL_DEWPOINT = "dewpoint";
85     public static final String CHANNEL_PRESENT = "present";
86     public static final String CHANNEL_TEMPERATURE = "temperature";
87     public static final String CHANNEL_LIGHT = "light";
88     public static final String CHANNEL_SUPPLYVOLTAGE = "supplyvoltage";
89     public static final String CHANNEL_VOLTAGE = "voltage";
90     public static final String CHANNEL_CURRENT = "current";
91     public static final String CHANNEL_PRESSURE = "pressure";
92     public static final String CHANNEL_DIGITAL = "digital";
93     public static final String CHANNEL_DIGITAL0 = "digital0";
94     public static final String CHANNEL_DIGITAL1 = "digital1";
95     public static final String CHANNEL_DIGITAL2 = "digital2";
96     public static final String CHANNEL_DIGITAL3 = "digital3";
97     public static final String CHANNEL_DIGITAL4 = "digital4";
98     public static final String CHANNEL_DIGITAL5 = "digital5";
99     public static final String CHANNEL_DIGITAL6 = "digital6";
100     public static final String CHANNEL_DIGITAL7 = "digital7";
101     public static final String CHANNEL_DIGITAL8 = "digital8";
102     public static final String CHANNEL_COUNTER = "counter";
103     public static final String CHANNEL_COUNTER0 = "counter0";
104     public static final String CHANNEL_COUNTER1 = "counter1";
105     public static final String CHANNEL_PWM_DUTY1 = "pwmduty1";
106     public static final String CHANNEL_PWM_DUTY2 = "pwmduty2";
107     public static final String CHANNEL_PWM_DUTY3 = "pwmduty3";
108     public static final String CHANNEL_PWM_DUTY4 = "pwmduty4";
109     public static final String CHANNEL_PWM_FREQ1 = "pwmfreq1";
110     public static final String CHANNEL_PWM_FREQ2 = "pwmfreq2";
111
112     public static final ChannelTypeUID CHANNEL_TYPE_UID_ABSHUMIDITY = new ChannelTypeUID(BINDING_ID, "abshumidity");
113     public static final ChannelTypeUID CHANNEL_TYPE_UID_COUNTER = new ChannelTypeUID(BINDING_ID, "counter");
114     public static final ChannelTypeUID CHANNEL_TYPE_UID_CURRENT = new ChannelTypeUID(BINDING_ID, "current");
115     public static final ChannelTypeUID CHANNEL_TYPE_UID_DEWPOINT = new ChannelTypeUID(BINDING_ID, "dewpoint");
116     public static final ChannelTypeUID CHANNEL_TYPE_UID_DIO = new ChannelTypeUID(BINDING_ID, "dio");
117     public static final ChannelTypeUID CHANNEL_TYPE_UID_HUMIDITY = new ChannelTypeUID(BINDING_ID, "humidity");
118     public static final ChannelTypeUID CHANNEL_TYPE_UID_HUMIDITYCONF = new ChannelTypeUID(BINDING_ID, "humidityconf");
119     public static final ChannelTypeUID CHANNEL_TYPE_UID_LIGHT = new ChannelTypeUID(BINDING_ID, "light");
120     public static final ChannelTypeUID CHANNEL_TYPE_UID_PRESENT = new ChannelTypeUID(BINDING_ID, "present");
121     public static final ChannelTypeUID CHANNEL_TYPE_UID_PRESSURE = new ChannelTypeUID(BINDING_ID, "pressure");
122     public static final ChannelTypeUID CHANNEL_TYPE_UID_TEMPERATURE = new ChannelTypeUID(BINDING_ID, "temperature");
123     public static final ChannelTypeUID CHANNEL_TYPE_UID_TEMPERATURE_POR = new ChannelTypeUID(BINDING_ID,
124             "temperature-por");
125     public static final ChannelTypeUID CHANNEL_TYPE_UID_TEMPERATURE_POR_RES = new ChannelTypeUID(BINDING_ID,
126             "temperature-por-res");
127     public static final ChannelTypeUID CHANNEL_TYPE_UID_VOLTAGE = new ChannelTypeUID(BINDING_ID, "voltage");
128     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_ANALOG = new ChannelTypeUID(BINDING_ID, "bae-analog");
129     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_COUNTER = new ChannelTypeUID(BINDING_ID, "bae-counter");
130     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_DIGITAL_OUT = new ChannelTypeUID(BINDING_ID, "bae-do");
131     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_DIN = new ChannelTypeUID(BINDING_ID, "bae-in");
132     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_DOUT = new ChannelTypeUID(BINDING_ID, "bae-out");
133     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_PIO = new ChannelTypeUID(BINDING_ID, "bae-pio");
134     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_PWM_DUTY = new ChannelTypeUID(BINDING_ID, "bae-pwm-duty");
135     public static final ChannelTypeUID CHANNEL_TYPE_UID_BAE_PWM_FREQUENCY = new ChannelTypeUID(BINDING_ID,
136             "bae-pwm-frequency");
137
138     public static final ChannelTypeUID CHANNEL_TYPE_UID_OWFS_NUMBER = new ChannelTypeUID(BINDING_ID, "owfs-number");
139     public static final ChannelTypeUID CHANNEL_TYPE_UID_OWFS_STRING = new ChannelTypeUID(BINDING_ID, "owfs-string");
140
141     // Maps for Discovery
142     public static final Map<OwSensorType, ThingTypeUID> THING_TYPE_MAP;
143     public static final Map<OwSensorType, String> THING_LABEL_MAP;
144     public static final Map<OwSensorType, Set<OwChannelConfig>> SENSOR_TYPE_CHANNEL_MAP;
145
146     public static final Map<String, String> ACCEPTED_ITEM_TYPES_MAP = Util
147             .readPropertiesFile("accepted_itemtypes.properties");
148
149     static {
150         Map<String, String> properties = Util.readPropertiesFile("sensor.properties");
151         THING_TYPE_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".thingtype"))
152                 .collect(Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]),
153                         e -> new ThingTypeUID(BINDING_ID, e.getValue())));
154         SENSOR_TYPE_CHANNEL_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".channels"))
155                 .collect(Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]),
156                         e -> !e.getValue().isEmpty() ? Stream.of(e.getValue().split(","))
157                                 .map(c -> OwChannelConfig.fromString(c)).collect(Collectors.toSet())
158                                 : new HashSet<>()));
159         THING_LABEL_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".label")).collect(
160                 Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]), e -> e.getValue()));
161     }
162 }