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.jeelink.internal;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
19 import org.openhab.binding.jeelink.internal.ec3k.Ec3kSensorDefinition;
20 import org.openhab.binding.jeelink.internal.lacrosse.LaCrosseSensorDefinition;
21 import org.openhab.binding.jeelink.internal.lacrosse.LgwSensorDefinition;
22 import org.openhab.binding.jeelink.internal.lacrosse.Tx22SensorDefinition;
23 import org.openhab.binding.jeelink.internal.pca301.Pca301SensorDefinition;
24 import org.openhab.binding.jeelink.internal.revolt.RevoltSensorDefinition;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.binding.ThingHandler;
30 * Base class for sensor definitions.
32 * @author Volker Bier - Initial contribution
34 * @param <R> the Reading type this sensor provides.
36 public abstract class SensorDefinition<R extends Reading> {
37 public static final String ALL_TYPE = "All";
39 private static final Set<SensorDefinition<?>> SENSOR_DEFS = Stream
40 .of(new LaCrosseSensorDefinition(), new Ec3kSensorDefinition(), new Pca301SensorDefinition(),
41 new Tx22SensorDefinition(), new RevoltSensorDefinition(), new LgwSensorDefinition())
42 .collect(Collectors.toSet());
43 private static final Set<JeeLinkReadingConverter<?>> CONVERTERS = SENSOR_DEFS.stream()
44 .map(SensorDefinition::createConverter).collect(Collectors.toSet());
46 protected final String type;
48 final ThingTypeUID thingTypeUid;
51 public SensorDefinition(ThingTypeUID thingTypeUid, String name, String type) {
52 this.thingTypeUid = thingTypeUid;
57 public String getName() {
61 public ThingTypeUID getThingTypeUID() {
65 public abstract Class<R> getReadingClass();
67 public abstract JeeLinkSensorHandler<R> createHandler(Thing thing);
69 public abstract JeeLinkReadingConverter<R> createConverter();
71 public static SensorDefinition<?> getSensorDefinition(Reading reading) {
72 for (SensorDefinition<?> sensor : SENSOR_DEFS) {
73 if (sensor.getReadingClass().equals(reading.getClass())) {
81 public static Set<SensorDefinition<?>> getDefinitions() {
85 public static ThingHandler createHandler(ThingTypeUID thingTypeUid, Thing thing) {
86 for (SensorDefinition<?> sensor : SENSOR_DEFS) {
87 if (sensor.getThingTypeUID().equals(thingTypeUid)) {
88 return sensor.createHandler(thing);
95 public static JeeLinkReadingConverter<?> getConverter(String sensorType) {
96 for (SensorDefinition<?> sensor : SENSOR_DEFS) {
97 if (sensor.getSensorType().equals(sensorType)) {
98 return sensor.createConverter();
104 public static Set<JeeLinkReadingConverter<?>> getDiscoveryConverters() {
108 private String getSensorType() {