Skip to content

Commit 87cab4e

Browse files
authored
Semantic Tags: Update system channel tags to match latest schema (openhab#4706)
* update tags to match xsd * use tag name constants * overload withTags() Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent e4cc912 commit 87cab4e

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed

bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/DefaultSystemChannelTypeProvider.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.eclipse.jdt.annotation.Nullable;
2525
import org.openhab.core.i18n.LocalizedKey;
2626
import org.openhab.core.library.CoreItemFactory;
27+
import org.openhab.core.semantics.model.DefaultSemanticTags.Point;
28+
import org.openhab.core.semantics.model.DefaultSemanticTags.Property;
2729
import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService;
2830
import org.openhab.core.thing.type.ChannelType;
2931
import org.openhab.core.thing.type.ChannelTypeBuilder;
@@ -50,6 +52,7 @@
5052
* @author Christoph Weitkamp - Added support for translation
5153
* @author Stefan Triller - Added more system channels
5254
* @author Christoph Weitkamp - factored out common i18n aspects into ThingTypeI18nLocalizationService
55+
* @author Andrew Fiddian-Green - Added system Point and Property tags
5356
*/
5457
@NonNullByDefault
5558
@Component
@@ -121,7 +124,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
121124
new StateOption("2", "average"), new StateOption("3", "good"),
122125
new StateOption("4", "excellent")))
123126
.build())
124-
.withTags(List.of("Measurement", "Level")).build();
127+
.withTags(Point.MEASUREMENT, Property.SIGNAL_STRENGTH).build();
125128

126129
/**
127130
* Low battery default system wide {@link ChannelType}. Represents a low battery warning with possible values
@@ -132,7 +135,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
132135
.withDescription("Low battery warning with possible values on (low battery) and off (battery ok)")
133136
.withCategory("LowBattery")
134137
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true).build())
135-
.withTags(List.of("LowBattery", "Energy")).build();
138+
.withTags(Point.ALARM, Property.LOW_BATTERY).build();
136139

137140
/**
138141
* Battery level default system wide {@link ChannelType}. Represents the battery level as a percentage.
@@ -143,7 +146,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
143146
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO)
144147
.withMaximum(new BigDecimal(100)).withStep(BigDecimal.ONE).withReadOnly(true).withPattern("%.0f %%")
145148
.build())
146-
.withTags(List.of("Measurement", "Energy")).build();
149+
.withTags(Point.MEASUREMENT, Property.ENERGY).build();
147150

148151
/**
149152
* System wide trigger {@link ChannelType} without event options.
@@ -188,7 +191,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
188191
public static final ChannelType SYSTEM_POWER = ChannelTypeBuilder
189192
.state(SYSTEM_CHANNEL_TYPE_UID_POWER, "Power", CoreItemFactory.SWITCH)
190193
.withDescription("Device is operable when channel has state ON").withCategory("Switch")
191-
.withTags(List.of("Switch", "Power")).build();
194+
.withTags(Point.SWITCH, Property.POWER).build();
192195

193196
/**
194197
* Location: default system wide {@link ChannelType} which displays a location
@@ -198,7 +201,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
198201
.withDescription("Location in lat./lon./height coordinates")
199202
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true)
200203
.withPattern("%2$s°N %3$s°E %1$sm").build())
201-
.withTag("Measurement").build();
204+
.withTags(Point.MEASUREMENT, Property.GEO_LOCATION).build();
202205

203206
/**
204207
* Motion: default system wide {@link ChannelType} which indications whether motion was detected (state ON)
@@ -207,7 +210,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
207210
.state(SYSTEM_CHANNEL_TYPE_UID_MOTION, "Motion", CoreItemFactory.SWITCH)
208211
.withDescription("Motion detected by the device").withCategory("Motion")
209212
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true).build())
210-
.withTags(List.of("Status", "Presence")).build();
213+
.withTags(Point.STATUS, Property.PRESENCE).build();
211214

212215
/**
213216
* Brightness: default system wide {@link ChannelType} which allows changing the brightness from 0-100%
@@ -217,15 +220,15 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
217220
.withDescription("Controls the brightness and switches the light on and off").withCategory("Light")
218221
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO)
219222
.withMaximum(new BigDecimal(100)).withPattern("%d %%").build())
220-
.withTags(List.of("Control", "Light")).build();
223+
.withTags(Point.CONTROL, Property.BRIGHTNESS).build();
221224

222225
/**
223226
* Color: default system wide {@link ChannelType} which allows changing the color
224227
*/
225228
public static final ChannelType SYSTEM_COLOR = ChannelTypeBuilder
226229
.state(SYSTEM_CHANNEL_TYPE_UID_COLOR, "Color", CoreItemFactory.COLOR)
227230
.withDescription("Controls the color of the light").withCategory("ColorLight")
228-
.withTags(List.of("Control", "Light")).build();
231+
.withTags(Point.CONTROL, Property.COLOR).build();
229232

230233
/**
231234
* Color-temperature: default system wide {@link ChannelType} which allows changing the color temperature in percent
@@ -236,7 +239,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
236239
.withCategory("ColorLight")
237240
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO)
238241
.withMaximum(new BigDecimal(100)).withPattern("%.0f").build())
239-
.withTags(List.of("Control", "ColorTemperature")).build();
242+
.withTags(Point.CONTROL, Property.COLOR_TEMPERATURE).build();
240243

241244
/**
242245
* Color-temperature: default system wide {@link ChannelType} which allows changing the color temperature in Kelvin
@@ -247,7 +250,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
247250
.withCategory("ColorLight").isAdvanced(true)
248251
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(1000))
249252
.withMaximum(new BigDecimal(10000)).withPattern("%.0f K").build())
250-
.withTags(List.of("Control", "ColorTemperature")).build();
253+
.withTags(Point.CONTROL, Property.COLOR_TEMPERATURE).build();
251254

252255
// media channels
253256

@@ -259,22 +262,22 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
259262
.withDescription("Change the sound volume of a device")
260263
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO)
261264
.withMaximum(new BigDecimal(100)).withPattern("%d %%").build())
262-
.withCategory("SoundVolume").withTags(List.of("Control", "SoundVolume")).build();
265+
.withCategory("SoundVolume").withTags(Point.CONTROL, Property.SOUND_VOLUME).build();
263266

264267
/**
265268
* Mute: default system wide {@link ChannelType} which allows muting and un-muting audio
266269
*/
267270
public static final ChannelType SYSTEM_MUTE = ChannelTypeBuilder
268271
.state(SYSTEM_CHANNEL_TYPE_UID_MUTE, "Mute", CoreItemFactory.SWITCH)
269272
.withDescription("Mute audio of the device").withCategory("SoundVolume_Mute")
270-
.withTags(List.of("Switch", "SoundVolume")).build();
273+
.withTags(Point.SWITCH, Property.SOUND_VOLUME).build();
271274

272275
/**
273276
* Media-control: system wide {@link ChannelType} which controls a media player
274277
*/
275278
public static final ChannelType SYSTEM_MEDIA_CONTROL = ChannelTypeBuilder
276279
.state(SYSTEM_CHANNEL_TYPE_UID_MEDIA_CONTROL, "Media Control", CoreItemFactory.PLAYER)
277-
.withCategory("MediaControl").withTag("Control").build();
280+
.withCategory("MediaControl").withTags(Point.CONTROL, Property.MEDIA_CONTROL).build();
278281

279282
/**
280283
* Media-title: default system wide {@link ChannelType} which displays the title of a (played) song
@@ -283,7 +286,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
283286
.state(SYSTEM_CHANNEL_TYPE_UID_MEDIA_TITLE, "Media Title", CoreItemFactory.STRING)
284287
.withDescription("Title of a (played) media file")
285288
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true).build())
286-
.withTag("Status").build();
289+
.withTags(Point.STATUS).build();
287290

288291
/**
289292
* Media-artist: default system wide {@link ChannelType} which displays the artist of a (played) song
@@ -292,7 +295,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
292295
.state(SYSTEM_CHANNEL_TYPE_UID_MEDIA_ARTIST, "Media Artist", CoreItemFactory.STRING)
293296
.withDescription("Artist of a (played) media file")
294297
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withReadOnly(true).build())
295-
.withTag("Status").build();
298+
.withTags(Point.STATUS).build();
296299

297300
// weather channels
298301

@@ -304,7 +307,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
304307
.withDescription("Current wind direction expressed as an angle").withCategory("Wind")
305308
.withStateDescriptionFragment(StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.ZERO)
306309
.withMaximum(new BigDecimal(360)).withReadOnly(true).withPattern("%.0f %unit%").build())
307-
.withTags(List.of("Measurement", "Wind")).build();
310+
.withTags(Point.MEASUREMENT, Property.WIND).build();
308311

309312
/**
310313
* Wind-speed: system wide {@link ChannelType} which shows the wind speed
@@ -314,7 +317,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
314317
.withDescription("Current wind speed").withCategory("Wind")
315318
.withStateDescriptionFragment(
316319
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
317-
.withTags(List.of("Measurement", "Wind")).build();
320+
.withTags(Point.MEASUREMENT, Property.WIND).build();
318321

319322
/**
320323
* Outdoor-temperature: system wide {@link ChannelType} which shows the outdoor temperature
@@ -324,7 +327,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
324327
.withDescription("Current outdoor temperature").withCategory("Temperature")
325328
.withStateDescriptionFragment(
326329
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
327-
.withTags(List.of("Measurement", "Temperature")).build();
330+
.withTags(Point.MEASUREMENT, Property.TEMPERATURE).build();
328331

329332
/**
330333
* Indoor-temperature: system wide {@link ChannelType} which shows the indoor temperature
@@ -334,7 +337,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
334337
.withDescription("Current indoor temperature").withCategory("Temperature")
335338
.withStateDescriptionFragment(
336339
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
337-
.withTags(List.of("Measurement", "Temperature")).build();
340+
.withTags(Point.MEASUREMENT, Property.TEMPERATURE).build();
338341

339342
/**
340343
* Atmospheric-humidity: system wide {@link ChannelType} which shows the atmospheric humidity
@@ -344,7 +347,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
344347
.withUnitHint("%").withDescription("Current atmospheric relative humidity").withCategory("Humidity")
345348
.withStateDescriptionFragment(
346349
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.0f %%").build())
347-
.withTags(List.of("Measurement", "Humidity")).build();
350+
.withTags(Point.MEASUREMENT, Property.HUMIDITY).build();
348351

349352
/**
350353
* Barometric-pressure: system wide {@link ChannelType} which shows the barometric pressure
@@ -354,7 +357,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
354357
.withDescription("Current barometric pressure").withCategory("Pressure")
355358
.withStateDescriptionFragment(
356359
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.3f %unit%").build())
357-
.withTags(List.of("Measurement", "Pressure")).build();
360+
.withTags(Point.MEASUREMENT, Property.PRESSURE).build();
358361

359362
// Energy
360363

@@ -366,7 +369,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
366369
.withDescription("Current electric power").withCategory("Energy")
367370
.withStateDescriptionFragment(
368371
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
369-
.withTags(List.of("Measurement", "Power")).build();
372+
.withTags(Point.MEASUREMENT, Property.POWER).build();
370373

371374
/**
372375
* Electric-current: system wide {@link ChannelType} which shows the electric current
@@ -376,7 +379,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
376379
.withDescription("Current electric current").withCategory("Energy")
377380
.withStateDescriptionFragment(
378381
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
379-
.withTags(List.of("Measurement", "Current")).build();
382+
.withTags(Point.MEASUREMENT, Property.CURRENT).build();
380383

381384
/**
382385
* Electric-voltage: system wide {@link ChannelType} which shows the electric voltage
@@ -386,7 +389,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
386389
.withDescription("Current electric voltage").withCategory("Energy")
387390
.withStateDescriptionFragment(
388391
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
389-
.withTags(List.of("Measurement", "Voltage")).build();
392+
.withTags(Point.MEASUREMENT, Property.VOLTAGE).build();
390393

391394
/**
392395
* Electrical-energy: system wide {@link ChannelType} which shows the electrical energy
@@ -396,7 +399,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
396399
.withDescription("Current electric energy").withCategory("Energy")
397400
.withStateDescriptionFragment(
398401
StateDescriptionFragmentBuilder.create().withReadOnly(true).withPattern("%.1f %unit%").build())
399-
.withTags(List.of("Measurement", "Energy")).build();
402+
.withTags(Point.MEASUREMENT, Property.ENERGY).build();
400403

401404
/**
402405
* UV Index: system wide {@link ChannelType} which shows the UV Index
@@ -405,7 +408,7 @@ public class DefaultSystemChannelTypeProvider implements ChannelTypeProvider {
405408
.state(SYSTEM_CHANNEL_TYPE_UID_UV_INDEX, "UV Index", CoreItemFactory.NUMBER)
406409
.withDescription("Current UV index").withStateDescriptionFragment(StateDescriptionFragmentBuilder.create()
407410
.withReadOnly(true).withPattern("%d").withMinimum(BigDecimal.ONE).build())
408-
.withTags(List.of("Measurement", "Ultraviolet")).build();
411+
.withTags(Point.MEASUREMENT, Property.ULTRAVIOLET).build();
409412

410413
private static final Collection<ChannelType> CHANNEL_TYPES = List.of(SYSTEM_CHANNEL_SIGNAL_STRENGTH,
411414
SYSTEM_CHANNEL_LOW_BATTERY, SYSTEM_CHANNEL_BATTERY_LEVEL, SYSTEM_TRIGGER, SYSTEM_RAWBUTTON, SYSTEM_BUTTON,

bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/type/AbstractChannelTypeBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import java.util.Collection;
1717
import java.util.HashSet;
1818
import java.util.Set;
19+
import java.util.stream.Stream;
1920

2021
import org.eclipse.jdt.annotation.NonNull;
2122
import org.eclipse.jdt.annotation.NonNullByDefault;
2223
import org.eclipse.jdt.annotation.Nullable;
24+
import org.openhab.core.semantics.SemanticTag;
2325
import org.openhab.core.thing.type.ChannelType;
2426
import org.openhab.core.thing.type.ChannelTypeBuilder;
2527
import org.openhab.core.thing.type.ChannelTypeUID;
@@ -80,6 +82,12 @@ public T withTags(Collection<String> tags) {
8082
return (T) this;
8183
}
8284

85+
@Override
86+
public T withTags(SemanticTag... tags) {
87+
this.tags.addAll(Stream.of(tags).map(t -> t.getName()).toList());
88+
return (T) this;
89+
}
90+
8391
@Override
8492
public T withConfigDescriptionURI(URI configDescriptionURI) {
8593
this.configDescriptionURI = configDescriptionURI;

bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/type/ChannelTypeBuilder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.eclipse.jdt.annotation.NonNull;
1919
import org.eclipse.jdt.annotation.NonNullByDefault;
20+
import org.openhab.core.semantics.SemanticTag;
2021
import org.openhab.core.thing.internal.type.StateChannelTypeBuilderImpl;
2122
import org.openhab.core.thing.internal.type.TriggerChannelTypeBuilderImpl;
2223

@@ -60,13 +61,21 @@ public interface ChannelTypeBuilder<@NonNull T extends ChannelTypeBuilder<T>> {
6061
T withTag(String tag);
6162

6263
/**
63-
* Sets the StateDescription for the ChannelType
64+
* Sets the Tags for the ChannelType
6465
*
6566
* @param tags Collection of tags to be added to the ChannelType
6667
* @return this Builder
6768
*/
6869
T withTags(Collection<String> tags);
6970

71+
/**
72+
* Sets the Tags for the ChannelType
73+
*
74+
* @param tags Collection of tags to be added to the ChannelType
75+
* @return this Builder
76+
*/
77+
T withTags(SemanticTag... tags);
78+
7079
/**
7180
* Sets the ConfigDescriptionURI for the ChannelType
7281
*

0 commit comments

Comments
 (0)