[onewire] Code improvements and bug fixes (#14400)

Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
J-N-K 2023-02-16 18:49:00 +01:00 committed by GitHub
parent 9a05e9f3b5
commit 5ea0dcbda9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 279 additions and 436 deletions

View File

@ -242,7 +242,7 @@
/bundles/org.openhab.binding.omnikinverter/ @hansbogert /bundles/org.openhab.binding.omnikinverter/ @hansbogert
/bundles/org.openhab.binding.omnilink/ @ecdye /bundles/org.openhab.binding.omnilink/ @ecdye
/bundles/org.openhab.binding.onebusaway/ @sdwilsh /bundles/org.openhab.binding.onebusaway/ @sdwilsh
/bundles/org.openhab.binding.onewire/ @openhab/add-ons-maintainers /bundles/org.openhab.binding.onewire/ @J-N-K
/bundles/org.openhab.binding.onewiregpio/ @aogorek /bundles/org.openhab.binding.onewiregpio/ @aogorek
/bundles/org.openhab.binding.onkyo/ @pail23 @paulianttila /bundles/org.openhab.binding.onkyo/ @pail23 @paulianttila
/bundles/org.openhab.binding.opengarage/ @psmedley /bundles/org.openhab.binding.opengarage/ @psmedley

View File

@ -87,19 +87,16 @@ public class DS2438Configuration {
SensorId associatedSensorId = new SensorId(sensorId.getPath() + matcher.group(2)); SensorId associatedSensorId = new SensorId(sensorId.getPath() + matcher.group(2));
switch (matcher.group(2).substring(0, 2)) { switch (matcher.group(2).substring(0, 2)) {
case "26": case "26" -> {
DS2438Configuration associatedDs2438Config = new DS2438Configuration(bridgeHandler, DS2438Configuration associatedDs2438Config = new DS2438Configuration(bridgeHandler,
associatedSensorId); associatedSensorId);
associatedSensors.put(associatedSensorId, associatedDs2438Config.getSensorSubType()); associatedSensors.put(associatedSensorId, associatedDs2438Config.getSensorSubType());
associatedSensors.putAll(associatedDs2438Config.getAssociatedSensors()); associatedSensors.putAll(associatedDs2438Config.getAssociatedSensors());
break; }
case "28": case "28" -> associatedSensors.put(associatedSensorId, OwSensorType.DS18B20);
associatedSensors.put(associatedSensorId, OwSensorType.DS18B20); case "3A" -> associatedSensors.put(associatedSensorId, OwSensorType.DS2413);
break; default -> {
case "3A": }
associatedSensors.put(associatedSensorId, OwSensorType.DS2413);
break;
default:
} }
} }
} }
@ -129,7 +126,7 @@ public class DS2438Configuration {
* @return a list of OwDiscoveryItems * @return a list of OwDiscoveryItems
*/ */
public List<SensorId> getAssociatedSensorIds(OwSensorType sensorType) { public List<SensorId> getAssociatedSensorIds(OwSensorType sensorType) {
return associatedSensors.entrySet().stream().filter(s -> s.getValue() == sensorType).map(s -> s.getKey()) return associatedSensors.entrySet().stream().filter(s -> s.getValue() == sensorType).map(Map.Entry::getKey)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -198,18 +195,16 @@ public class DS2438Configuration {
List<OwSensorType> associatedSensorTypes) { List<OwSensorType> associatedSensorTypes) {
OwSensorType multisensorType = OwSensorType.UNKNOWN; OwSensorType multisensorType = OwSensorType.UNKNOWN;
switch (associatedSensorTypes.size()) { switch (associatedSensorTypes.size()) {
case 0: case 0 -> multisensorType = mainsensorType;
multisensorType = mainsensorType; case 1 -> {
break;
case 1:
if (mainsensorType == OwSensorType.MS_TH_S && associatedSensorTypes.contains(OwSensorType.DS18B20)) { if (mainsensorType == OwSensorType.MS_TH_S && associatedSensorTypes.contains(OwSensorType.DS18B20)) {
multisensorType = OwSensorType.BMS_S; multisensorType = OwSensorType.BMS_S;
} else if (mainsensorType == OwSensorType.MS_TH } else if (mainsensorType == OwSensorType.MS_TH
&& associatedSensorTypes.contains(OwSensorType.DS18B20)) { && associatedSensorTypes.contains(OwSensorType.DS18B20)) {
multisensorType = OwSensorType.BMS; multisensorType = OwSensorType.BMS;
} }
break; }
case 3: case 3 -> {
if (mainsensorType == OwSensorType.MS_TH_S && associatedSensorTypes.contains(OwSensorType.MS_TV) if (mainsensorType == OwSensorType.MS_TH_S && associatedSensorTypes.contains(OwSensorType.MS_TV)
&& associatedSensorTypes.contains(OwSensorType.DS18B20) && associatedSensorTypes.contains(OwSensorType.DS18B20)
&& associatedSensorTypes.contains(OwSensorType.DS2413)) { && associatedSensorTypes.contains(OwSensorType.DS2413)) {
@ -221,8 +216,9 @@ public class DS2438Configuration {
// two DS2438 (first TH, second TV), DS18B20, DS2413 // two DS2438 (first TH, second TV), DS18B20, DS2413
multisensorType = OwSensorType.AMS; multisensorType = OwSensorType.AMS;
} }
break; }
default: default -> {
}
} }
return multisensorType; return multisensorType;

View File

@ -14,8 +14,6 @@ package org.openhab.binding.onewire.internal;
import static org.openhab.binding.onewire.internal.OwBindingConstants.CHANNEL_DIGITAL; import static org.openhab.binding.onewire.internal.OwBindingConstants.CHANNEL_DIGITAL;
import java.util.Arrays;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter; import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
@ -100,6 +98,6 @@ public class DigitalIoConfig {
@Override @Override
public String toString() { public String toString() {
return String.format("path=%s, mode=%s, logic=%s", Arrays.asList(getParameter()), ioMode, ioLogic); return String.format("path=%s, mode=%s, logic=%s", getParameter(), ioMode, ioLogic);
} }
} }

View File

@ -26,7 +26,7 @@ import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.type.ChannelTypeUID; import org.openhab.core.thing.type.ChannelTypeUID;
/** /**
* The {@link OneWireBinding} class defines common constants, which are * The {@link OwBindingConstants} class defines common constants, which are
* used across the whole binding. * used across the whole binding.
* *
* @author Jan N. Klug - Initial contribution * @author Jan N. Klug - Initial contribution
@ -143,19 +143,17 @@ public class OwBindingConstants {
public static final Map<OwSensorType, String> THING_LABEL_MAP; public static final Map<OwSensorType, String> THING_LABEL_MAP;
public static final Map<OwSensorType, Set<OwChannelConfig>> SENSOR_TYPE_CHANNEL_MAP; public static final Map<OwSensorType, Set<OwChannelConfig>> SENSOR_TYPE_CHANNEL_MAP;
public static final Map<String, String> ACCEPTED_ITEM_TYPES_MAP = Util
.readPropertiesFile("accepted_itemtypes.properties");
static { static {
Map<String, String> properties = Util.readPropertiesFile("sensor.properties"); Map<String, String> properties = Util.readPropertiesFile("sensor.properties");
THING_TYPE_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".thingtype")) THING_TYPE_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".thingtype"))
.collect(Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]), .collect(Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]),
e -> new ThingTypeUID(BINDING_ID, e.getValue()))); e -> new ThingTypeUID(BINDING_ID, e.getValue())));
SENSOR_TYPE_CHANNEL_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".channels")) SENSOR_TYPE_CHANNEL_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".channels"))
.collect(Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]), .collect(
e -> !e.getValue().isEmpty() ? Stream.of(e.getValue().split(",")) Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]),
.map(c -> OwChannelConfig.fromString(c)).collect(Collectors.toSet()) e -> !e.getValue().isEmpty() ? Stream.of(e.getValue().split(","))
: new HashSet<>())); .map(OwChannelConfig::fromString).collect(Collectors.toSet())
: new HashSet<>()));
THING_LABEL_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".label")).collect( THING_LABEL_MAP = properties.entrySet().stream().filter(e -> e.getKey().endsWith(".label")).collect(
Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]), e -> e.getValue())); Collectors.toConcurrentMap(e -> OwSensorType.valueOf(e.getKey().split("\\.")[0]), e -> e.getValue()));
} }

View File

@ -14,32 +14,23 @@ package org.openhab.binding.onewire.internal;
import static org.openhab.binding.onewire.internal.OwBindingConstants.SUPPORTED_THING_TYPES; import static org.openhab.binding.onewire.internal.OwBindingConstants.SUPPORTED_THING_TYPES;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.onewire.internal.discovery.OwDiscoveryService;
import org.openhab.binding.onewire.internal.handler.AdvancedMultisensorThingHandler; import org.openhab.binding.onewire.internal.handler.AdvancedMultisensorThingHandler;
import org.openhab.binding.onewire.internal.handler.BAE091xSensorThingHandler; import org.openhab.binding.onewire.internal.handler.BAE091xSensorThingHandler;
import org.openhab.binding.onewire.internal.handler.BasicMultisensorThingHandler; import org.openhab.binding.onewire.internal.handler.BasicMultisensorThingHandler;
import org.openhab.binding.onewire.internal.handler.BasicThingHandler; import org.openhab.binding.onewire.internal.handler.BasicThingHandler;
import org.openhab.binding.onewire.internal.handler.EDSSensorThingHandler; import org.openhab.binding.onewire.internal.handler.EDSSensorThingHandler;
import org.openhab.binding.onewire.internal.handler.OwserverBridgeHandler; import org.openhab.binding.onewire.internal.handler.OwserverBridgeHandler;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing; import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory; import org.openhab.core.thing.binding.BaseThingHandlerFactory;
import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory; import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* The {@link OwHandlerFactory} is responsible for creating things and thing * The {@link OwHandlerFactory} is responsible for creating things and thing
@ -50,11 +41,12 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault @NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.onewire") @Component(service = ThingHandlerFactory.class, configurationPid = "binding.onewire")
public class OwHandlerFactory extends BaseThingHandlerFactory { public class OwHandlerFactory extends BaseThingHandlerFactory {
Logger logger = LoggerFactory.getLogger(OwHandlerFactory.class); private final OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider;
private final Map<ThingUID, ServiceRegistration<?>> discoveryServiceRegs = new HashMap<>();
@NonNullByDefault({}) @Activate
private OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider; public OwHandlerFactory(@Reference OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
this.dynamicStateDescriptionProvider = dynamicStateDescriptionProvider;
}
@Override @Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) { public boolean supportsThingType(ThingTypeUID thingTypeUID) {
@ -66,9 +58,7 @@ public class OwHandlerFactory extends BaseThingHandlerFactory {
ThingTypeUID thingTypeUID = thing.getThingTypeUID(); ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (OwserverBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { if (OwserverBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
OwserverBridgeHandler owserverBridgeHandler = new OwserverBridgeHandler((Bridge) thing); return new OwserverBridgeHandler((Bridge) thing);
registerDiscoveryService(owserverBridgeHandler);
return owserverBridgeHandler;
} else if (BasicMultisensorThingHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { } else if (BasicMultisensorThingHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return new BasicMultisensorThingHandler(thing, dynamicStateDescriptionProvider); return new BasicMultisensorThingHandler(thing, dynamicStateDescriptionProvider);
} else if (AdvancedMultisensorThingHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { } else if (AdvancedMultisensorThingHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
@ -83,41 +73,4 @@ public class OwHandlerFactory extends BaseThingHandlerFactory {
return null; return null;
} }
@Override
public void unregisterHandler(Thing thing) {
super.unregisterHandler(thing);
logger.error("factory {} deleting thing {}", this, thing);
}
private synchronized void registerDiscoveryService(OwserverBridgeHandler owserverBridgeHandler) {
OwDiscoveryService owDiscoveryService = new OwDiscoveryService(owserverBridgeHandler);
this.discoveryServiceRegs.put(owserverBridgeHandler.getThing().getUID(),
bundleContext.registerService(DiscoveryService.class.getName(), owDiscoveryService, new Hashtable<>()));
}
@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof OwserverBridgeHandler) {
// remove discovery service, if bridge handler is removed
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.remove(thingHandler.getThing().getUID());
if (serviceReg != null) {
OwDiscoveryService service = (OwDiscoveryService) bundleContext.getService(serviceReg.getReference());
serviceReg.unregister();
if (service != null) {
service.deactivate();
}
}
}
}
@Reference
protected void setDynamicStateDescriptionProvider(OwDynamicStateDescriptionProvider provider) {
this.dynamicStateDescriptionProvider = provider;
}
protected void unsetDynamicStateDescriptionProvider(OwDynamicStateDescriptionProvider provider) {
this.dynamicStateDescriptionProvider = null;
}
} }

View File

@ -13,7 +13,7 @@
package org.openhab.binding.onewire.internal; package org.openhab.binding.onewire.internal;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -52,9 +52,9 @@ public class Util {
if (temperatureDegC == null) { if (temperatureDegC == null) {
throw new IllegalArgumentException("could not change unit"); throw new IllegalArgumentException("could not change unit");
} }
Double theta = temperatureDegC.doubleValue(); double theta = temperatureDegC.doubleValue();
// saturation vapor pressure in kg/(m s^2) // saturation vapor pressure in kg/(m s^2)
Double saturationVaporPressure = 611.2 * Math.exp(17.62 * theta / (243.12 + theta)); double saturationVaporPressure = 611.2 * Math.exp(17.62 * theta / (243.12 + theta));
// absolute humidity in kg/m^3 // absolute humidity in kg/m^3
Double aH = relativeHumidity.doubleValue() / 100 * saturationVaporPressure / (461.52 * (273.15 + theta)); Double aH = relativeHumidity.doubleValue() / 100 * saturationVaporPressure / (461.52 * (273.15 + theta));
State absoluteHumidity = new QuantityType<>(aH, Units.KILOGRAM_PER_CUBICMETRE).toUnit("g/m³"); State absoluteHumidity = new QuantityType<>(aH, Units.KILOGRAM_PER_CUBICMETRE).toUnit("g/m³");
@ -78,24 +78,32 @@ public class Util {
if (temperatureDegC == null) { if (temperatureDegC == null) {
throw new IllegalArgumentException("could not change unit"); throw new IllegalArgumentException("could not change unit");
} }
Double theta = temperatureDegC.doubleValue(); double theta = temperatureDegC.doubleValue();
Double rH = relativeHumidity.doubleValue() / 100; double rH = relativeHumidity.doubleValue() / 100;
// dewpoint in °C // dewpoint in °C
Double dP = 243.12 * (((17.62 * theta) / (243.12 + theta) + Math.log(rH)) Double dP = 243.12 * (((17.62 * theta) / (243.12 + theta) + Math.log(rH))
/ (((17.62 * 243.12) / (243.12 + theta) - Math.log(rH)))); / (((17.62 * 243.12) / (243.12 + theta) - Math.log(rH))));
State dewPoint = new QuantityType<>(dP, SIUnits.CELSIUS); return new QuantityType<>(dP, SIUnits.CELSIUS);
return dewPoint;
} }
public static Map<String, String> readPropertiesFile(String filename) { public static Map<String, String> readPropertiesFile(String filename) {
URL resource = Thread.currentThread().getContextClassLoader().getResource(filename); ClassLoader classLoader = OwBindingConstants.class.getClassLoader();
if (classLoader == null) {
LOGGER.warn("Could not get classloader, binding will fail.");
return Map.of();
}
Properties properties = new Properties(); Properties properties = new Properties();
try {
properties.load(resource.openStream()); try (InputStream inputStream = classLoader.getResourceAsStream(filename)) {
if (inputStream == null) {
LOGGER.warn("Could not get input stream for resource file '{}', binding will fail.", filename);
return Map.of();
}
properties.load(inputStream);
return properties.entrySet().stream() return properties.entrySet().stream()
.collect(Collectors.toMap(e -> (String) e.getKey(), e -> (String) e.getValue())); .collect(Collectors.toMap(e -> (String) e.getKey(), e -> (String) e.getValue()));
} catch (IOException e) { } catch (IOException e) {
LOGGER.warn("Could not read resource file {}, binding will probably fail: {}", filename, e.getMessage()); LOGGER.warn("Could not read resource file {}, binding will fail: {}", filename, e.getMessage());
return new HashMap<>(); return new HashMap<>();
} }
} }

View File

@ -26,7 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The {@link AbstractOwClass} class defines an abstract onewire device * The {@link AbstractOwDevice} class defines an abstract onewire device
* *
* @author Jan N. Klug - Initial contribution * @author Jan N. Klug - Initial contribution
*/ */
@ -68,7 +68,7 @@ public abstract class AbstractOwDevice {
/** /**
* refresh this sensor * refresh this sensor
* *
* @param bridgeHandler for sending requests * @param owBridgeHandler for sending requests
* @param forcedRefresh post update even if state did not change * @param forcedRefresh post update even if state did not change
* @throws OwException in case of communication error * @throws OwException in case of communication error
*/ */
@ -80,9 +80,7 @@ public abstract class AbstractOwDevice {
* @param channelID the channels channelID * @param channelID the channels channelID
*/ */
public void enableChannel(String channelID) { public void enableChannel(String channelID) {
if (!enabledChannels.contains(channelID)) { enabledChannels.add(channelID);
enabledChannels.add(channelID);
}
} }
/** /**
@ -91,9 +89,7 @@ public abstract class AbstractOwDevice {
* @param channelID the channels channelID * @param channelID the channels channelID
*/ */
public void disableChannel(String channelID) { public void disableChannel(String channelID) {
if (enabledChannels.contains(channelID)) { enabledChannels.remove(channelID);
enabledChannels.remove(channelID);
}
} }
/** /**
@ -108,10 +104,9 @@ public abstract class AbstractOwDevice {
/** /**
* check sensor presence and update thing state * check sensor presence and update thing state
* *
* @param owServerConnection * @param bridgeHandler
* @return sensors presence state * @return sensors presence state
*/ */
public Boolean checkPresence(OwserverBridgeHandler bridgeHandler) { public Boolean checkPresence(OwserverBridgeHandler bridgeHandler) {
try { try {
State present = bridgeHandler.checkPresence(sensorId); State present = bridgeHandler.checkPresence(sensorId);
@ -123,18 +118,4 @@ public abstract class AbstractOwDevice {
return false; return false;
} }
} }
/**
* get this sensors type
*
* @param bridgeHandler bridge handler to request from if type formerly unknown
* @return this sensors type
* @throws OwException
*/
public OwSensorType getSensorType(OwserverBridgeHandler bridgeHandler) throws OwException {
if (sensorType == OwSensorType.UNKNOWN) {
sensorType = bridgeHandler.getType(sensorId);
}
return sensorType;
}
} }

View File

@ -88,11 +88,11 @@ public class BAE0910 extends AbstractOwDevice {
private final OwserverDeviceParameter duty3Parameter = new OwserverDeviceParameter("/duty3"); private final OwserverDeviceParameter duty3Parameter = new OwserverDeviceParameter("/duty3");
private final OwserverDeviceParameter duty4Parameter = new OwserverDeviceParameter("/duty4"); private final OwserverDeviceParameter duty4Parameter = new OwserverDeviceParameter("/duty4");
private BitSet outcRegister = new BitSet(8); private final BitSet outcRegister = new BitSet(8);
private BitSet piocRegister = new BitSet(8); private final BitSet piocRegister = new BitSet(8);
private BitSet adccRegister = new BitSet(8); private final BitSet adccRegister = new BitSet(8);
private BitSet tpm1cRegister = new BitSet(8); private final BitSet tpm1cRegister = new BitSet(8);
private BitSet tpm2cRegister = new BitSet(8); private final BitSet tpm2cRegister = new BitSet(8);
private double resolution1 = 8; // in µs private double resolution1 = 8; // in µs
private double resolution2 = 8; // in µs private double resolution2 = 8; // in µs
@ -155,15 +155,16 @@ public class BAE0910 extends AbstractOwDevice {
BAE091xPIOConfiguration channelConfig = channel.getConfiguration().as(BAE091xPIOConfiguration.class); BAE091xPIOConfiguration channelConfig = channel.getConfiguration().as(BAE091xPIOConfiguration.class);
piocRegister.set(PIOC_DD, channelConfig.mode.equals("output")); piocRegister.set(PIOC_DD, channelConfig.mode.equals("output"));
switch (channelConfig.pulldevice) { switch (channelConfig.pulldevice) {
case "pullup": case "pullup" -> {
piocRegister.set(PIOC_PE); piocRegister.set(PIOC_PE);
piocRegister.clear(PIOC_PD); piocRegister.clear(PIOC_PD);
break; }
case "pulldown": case "pulldown" -> {
piocRegister.set(PIOC_PE); piocRegister.set(PIOC_PE);
piocRegister.set(PIOC_PD); piocRegister.set(PIOC_PD);
break; }
default: default -> {
}
} }
} else { } else {
throw new OwException("trying to configure pin 6 but channel is missing"); throw new OwException("trying to configure pin 6 but channel is missing");
@ -284,81 +285,78 @@ public class BAE0910 extends AbstractOwDevice {
try { try {
BitSet value = new BitSet(8); BitSet value = new BitSet(8);
switch (channelId) { switch (channelId) {
case CHANNEL_DIGITAL2: case CHANNEL_DIGITAL2 -> {
// output // output
if (!outcRegister.get(OUTC_OUTEN)) { if (!outcRegister.get(OUTC_OUTEN)) {
return false; return false;
} }
value.set(0, ((OnOffType) command).equals(OnOffType.ON)); value.set(0, command.equals(OnOffType.ON));
bridgeHandler.writeBitSet(sensorId, pin2OutParameter, value); bridgeHandler.writeBitSet(sensorId, pin2OutParameter, value);
break; }
case CHANNEL_DIGITAL6: case CHANNEL_DIGITAL6 -> {
// not input, pio // not input, pio
if (!piocRegister.get(PIOC_DD) || !piocRegister.get(PIOC_PIOEN)) { if (!piocRegister.get(PIOC_DD) || !piocRegister.get(PIOC_PIOEN)) {
return false; return false;
} }
value.set(0, ((OnOffType) command).equals(OnOffType.ON)); value.set(0, command.equals(OnOffType.ON));
bridgeHandler.writeBitSet(sensorId, pin6PIOParameter, value); bridgeHandler.writeBitSet(sensorId, pin6PIOParameter, value);
break; }
case CHANNEL_DIGITAL7: case CHANNEL_DIGITAL7 -> {
// not pwm, not analog // not pwm, not analog
if (!tpm2cRegister.get(TPMC_PWMDIS) || adccRegister.get(ADCC_ADCEN)) { if (!tpm2cRegister.get(TPMC_PWMDIS) || adccRegister.get(ADCC_ADCEN)) {
return false; return false;
} }
tpm2cRegister.set(TPMC_POL, ((OnOffType) command).equals(OnOffType.ON)); tpm2cRegister.set(TPMC_POL, command.equals(OnOffType.ON));
bridgeHandler.writeBitSet(sensorId, tpm2cParameter, tpm2cRegister); bridgeHandler.writeBitSet(sensorId, tpm2cParameter, tpm2cRegister);
break; }
case CHANNEL_DIGITAL8: case CHANNEL_DIGITAL8 -> {
// not input, not pwm // not input, not pwm
if (tpm1cRegister.get(TPMC_INENA) || !tpm1cRegister.get(TPMC_PWMDIS)) { if (tpm1cRegister.get(TPMC_INENA) || !tpm1cRegister.get(TPMC_PWMDIS)) {
return false; return false;
} }
tpm1cRegister.set(TPMC_POL, ((OnOffType) command).equals(OnOffType.ON)); tpm1cRegister.set(TPMC_POL, command.equals(OnOffType.ON));
bridgeHandler.writeBitSet(sensorId, tpm1cParameter, tpm1cRegister); bridgeHandler.writeBitSet(sensorId, tpm1cParameter, tpm1cRegister);
break; }
case CHANNEL_PWM_FREQ1: case CHANNEL_PWM_FREQ1 -> {
if (command instanceof QuantityType<?>) { if (command instanceof QuantityType<?>) {
bridgeHandler.writeDecimalType(sensorId, period1Parameter, bridgeHandler.writeDecimalType(sensorId, period1Parameter,
convertFrequencyToPeriod(command, resolution1)); convertFrequencyToPeriod(command, resolution1));
} }
break; }
case CHANNEL_PWM_FREQ2: case CHANNEL_PWM_FREQ2 -> {
if (command instanceof QuantityType<?>) { if (command instanceof QuantityType<?>) {
bridgeHandler.writeDecimalType(sensorId, period2Parameter, bridgeHandler.writeDecimalType(sensorId, period2Parameter,
convertFrequencyToPeriod(command, resolution2)); convertFrequencyToPeriod(command, resolution2));
} }
break; }
case CHANNEL_PWM_DUTY1: case CHANNEL_PWM_DUTY1 -> {
if (command instanceof QuantityType<?>) { if (command instanceof QuantityType<?>) {
bridgeHandler.writeDecimalType(sensorId, duty1Parameter, calculateDutyCycle(command, bridgeHandler.writeDecimalType(sensorId, duty1Parameter, calculateDutyCycle(command,
(DecimalType) bridgeHandler.readDecimalType(sensorId, period1Parameter))); (DecimalType) bridgeHandler.readDecimalType(sensorId, period1Parameter)));
} }
break; }
case CHANNEL_PWM_DUTY2: case CHANNEL_PWM_DUTY2 -> {
if (command instanceof QuantityType<?>) { if (command instanceof QuantityType<?>) {
bridgeHandler.writeDecimalType(sensorId, duty2Parameter, calculateDutyCycle(command, bridgeHandler.writeDecimalType(sensorId, duty2Parameter, calculateDutyCycle(command,
(DecimalType) bridgeHandler.readDecimalType(sensorId, period2Parameter))); (DecimalType) bridgeHandler.readDecimalType(sensorId, period2Parameter)));
} }
break; }
case CHANNEL_PWM_DUTY3: case CHANNEL_PWM_DUTY3 -> {
if (command instanceof QuantityType<?>) { if (command instanceof QuantityType<?>) {
bridgeHandler.writeDecimalType(sensorId, duty3Parameter, calculateDutyCycle(command, bridgeHandler.writeDecimalType(sensorId, duty3Parameter, calculateDutyCycle(command,
(DecimalType) bridgeHandler.readDecimalType(sensorId, period1Parameter))); (DecimalType) bridgeHandler.readDecimalType(sensorId, period1Parameter)));
} }
break; }
case CHANNEL_PWM_DUTY4: case CHANNEL_PWM_DUTY4 -> {
if (command instanceof QuantityType<?>) { if (command instanceof QuantityType<?>) {
bridgeHandler.writeDecimalType(sensorId, duty4Parameter, calculateDutyCycle(command, bridgeHandler.writeDecimalType(sensorId, duty4Parameter, calculateDutyCycle(command,
(DecimalType) bridgeHandler.readDecimalType(sensorId, period2Parameter))); (DecimalType) bridgeHandler.readDecimalType(sensorId, period2Parameter)));
} }
break; }
default: default -> throw new OwException("unknown or invalid channel");
throw new OwException("unknown or invalid channel");
} }
return true; return true;
} catch ( } catch (OwException e) {
OwException e) {
logger.info("could not write {} to {}: {}", command, channelId, e.getMessage()); logger.info("could not write {} to {}: {}", command, channelId, e.getMessage());
return false; return false;
} }
@ -369,14 +367,11 @@ public class BAE0910 extends AbstractOwDevice {
OwserverDeviceParameter deviceTypeParameter = new OwserverDeviceParameter("/device_type"); OwserverDeviceParameter deviceTypeParameter = new OwserverDeviceParameter("/device_type");
String subDeviceType = bridgeHandler.readString(sensorId, deviceTypeParameter); String subDeviceType = bridgeHandler.readString(sensorId, deviceTypeParameter);
switch (subDeviceType) { return switch (subDeviceType) {
case "2": case "2" -> OwSensorType.BAE0910;
return OwSensorType.BAE0910; case "3" -> OwSensorType.BAE0911;
case "3": default -> OwSensorType.UNKNOWN;
return OwSensorType.BAE0911; };
default:
return OwSensorType.UNKNOWN;
}
} }
private DecimalType convertFrequencyToPeriod(Command command, double resolution) throws OwException { private DecimalType convertFrequencyToPeriod(Command command, double resolution) throws OwException {

View File

@ -44,35 +44,31 @@ public class OwDiscoveryItem {
private OwSensorType sensorType = OwSensorType.UNKNOWN; private OwSensorType sensorType = OwSensorType.UNKNOWN;
private String vendor = "Dallas/Maxim"; private String vendor = "Dallas/Maxim";
private OwPageBuffer pages = new OwPageBuffer();
private ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, "");
private final Map<SensorId, OwSensorType> associatedSensors = new HashMap<>(); private final Map<SensorId, OwSensorType> associatedSensors = new HashMap<>();
public OwDiscoveryItem(OwserverBridgeHandler bridgeHandler, SensorId sensorId) throws OwException { public OwDiscoveryItem(OwserverBridgeHandler bridgeHandler, SensorId sensorId) throws OwException {
this.sensorId = sensorId; this.sensorId = sensorId;
sensorType = bridgeHandler.getType(sensorId); sensorType = bridgeHandler.getType(sensorId);
switch (sensorType) { switch (sensorType) {
case DS2438: case DS2438 -> {
pages = bridgeHandler.readPages(sensorId); bridgeHandler.readPages(sensorId);
DS2438Configuration config = new DS2438Configuration(bridgeHandler, sensorId); DS2438Configuration config = new DS2438Configuration(bridgeHandler, sensorId);
associatedSensors.putAll(config.getAssociatedSensors()); associatedSensors.putAll(config.getAssociatedSensors());
logger.trace("found associated sensors: {}", associatedSensors); logger.trace("found associated sensors: {}", associatedSensors);
vendor = config.getVendor(); vendor = config.getVendor();
sensorType = config.getSensorSubType(); sensorType = config.getSensorSubType();
break; }
case EDS: case EDS -> {
vendor = "Embedded Data Systems"; vendor = "Embedded Data Systems";
pages = bridgeHandler.readPages(sensorId); OwPageBuffer pages = bridgeHandler.readPages(sensorId);
try { // determine subsensorType try { // determine subsensorType
sensorType = OwSensorType.valueOf(new String(pages.getPage(0), 0, 7, StandardCharsets.US_ASCII)); sensorType = OwSensorType.valueOf(new String(pages.getPage(0), 0, 7, StandardCharsets.US_ASCII));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
sensorType = OwSensorType.UNKNOWN; sensorType = OwSensorType.UNKNOWN;
} }
break; }
default: default -> {
}
} }
} }
@ -142,12 +138,10 @@ public class OwDiscoveryItem {
logger.debug("checkSensorType: {} with {}", this, associatedSensors); logger.debug("checkSensorType: {} with {}", this, associatedSensors);
switch (sensorType) { switch (sensorType) {
case MS_TH: case MS_TH, MS_TH_S -> sensorType = DS2438Configuration.getMultisensorType(sensorType,
case MS_TH_S: new ArrayList<>(associatedSensors.values()));
sensorType = DS2438Configuration.getMultisensorType(sensorType, default -> {
new ArrayList<>(associatedSensors.values())); }
break;
default:
} }
} }

View File

@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.onewire.internal.OwException; import org.openhab.binding.onewire.internal.OwException;
import org.openhab.binding.onewire.internal.SensorId; import org.openhab.binding.onewire.internal.SensorId;
import org.openhab.binding.onewire.internal.device.OwSensorType; import org.openhab.binding.onewire.internal.device.OwSensorType;
@ -31,6 +32,8 @@ import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder; import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID; import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -40,28 +43,27 @@ import org.slf4j.LoggerFactory;
* @author Jan N. Klug - Initial contribution * @author Jan N. Klug - Initial contribution
*/ */
@NonNullByDefault @NonNullByDefault
public class OwDiscoveryService extends AbstractDiscoveryService { public class OwDiscoveryService extends AbstractDiscoveryService implements ThingHandlerService {
private final Logger logger = LoggerFactory.getLogger(OwDiscoveryService.class); private final Logger logger = LoggerFactory.getLogger(OwDiscoveryService.class);
private final OwserverBridgeHandler owBridgeHandler; private @Nullable OwserverBridgeHandler bridgeHandler;
private final ThingUID bridgeUID;
Map<SensorId, OwDiscoveryItem> owDiscoveryItems = new HashMap<>(); Map<SensorId, OwDiscoveryItem> owDiscoveryItems = new HashMap<>();
Set<SensorId> associatedSensors = new HashSet<>(); Set<SensorId> associatedSensors = new HashSet<>();
public OwDiscoveryService(OwserverBridgeHandler owBridgeHandler) { public OwDiscoveryService() {
super(SUPPORTED_THING_TYPES, 60, false); super(SUPPORTED_THING_TYPES, 60, false);
this.owBridgeHandler = owBridgeHandler; logger.debug("registering discovery service for {}", bridgeHandler);
this.bridgeUID = owBridgeHandler.getThing().getUID();
logger.debug("registering discovery service for {}", owBridgeHandler);
} }
private void scanDirectory(String baseDirectory) { private void scanDirectory(OwserverBridgeHandler bridgeHandler, String baseDirectory) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
List<SensorId> directoryList; List<SensorId> directoryList;
logger.trace("scanning {} on bridge {}", baseDirectory, bridgeUID); logger.trace("scanning {} on bridge {}", baseDirectory, bridgeUID);
try { try {
directoryList = owBridgeHandler.getDirectory(baseDirectory); directoryList = bridgeHandler.getDirectory(baseDirectory);
} catch (OwException e) { } catch (OwException e) {
logger.info("empty directory '{}' for {}", baseDirectory, bridgeUID); logger.info("empty directory '{}' for {}", baseDirectory, bridgeUID);
return; return;
@ -70,13 +72,13 @@ public class OwDiscoveryService extends AbstractDiscoveryService {
// find all valid sensors // find all valid sensors
for (SensorId directoryEntry : directoryList) { for (SensorId directoryEntry : directoryList) {
try { try {
OwDiscoveryItem owDiscoveryItem = new OwDiscoveryItem(owBridgeHandler, directoryEntry); OwDiscoveryItem owDiscoveryItem = new OwDiscoveryItem(bridgeHandler, directoryEntry);
if (owDiscoveryItem.getSensorType() == OwSensorType.DS2409) { if (owDiscoveryItem.getSensorType() == OwSensorType.DS2409) {
// scan hub sub-directories // scan hub sub-directories
logger.trace("found hub {}, scanning sub-directories", directoryEntry); logger.trace("found hub {}, scanning sub-directories", directoryEntry);
scanDirectory(owDiscoveryItem.getSensorId().getFullPath() + "/main/"); scanDirectory(bridgeHandler, owDiscoveryItem.getSensorId().getFullPath() + "/main/");
scanDirectory(owDiscoveryItem.getSensorId().getFullPath() + "/aux/"); scanDirectory(bridgeHandler, owDiscoveryItem.getSensorId().getFullPath() + "/aux/");
} else { } else {
// add found sensor to list // add found sensor to list
logger.trace("found sensor {} (type: {})", directoryEntry, owDiscoveryItem.getSensorType()); logger.trace("found sensor {} (type: {})", directoryEntry, owDiscoveryItem.getSensorType());
@ -93,7 +95,15 @@ public class OwDiscoveryService extends AbstractDiscoveryService {
@Override @Override
public void startScan() { public void startScan() {
scanDirectory("/"); OwserverBridgeHandler bridgeHandler = this.bridgeHandler;
if (bridgeHandler == null) {
logger.warn("bridgeHandler not found");
return;
}
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
scanDirectory(bridgeHandler, "/");
// remove duplicates // remove duplicates
owDiscoveryItems.entrySet().removeIf(s -> associatedSensors.contains(s.getKey())); owDiscoveryItems.entrySet().removeIf(s -> associatedSensors.contains(s.getKey()));
@ -130,6 +140,18 @@ public class OwDiscoveryService extends AbstractDiscoveryService {
super.stopScan(); super.stopScan();
} }
@Override
public void setThingHandler(ThingHandler thingHandler) {
if (thingHandler instanceof OwserverBridgeHandler) {
this.bridgeHandler = (OwserverBridgeHandler) thingHandler;
}
}
@Override
public @Nullable ThingHandler getThingHandler() {
return bridgeHandler;
}
@Override @Override
public void deactivate() { public void deactivate() {
removeOlderResults(new Date().getTime()); removeOlderResults(new Date().getTime());

View File

@ -14,10 +14,7 @@ package org.openhab.binding.onewire.internal.handler;
import static org.openhab.binding.onewire.internal.OwBindingConstants.*; import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -52,11 +49,9 @@ import org.slf4j.LoggerFactory;
*/ */
@NonNullByDefault @NonNullByDefault
public class AdvancedMultisensorThingHandler extends OwBaseThingHandler { public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = new HashSet<>( public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_AMS, THING_TYPE_BMS);
Arrays.asList(THING_TYPE_AMS, THING_TYPE_BMS)); public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.AMS, OwSensorType.AMS_S,
public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Collections OwSensorType.BMS, OwSensorType.BMS_S);
.unmodifiableSet(Stream.of(OwSensorType.AMS, OwSensorType.AMS_S, OwSensorType.BMS, OwSensorType.BMS_S)
.collect(Collectors.toSet()));
private static final String PROPERTY_DS18B20 = "ds18b20"; private static final String PROPERTY_DS18B20 = "ds18b20";
private static final String PROPERTY_DS2413 = "ds2413"; private static final String PROPERTY_DS2413 = "ds2413";
@ -90,7 +85,7 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
return; return;
} }
hwRevision = Integer.valueOf(properties.getOrDefault(PROPERTY_HW_REVISION, "0")); hwRevision = Integer.parseInt(properties.getOrDefault(PROPERTY_HW_REVISION, "0"));
try { try {
sensors.add(new DS2438(sensorId, this)); sensors.add(new DS2438(sensorId, this));
@ -104,9 +99,7 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "properties invalid"); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "properties invalid");
} }
scheduler.execute(() -> { scheduler.execute(this::configureThingChannels);
configureThingChannels();
});
} }
@Override @Override
@ -140,8 +133,8 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
sensors.get(i).refresh(bridgeHandler, forcedRefresh); sensors.get(i).refresh(bridgeHandler, forcedRefresh);
} }
} else { } else {
for (int i = 0; i < sensors.size(); i++) { for (AbstractOwDevice sensor : sensors) {
sensors.get(i).refresh(bridgeHandler, forcedRefresh); sensor.refresh(bridgeHandler, forcedRefresh);
} }
} }
} }
@ -159,7 +152,7 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
// delete unwanted channels // delete unwanted channels
Set<String> existingChannelIds = thing.getChannels().stream().map(channel -> channel.getUID().getId()) Set<String> existingChannelIds = thing.getChannels().stream().map(channel -> channel.getUID().getId())
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Set<String> wantedChannelIds = SENSOR_TYPE_CHANNEL_MAP.get(sensorType).stream() Set<String> wantedChannelIds = SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of()).stream()
.map(channelConfig -> channelConfig.channelId).collect(Collectors.toSet()); .map(channelConfig -> channelConfig.channelId).collect(Collectors.toSet());
wantedChannelIds.add(CHANNEL_TEMPERATURE); wantedChannelIds.add(CHANNEL_TEMPERATURE);
wantedChannelIds.add(CHANNEL_HUMIDITY); wantedChannelIds.add(CHANNEL_HUMIDITY);
@ -167,9 +160,8 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
.forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId)); .forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId));
// add or update wanted channels // add or update wanted channels
SENSOR_TYPE_CHANNEL_MAP.get(sensorType).stream().forEach(channelConfig -> { SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of()).stream()
addChannelIfMissingAndEnable(thingBuilder, channelConfig); .forEach(channelConfig -> addChannelIfMissingAndEnable(thingBuilder, channelConfig));
});
// temperature channel // temperature channel
if (configuration.containsKey(CONFIG_TEMPERATURESENSOR) if (configuration.containsKey(CONFIG_TEMPERATURESENSOR)
@ -184,12 +176,7 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
// humidity channel // humidity channel
addChannelIfMissingAndEnable(thingBuilder, new OwChannelConfig(CHANNEL_HUMIDITY, CHANNEL_TYPE_UID_HUMIDITY), addChannelIfMissingAndEnable(thingBuilder, new OwChannelConfig(CHANNEL_HUMIDITY, CHANNEL_TYPE_UID_HUMIDITY),
new Configuration(new HashMap<String, Object>() { new Configuration(Map.of(CONFIG_HUMIDITY, "/HIH4000/humidity")));
private static final long serialVersionUID = 1L;
{
put(CONFIG_HUMIDITY, "/HIH4000/humidity");
}
}));
// configure light channel // configure light channel
if (sensorType == OwSensorType.AMS_S || sensorType == OwSensorType.BMS_S) { if (sensorType == OwSensorType.AMS_S || sensorType == OwSensorType.BMS_S) {
@ -230,23 +217,18 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
properties.put(PROPERTY_HW_REVISION, ds2438configuration.getHardwareRevision()); properties.put(PROPERTY_HW_REVISION, ds2438configuration.getHardwareRevision());
switch (sensorType) { switch (sensorType) {
case BMS: case BMS, BMS_S -> properties.put(PROPERTY_DS18B20,
case BMS_S: ds2438configuration.getAssociatedSensorIds(OwSensorType.DS18B20).get(0).getFullPath());
properties.put(PROPERTY_DS18B20, case AMS, AMS_S -> {
ds2438configuration.getAssociatedSensorIds(OwSensorType.DS18B20).get(0).getFullPath());
break;
case AMS:
case AMS_S:
properties.put(PROPERTY_DS18B20, properties.put(PROPERTY_DS18B20,
ds2438configuration.getAssociatedSensorIds(OwSensorType.DS18B20).get(0).getFullPath()); ds2438configuration.getAssociatedSensorIds(OwSensorType.DS18B20).get(0).getFullPath());
properties.put(PROPERTY_DS2413, properties.put(PROPERTY_DS2413,
ds2438configuration.getAssociatedSensorIds(OwSensorType.DS2413).get(0).getFullPath()); ds2438configuration.getAssociatedSensorIds(OwSensorType.DS2413).get(0).getFullPath());
properties.put(PROPERTY_DS2438, properties.put(PROPERTY_DS2438,
ds2438configuration.getAssociatedSensorIds(OwSensorType.MS_TV).get(0).getFullPath()); ds2438configuration.getAssociatedSensorIds(OwSensorType.MS_TV).get(0).getFullPath());
}
break; default -> throw new OwException(
default: "sensorType " + sensorType.toString() + " not supported by this thing handler");
throw new OwException("sensorType " + sensorType.toString() + " not supported by this thing handler");
} }
updateProperties(properties); updateProperties(properties);
@ -259,10 +241,6 @@ public class AdvancedMultisensorThingHandler extends OwBaseThingHandler {
* @return * @return
*/ */
private static Set<String> getRequiredProperties(ThingTypeUID thingType) { private static Set<String> getRequiredProperties(ThingTypeUID thingType) {
if (THING_TYPE_AMS.equals(thingType)) { return THING_TYPE_AMS.equals(thingType) ? REQUIRED_PROPERTIES_AMS : REQUIRED_PROPERTIES_BMS;
return REQUIRED_PROPERTIES_AMS;
} else {
return REQUIRED_PROPERTIES_BMS;
}
} }
} }

View File

@ -14,7 +14,6 @@ package org.openhab.binding.onewire.internal.handler;
import static org.openhab.binding.onewire.internal.OwBindingConstants.*; import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -47,11 +46,11 @@ import org.slf4j.LoggerFactory;
*/ */
@NonNullByDefault @NonNullByDefault
public class BAE091xSensorThingHandler extends OwBaseThingHandler { public class BAE091xSensorThingHandler extends OwBaseThingHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BAE091X); public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BAE091X);
private final Logger logger = LoggerFactory.getLogger(BAE091xSensorThingHandler.class); private final Logger logger = LoggerFactory.getLogger(BAE091xSensorThingHandler.class);
public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Collections.singleton(OwSensorType.BAE0910); public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.BAE0910);
public BAE091xSensorThingHandler(Thing thing, OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) { public BAE091xSensorThingHandler(Thing thing, OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
super(thing, dynamicStateDescriptionProvider, SUPPORTED_SENSOR_TYPES); super(thing, dynamicStateDescriptionProvider, SUPPORTED_SENSOR_TYPES);
@ -89,9 +88,7 @@ public class BAE091xSensorThingHandler extends OwBaseThingHandler {
sensors.add(new BAE0910(sensorId, this)); sensors.add(new BAE0910(sensorId, this));
scheduler.execute(() -> { scheduler.execute(this::configureThingChannels);
configureThingChannels();
});
} }
@Override @Override
@ -101,8 +98,7 @@ public class BAE091xSensorThingHandler extends OwBaseThingHandler {
BAE091xHandlerConfiguration configuration = getConfig().as(BAE091xHandlerConfiguration.class); BAE091xHandlerConfiguration configuration = getConfig().as(BAE091xHandlerConfiguration.class);
Set<OwChannelConfig> wantedChannel = new HashSet<>(); Set<OwChannelConfig> wantedChannel = new HashSet<>(SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of()));
wantedChannel.addAll(SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of()));
// Pin1: // Pin1:
switch (configuration.pin1) { switch (configuration.pin1) {
@ -214,7 +210,7 @@ public class BAE091xSensorThingHandler extends OwBaseThingHandler {
.forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId)); .forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId));
// add or update wanted channels // add or update wanted channels
wantedChannel.stream().forEach(channelConfig -> { wantedChannel.forEach(channelConfig -> {
addChannelIfMissingAndEnable(thingBuilder, channelConfig); addChannelIfMissingAndEnable(thingBuilder, channelConfig);
}); });

View File

@ -14,11 +14,8 @@ package org.openhab.binding.onewire.internal.handler;
import static org.openhab.binding.onewire.internal.OwBindingConstants.*; import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.onewire.internal.DS2438Configuration; import org.openhab.binding.onewire.internal.DS2438Configuration;
@ -44,10 +41,9 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault @NonNullByDefault
public class BasicMultisensorThingHandler extends OwBaseThingHandler { public class BasicMultisensorThingHandler extends OwBaseThingHandler {
public Logger logger = LoggerFactory.getLogger(BasicMultisensorThingHandler.class); public Logger logger = LoggerFactory.getLogger(BasicMultisensorThingHandler.class);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_MS_TX); public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_MS_TX);
public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Collections public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.MS_TH, OwSensorType.MS_TC,
.unmodifiableSet(Stream.of(OwSensorType.MS_TH, OwSensorType.MS_TC, OwSensorType.MS_TL, OwSensorType.MS_TV, OwSensorType.MS_TL, OwSensorType.MS_TV, OwSensorType.DS1923, OwSensorType.DS2438);
OwSensorType.DS1923, OwSensorType.DS2438).collect(Collectors.toSet()));
public BasicMultisensorThingHandler(Thing thing, public BasicMultisensorThingHandler(Thing thing,
OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) { OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
@ -74,24 +70,17 @@ public class BasicMultisensorThingHandler extends OwBaseThingHandler {
sensors.add(new DS2438(sensorId, this)); sensors.add(new DS2438(sensorId, this));
} }
scheduler.execute(() -> { scheduler.execute(this::configureThingChannels);
configureThingChannels();
});
} }
@Override @Override
protected void configureThingChannels() { protected void configureThingChannels() {
switch (sensorType) { switch (sensorType) {
case DS2438: case DS2438 -> ((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.INTERNAL);
((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.INTERNAL); case MS_TC -> ((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.IBUTTONLINK);
break; case MS_TL -> ((DS2438) sensors.get(0)).setLightSensorType(LightSensorType.IBUTTONLINK);
case MS_TC: default -> {
((DS2438) sensors.get(0)).setCurrentSensorType(CurrentSensorType.IBUTTONLINK); }
break;
case MS_TL:
((DS2438) sensors.get(0)).setLightSensorType(LightSensorType.IBUTTONLINK);
break;
default:
} }
super.configureThingChannels(); super.configureThingChannels();

View File

@ -14,10 +14,7 @@ package org.openhab.binding.onewire.internal.handler;
import static org.openhab.binding.onewire.internal.OwBindingConstants.*; import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider; import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider;
@ -45,11 +42,10 @@ import org.slf4j.LoggerFactory;
*/ */
@NonNullByDefault @NonNullByDefault
public class BasicThingHandler extends OwBaseThingHandler { public class BasicThingHandler extends OwBaseThingHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BASIC); public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BASIC);
public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Collections public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.DS1420, OwSensorType.DS18B20,
.unmodifiableSet(Stream.of(OwSensorType.DS1420, OwSensorType.DS18B20, OwSensorType.DS18S20, OwSensorType.DS18S20, OwSensorType.DS1822, OwSensorType.DS2401, OwSensorType.DS2405, OwSensorType.DS2406,
OwSensorType.DS1822, OwSensorType.DS2401, OwSensorType.DS2405, OwSensorType.DS2406, OwSensorType.DS2408, OwSensorType.DS2413, OwSensorType.DS2423);
OwSensorType.DS2408, OwSensorType.DS2413, OwSensorType.DS2423).collect(Collectors.toSet()));
private final Logger logger = LoggerFactory.getLogger(BasicThingHandler.class); private final Logger logger = LoggerFactory.getLogger(BasicThingHandler.class);
@ -65,36 +61,17 @@ public class BasicThingHandler extends OwBaseThingHandler {
// add sensor // add sensor
switch (sensorType) { switch (sensorType) {
case DS18B20: case DS18B20, DS18S20, DS1822 -> sensors.add(new DS18x20(sensorId, this));
case DS18S20: case DS1420, DS2401 -> sensors.add(new DS2401(sensorId, this));
case DS1822: case DS2405 -> sensors.add(new DS2405(sensorId, this));
sensors.add(new DS18x20(sensorId, this)); case DS2406, DS2413 -> sensors.add(new DS2406_DS2413(sensorId, this));
break; case DS2408 -> sensors.add(new DS2408(sensorId, this));
case DS1420: case DS2423 -> sensors.add(new DS2423(sensorId, this));
case DS2401: default -> throw new IllegalArgumentException(
sensors.add(new DS2401(sensorId, this)); "unsupported sensorType " + sensorType.name() + ", this should have been checked before!");
break;
case DS2405:
sensors.add(new DS2405(sensorId, this));
break;
case DS2406:
case DS2413:
sensors.add(new DS2406_DS2413(sensorId, this));
break;
case DS2408:
sensors.add(new DS2408(sensorId, this));
break;
case DS2423:
sensors.add(new DS2423(sensorId, this));
break;
default:
throw new IllegalArgumentException(
"unsupported sensorType " + sensorType.name() + ", this should have been checked before!");
} }
scheduler.execute(() -> { scheduler.execute(this::configureThingChannels);
configureThingChannels();
});
} }
@Override @Override

View File

@ -18,8 +18,6 @@ import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider; import org.openhab.binding.onewire.internal.OwDynamicStateDescriptionProvider;
@ -37,10 +35,9 @@ import org.openhab.core.thing.ThingTypeUID;
*/ */
@NonNullByDefault @NonNullByDefault
public class EDSSensorThingHandler extends OwBaseThingHandler { public class EDSSensorThingHandler extends OwBaseThingHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_EDS_ENV); public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_EDS_ENV);
public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Collections public static final Set<OwSensorType> SUPPORTED_SENSOR_TYPES = Set.of(OwSensorType.EDS0064, OwSensorType.EDS0065,
.unmodifiableSet(Stream.of(OwSensorType.EDS0064, OwSensorType.EDS0065, OwSensorType.EDS0066, OwSensorType.EDS0066, OwSensorType.EDS0067, OwSensorType.EDS0068);
OwSensorType.EDS0067, OwSensorType.EDS0068).collect(Collectors.toSet()));
private static final Set<String> REQUIRED_PROPERTIES = Collections.singleton(PROPERTY_HW_REVISION); private static final Set<String> REQUIRED_PROPERTIES = Collections.singleton(PROPERTY_HW_REVISION);
public EDSSensorThingHandler(Thing thing, OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) { public EDSSensorThingHandler(Thing thing, OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
@ -56,9 +53,7 @@ public class EDSSensorThingHandler extends OwBaseThingHandler {
// add sensors // add sensors
sensors.add(new EDS006x(sensorId, sensorType, this)); sensors.add(new EDS006x(sensorId, sensorType, this));
scheduler.execute(() -> { scheduler.execute(this::configureThingChannels);
configureThingChannels();
});
} }
@Override @Override
@ -70,7 +65,7 @@ public class EDSSensorThingHandler extends OwBaseThingHandler {
OwSensorType sensorType = OwSensorType.UNKNOWN; OwSensorType sensorType = OwSensorType.UNKNOWN;
try { try {
sensorType = OwSensorType.valueOf(new String(pages.getPage(0), 0, 7, StandardCharsets.US_ASCII)); sensorType = OwSensorType.valueOf(new String(pages.getPage(0), 0, 7, StandardCharsets.US_ASCII));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException ignored) {
} }
if (!SUPPORTED_SENSOR_TYPES.contains(sensorType)) { if (!SUPPORTED_SENSOR_TYPES.contains(sensorType)) {

View File

@ -15,14 +15,12 @@ package org.openhab.binding.onewire.internal.handler;
import static org.openhab.binding.onewire.internal.OwBindingConstants.*; import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -43,6 +41,7 @@ import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingStatusInfo; import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.ChannelBuilder; import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder; import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.types.Command; import org.openhab.core.types.Command;
@ -64,8 +63,7 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
protected static final int PROPERTY_UPDATE_INTERVAL = 5000; // in ms protected static final int PROPERTY_UPDATE_INTERVAL = 5000; // in ms
protected static final int PROPERTY_UPDATE_MAX_RETRY = 5; protected static final int PROPERTY_UPDATE_MAX_RETRY = 5;
private static final Set<String> REQUIRED_PROPERTIES = Collections private static final Set<String> REQUIRED_PROPERTIES = Set.of(PROPERTY_MODELID, PROPERTY_VENDOR);
.unmodifiableSet(Stream.of(PROPERTY_MODELID, PROPERTY_VENDOR).collect(Collectors.toSet()));
protected List<String> requiredProperties = new ArrayList<>(REQUIRED_PROPERTIES); protected List<String> requiredProperties = new ArrayList<>(REQUIRED_PROPERTIES);
protected Set<OwSensorType> supportedSensorTypes; protected Set<OwSensorType> supportedSensorTypes;
@ -137,7 +135,7 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
return false; return false;
} }
refreshInterval = configuration.refresh * 1000; refreshInterval = configuration.refresh * 1000L;
// check if all required properties are present. update if not // check if all required properties are present. update if not
for (String property : requiredProperties) { for (String property : requiredProperties) {
@ -166,13 +164,13 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
// remove unwanted channels // remove unwanted channels
Set<String> existingChannelIds = thing.getChannels().stream().map(channel -> channel.getUID().getId()) Set<String> existingChannelIds = thing.getChannels().stream().map(channel -> channel.getUID().getId())
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Set<String> wantedChannelIds = SENSOR_TYPE_CHANNEL_MAP.get(sensorType).stream() Set<String> wantedChannelIds = SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of()).stream()
.map(channelConfig -> channelConfig.channelId).collect(Collectors.toSet()); .map(channelConfig -> channelConfig.channelId).collect(Collectors.toSet());
existingChannelIds.stream().filter(channelId -> !wantedChannelIds.contains(channelId)) existingChannelIds.stream().filter(channelId -> !wantedChannelIds.contains(channelId))
.forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId)); .forEach(channelId -> removeChannelIfExisting(thingBuilder, channelId));
// add or update wanted channels // add or update wanted channels
SENSOR_TYPE_CHANNEL_MAP.get(sensorType).stream().forEach(channelConfig -> { SENSOR_TYPE_CHANNEL_MAP.getOrDefault(sensorType, Set.of()).stream().forEach(channelConfig -> {
addChannelIfMissingAndEnable(thingBuilder, channelConfig); addChannelIfMissingAndEnable(thingBuilder, channelConfig);
}); });
@ -325,8 +323,7 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
* called by the bridge handler * called by the bridge handler
* *
* @param bridgeHandler the bridge handler to be used * @param bridgeHandler the bridge handler to be used
* @return properties to be added to the properties map * @throws OwException in case an error occurs
* @throws OwException
*/ */
public void updateSensorProperties(OwserverBridgeHandler bridgeHandler) throws OwException { public void updateSensorProperties(OwserverBridgeHandler bridgeHandler) throws OwException {
Map<String, String> properties = editProperties(); Map<String, String> properties = editProperties();
@ -365,10 +362,9 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
* *
* @param thingBuilder ThingBuilder of the edited thing * @param thingBuilder ThingBuilder of the edited thing
* @param channelConfig a OwChannelConfig for the new channel * @param channelConfig a OwChannelConfig for the new channel
* @return the newly created channel
*/ */
protected Channel addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig) { protected void addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig) {
return addChannelIfMissingAndEnable(thingBuilder, channelConfig, null, 0); addChannelIfMissingAndEnable(thingBuilder, channelConfig, null, 0);
} }
/** /**
@ -377,11 +373,10 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
* @param thingBuilder ThingBuilder of the edited thing * @param thingBuilder ThingBuilder of the edited thing
* @param channelConfig a OwChannelConfig for the new channel * @param channelConfig a OwChannelConfig for the new channel
* @param configuration the new Configuration for this channel * @param configuration the new Configuration for this channel
* @return the newly created channel
*/ */
protected Channel addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig, protected void addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig,
Configuration configuration) { Configuration configuration) {
return addChannelIfMissingAndEnable(thingBuilder, channelConfig, configuration, 0); addChannelIfMissingAndEnable(thingBuilder, channelConfig, configuration, 0);
} }
/** /**
@ -390,11 +385,10 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
* @param thingBuilder ThingBuilder of the edited thing * @param thingBuilder ThingBuilder of the edited thing
* @param channelConfig a OwChannelConfig for the new channel * @param channelConfig a OwChannelConfig for the new channel
* @param sensorNo number of sensor that provides this channel * @param sensorNo number of sensor that provides this channel
* @return the newly created channel
*/ */
protected Channel addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig, protected void addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig,
int sensorNo) { int sensorNo) {
return addChannelIfMissingAndEnable(thingBuilder, channelConfig, null, sensorNo); addChannelIfMissingAndEnable(thingBuilder, channelConfig, null, sensorNo);
} }
/** /**
@ -404,9 +398,8 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
* @param channelConfig a OwChannelConfig for the new channel * @param channelConfig a OwChannelConfig for the new channel
* @param configuration the new Configuration for this channel * @param configuration the new Configuration for this channel
* @param sensorNo number of sensor that provides this channel * @param sensorNo number of sensor that provides this channel
* @return the newly created channel
*/ */
protected Channel addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig, protected void addChannelIfMissingAndEnable(ThingBuilder thingBuilder, OwChannelConfig channelConfig,
@Nullable Configuration configuration, int sensorNo) { @Nullable Configuration configuration, int sensorNo) {
Channel channel = thing.getChannel(channelConfig.channelId); Channel channel = thing.getChannel(channelConfig.channelId);
Configuration config = configuration; Configuration config = configuration;
@ -423,23 +416,28 @@ public abstract class OwBaseThingHandler extends BaseThingHandler {
// create channel if missing // create channel if missing
if (channel == null) { if (channel == null) {
ChannelBuilder channelBuilder = ChannelBuilder ChannelUID channelUID = new ChannelUID(thing.getUID(), channelConfig.channelId);
.create(new ChannelUID(thing.getUID(), channelConfig.channelId),
ACCEPTED_ITEM_TYPES_MAP.get(channelConfig.channelId)) ThingHandlerCallback callback = getCallback();
.withType(channelConfig.channelTypeUID); if (callback == null) {
logger.warn("Could not get callback, adding '{}' failed.", channelUID);
return;
}
ChannelBuilder channelBuilder = callback.createChannelBuilder(channelUID, channelConfig.channelTypeUID);
if (label != null) { if (label != null) {
channelBuilder.withLabel(label); channelBuilder.withLabel(label);
} }
if (config != null) { if (config != null) {
channelBuilder.withConfiguration(config); channelBuilder.withConfiguration(config);
} }
channel = channelBuilder.build(); channel = channelBuilder.build();
thingBuilder.withChannel(channel); thingBuilder.withChannel(channel);
} }
// enable channel in sensor // enable channel in sensor
sensors.get(sensorNo).enableChannel(channelConfig.channelId); sensors.get(sensorNo).enableChannel(channelConfig.channelId);
return channel;
} }
} }

View File

@ -17,6 +17,7 @@ import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -32,6 +33,7 @@ import org.openhab.binding.onewire.internal.OwException;
import org.openhab.binding.onewire.internal.OwPageBuffer; import org.openhab.binding.onewire.internal.OwPageBuffer;
import org.openhab.binding.onewire.internal.SensorId; import org.openhab.binding.onewire.internal.SensorId;
import org.openhab.binding.onewire.internal.device.OwSensorType; import org.openhab.binding.onewire.internal.device.OwSensorType;
import org.openhab.binding.onewire.internal.discovery.OwDiscoveryService;
import org.openhab.binding.onewire.internal.owserver.OwfsDirectChannelConfig; import org.openhab.binding.onewire.internal.owserver.OwfsDirectChannelConfig;
import org.openhab.binding.onewire.internal.owserver.OwserverConnection; import org.openhab.binding.onewire.internal.owserver.OwserverConnection;
import org.openhab.binding.onewire.internal.owserver.OwserverConnectionState; import org.openhab.binding.onewire.internal.owserver.OwserverConnectionState;
@ -47,6 +49,7 @@ import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseBridgeHandler; import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.openhab.core.types.Command; import org.openhab.core.types.Command;
import org.openhab.core.types.State; import org.openhab.core.types.State;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -236,7 +239,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* *
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @return ON if present, OFF if missing * @return ON if present, OFF if missing
* @throws OwException * @throws OwException in case an error occurs
*/ */
public State checkPresence(SensorId sensorId) throws OwException { public State checkPresence(SensorId sensorId) throws OwException {
synchronized (owserverConnection) { synchronized (owserverConnection) {
@ -249,14 +252,14 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* *
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @return a String containing the sensor type * @return a String containing the sensor type
* @throws OwException * @throws OwException in case an error occurs
*/ */
public OwSensorType getType(SensorId sensorId) throws OwException { public OwSensorType getType(SensorId sensorId) throws OwException {
OwSensorType sensorType = OwSensorType.UNKNOWN; OwSensorType sensorType = OwSensorType.UNKNOWN;
synchronized (owserverConnection) { synchronized (owserverConnection) {
try { try {
sensorType = OwSensorType.valueOf(owserverConnection.readString(sensorId + "/type")); sensorType = OwSensorType.valueOf(owserverConnection.readString(sensorId + "/type"));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException ignored) {
} }
} }
return sensorType; return sensorType;
@ -267,7 +270,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* *
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @return a OwPageBuffer object containing the requested information * @return a OwPageBuffer object containing the requested information
* @throws OwException * @throws OwException in case an error occurs
*/ */
public OwPageBuffer readPages(SensorId sensorId) throws OwException { public OwPageBuffer readPages(SensorId sensorId) throws OwException {
synchronized (owserverConnection) { synchronized (owserverConnection) {
@ -281,7 +284,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @param parameter device parameters needed for this request * @param parameter device parameters needed for this request
* @return a DecimalType * @return a DecimalType
* @throws OwException * @throws OwException in case an error occurs
*/ */
public State readDecimalType(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException { public State readDecimalType(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException {
synchronized (owserverConnection) { synchronized (owserverConnection) {
@ -295,7 +298,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @param parameter device parameters needed for this request * @param parameter device parameters needed for this request
* @return a BitSet * @return a BitSet
* @throws OwException * @throws OwException in case an error occurs
*/ */
public BitSet readBitSet(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException { public BitSet readBitSet(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException {
return BitSet.valueOf(new long[] { ((DecimalType) readDecimalType(sensorId, parameter)).longValue() }); return BitSet.valueOf(new long[] { ((DecimalType) readDecimalType(sensorId, parameter)).longValue() });
@ -307,7 +310,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @param parameter device parameters needed for this request * @param parameter device parameters needed for this request
* @return a list of DecimalType values * @return a list of DecimalType values
* @throws OwException * @throws OwException in case an error occurs
*/ */
public List<State> readDecimalTypeArray(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException { public List<State> readDecimalTypeArray(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException {
synchronized (owserverConnection) { synchronized (owserverConnection) {
@ -321,7 +324,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @param parameter device parameters needed for this request * @param parameter device parameters needed for this request
* @return a String * @return a String
* @throws OwException * @throws OwException in case an error occurs
*/ */
public String readString(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException { public String readString(SensorId sensorId, OwserverDeviceParameter parameter) throws OwException {
synchronized (owserverConnection) { synchronized (owserverConnection) {
@ -334,7 +337,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* *
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @param parameter device parameters needed for this request * @param parameter device parameters needed for this request
* @throws OwException * @throws OwException in case an error occurs
*/ */
public void writeDecimalType(SensorId sensorId, OwserverDeviceParameter parameter, DecimalType value) public void writeDecimalType(SensorId sensorId, OwserverDeviceParameter parameter, DecimalType value)
throws OwException { throws OwException {
@ -348,7 +351,7 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
* *
* @param sensorId the sensor's full ID * @param sensorId the sensor's full ID
* @param parameter device parameters needed for this request * @param parameter device parameters needed for this request
* @throws OwException * @throws OwException in case an error occurs
*/ */
public void writeBitSet(SensorId sensorId, OwserverDeviceParameter parameter, BitSet value) throws OwException { public void writeBitSet(SensorId sensorId, OwserverDeviceParameter parameter, BitSet value) throws OwException {
writeDecimalType(sensorId, parameter, new DecimalType(value.toLongArray()[0])); writeDecimalType(sensorId, parameter, new DecimalType(value.toLongArray()[0]));
@ -427,4 +430,9 @@ public class OwserverBridgeHandler extends BaseBridgeHandler {
} }
} }
} }
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Set.of(OwDiscoveryService.class);
}
} }

View File

@ -174,8 +174,7 @@ public class OwserverConnection {
returnValue = OnOffType.ON; returnValue = OnOffType.ON;
} }
} catch (OwException e) { } catch (OwException ignored) {
returnValue = OnOffType.OFF;
} }
logger.trace("presence {} : {}", path, returnValue); logger.trace("presence {} : {}", path, returnValue);
return returnValue; return returnValue;
@ -186,7 +185,7 @@ public class OwserverConnection {
* *
* @param path full owfs path to sensor * @param path full owfs path to sensor
* @return DecimalType if successful * @return DecimalType if successful
* @throws OwException * @throws OwException in case an error occurs
*/ */
public State readDecimalType(String path) throws OwException { public State readDecimalType(String path) throws OwException {
State returnState = UnDefType.UNDEF; State returnState = UnDefType.UNDEF;
@ -211,7 +210,7 @@ public class OwserverConnection {
* *
* @param path full owfs path to sensor * @param path full owfs path to sensor
* @return a List of DecimalType values if successful * @return a List of DecimalType values if successful
* @throws OwException * @throws OwException in case an error occurs
*/ */
public List<State> readDecimalTypeArray(String path) throws OwException { public List<State> readDecimalTypeArray(String path) throws OwException {
List<State> returnList = new ArrayList<>(); List<State> returnList = new ArrayList<>();
@ -232,7 +231,7 @@ public class OwserverConnection {
* *
* @param path full owfs path to sensor * @param path full owfs path to sensor
* @return requested String * @return requested String
* @throws OwException * @throws OwException in case an error occurs
*/ */
public String readString(String path) throws OwException { public String readString(String path) throws OwException {
OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.READ, path); OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.READ, path);
@ -250,7 +249,7 @@ public class OwserverConnection {
* *
* @param path full owfs path to sensor * @param path full owfs path to sensor
* @return page buffer * @return page buffer
* @throws OwException * @throws OwException in case an error occurs
*/ */
public OwPageBuffer readPages(String path) throws OwException { public OwPageBuffer readPages(String path) throws OwException {
OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.READ, path + "/pages/page.ALL"); OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.READ, path + "/pages/page.ALL");
@ -267,7 +266,7 @@ public class OwserverConnection {
* *
* @param path full owfs path to the sensor * @param path full owfs path to the sensor
* @param value the value to write * @param value the value to write
* @throws OwException * @throws OwException in case an error occurs
*/ */
public void writeDecimalType(String path, DecimalType value) throws OwException { public void writeDecimalType(String path, DecimalType value) throws OwException {
OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.WRITE, path); OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.WRITE, path);
@ -284,7 +283,7 @@ public class OwserverConnection {
* *
* @param requestPacket the request to be send * @param requestPacket the request to be send
* @return the raw owserver answer * @return the raw owserver answer
* @throws OwException * @throws OwException in case an error occurs
*/ */
private OwserverPacket request(OwserverPacket requestPacket) throws OwException { private OwserverPacket request(OwserverPacket requestPacket) throws OwException {
OwserverPacket returnPacket = new OwserverPacket(OwserverPacketType.RETURN); OwserverPacket returnPacket = new OwserverPacket(OwserverPacketType.RETURN);
@ -441,7 +440,7 @@ public class OwserverConnection {
* {@link OwException} is thrown. * {@link OwException} is thrown.
* *
* @param requestPacket data to write * @param requestPacket data to write
* @throws OwException * @throws OwException in case an error occurs
*/ */
private void write(OwserverPacket requestPacket) throws OwException { private void write(OwserverPacket requestPacket) throws OwException {
try { try {
@ -475,7 +474,7 @@ public class OwserverConnection {
* *
* @param noTimeoutException retry in case of read time outs instead of exiting with an {@link OwException}. * @param noTimeoutException retry in case of read time outs instead of exiting with an {@link OwException}.
* @return the read packet * @return the read packet
* @throws OwException * @throws OwException in case an error occurs
*/ */
private OwserverPacket read(boolean noTimeoutException) throws OwException { private OwserverPacket read(boolean noTimeoutException) throws OwException {
OwserverPacket returnPacket = new OwserverPacket(OwserverPacketType.RETURN); OwserverPacket returnPacket = new OwserverPacket(OwserverPacketType.RETURN);
@ -495,7 +494,7 @@ public class OwserverConnection {
throw e; throw e;
} catch (IOException e) { } catch (IOException e) {
// Read time out // Read time out
if (e.getMessage().equals("Read timed out") && noTimeoutException) { if ("Read timed out".equals(e.getMessage()) && noTimeoutException) {
logger.trace("timeout - setting error code to -1"); logger.trace("timeout - setting error code to -1");
// will lead to re-try reading in request method!!! // will lead to re-try reading in request method!!!
returnPacket.setPayload("timeout"); returnPacket.setPayload("timeout");

View File

@ -39,6 +39,9 @@ public class OwserverDeviceParameter {
} else { } else {
this.prefix = prefix; this.prefix = prefix;
} }
if (this.prefix.startsWith("/")) {
this.prefix = this.prefix.substring(1);
}
if (path.startsWith("/")) { if (path.startsWith("/")) {
this.path = path; this.path = path;
} else { } else {

View File

@ -13,7 +13,6 @@
package org.openhab.binding.onewire.internal.owserver; package org.openhab.binding.onewire.internal.owserver;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -60,10 +59,10 @@ public class OwserverPacket {
* *
* @param owInputStream input stream to read from * @param owInputStream input stream to read from
* @throws IOException * @throws IOException
* @throws OwExeption * @throws OwException in case an error occurs
*/ */
public OwserverPacket(DataInputStream owInputStream, OwserverPacketType packetType) public OwserverPacket(DataInputStream owInputStream, OwserverPacketType packetType)
throws IOException, OwException, EOFException { throws IOException, OwException {
this.packetType = packetType; this.packetType = packetType;
// header // header
@ -148,7 +147,7 @@ public class OwserverPacket {
/** /**
* set this packet's temperature scale * set this packet's temperature scale
* *
* @param pressureScale * @param temperatureScale
*/ */
public void setTemperatureScale(OwserverTemperatureScale temperatureScale) { public void setTemperatureScale(OwserverTemperatureScale temperatureScale) {
controlFlags = temperatureScale.setFlag(controlFlags); controlFlags = temperatureScale.setFlag(controlFlags);
@ -181,7 +180,7 @@ public class OwserverPacket {
* @param payload string representation of the payload to append * @param payload string representation of the payload to append
*/ */
public void appendPayload(String payload) { public void appendPayload(String payload) {
byte appendBytes[] = payload.getBytes(); byte[] appendBytes = payload.getBytes();
byte[] fullPayload = new byte[this.payload.length + appendBytes.length]; byte[] fullPayload = new byte[this.payload.length + appendBytes.length];
System.arraycopy(this.payload, 0, fullPayload, 0, this.payload.length); System.arraycopy(this.payload, 0, fullPayload, 0, this.payload.length);
@ -298,8 +297,7 @@ public class OwserverPacket {
* @return OwPageBuffer with this packet's payload * @return OwPageBuffer with this packet's payload
*/ */
public OwPageBuffer getPayload() { public OwPageBuffer getPayload() {
OwPageBuffer byteBuffer = new OwPageBuffer(payload); return new OwPageBuffer(payload);
return byteBuffer;
} }
/** /**

View File

@ -109,9 +109,9 @@ channel-type.onewire.dewpoint.label = Dewpoint
channel-type.onewire.dewpoint.description = dewpoint (calculated from temperature and relative humidity) channel-type.onewire.dewpoint.description = dewpoint (calculated from temperature and relative humidity)
channel-type.onewire.dio.label = Digital I/O channel-type.onewire.dio.label = Digital I/O
channel-type.onewire.humidity.label = Humidity channel-type.onewire.humidity.label = Humidity
channel-type.onewire.humidity.description = relative humidity (0-100%) channel-type.onewire.humidity.description = Relative humidity (0-100%)
channel-type.onewire.humidityconf.label = Humidity channel-type.onewire.humidityconf.label = Humidity
channel-type.onewire.humidityconf.description = relative humidity (0-100%) channel-type.onewire.humidityconf.description = Relative humidity (0-100%)
channel-type.onewire.light.label = Illuminance channel-type.onewire.light.label = Illuminance
channel-type.onewire.light.description = Ambient light channel-type.onewire.light.description = Ambient light
channel-type.onewire.owfs-number.label = Direct Access to OWFS-Path (Number) channel-type.onewire.owfs-number.label = Direct Access to OWFS-Path (Number)

View File

@ -65,14 +65,14 @@
<channel-type id="humidity"> <channel-type id="humidity">
<item-type>Number:Dimensionless</item-type> <item-type>Number:Dimensionless</item-type>
<label>Humidity</label> <label>Humidity</label>
<description>relative humidity (0-100%)</description> <description>Relative humidity (0-100%)</description>
<state readOnly="true" pattern="%d %%"/> <state readOnly="true" pattern="%.0f %%"/>
</channel-type> </channel-type>
<channel-type id="humidityconf"> <channel-type id="humidityconf">
<item-type>Number:Dimensionless</item-type> <item-type>Number:Dimensionless</item-type>
<label>Humidity</label> <label>Humidity</label>
<description>relative humidity (0-100%)</description> <description>Relative humidity (0-100%)</description>
<state readOnly="true" pattern="%d %%"/> <state readOnly="true" pattern="%.0f %%"/>
<config-description> <config-description>
<parameter name="humiditytype" type="text" required="false"> <parameter name="humiditytype" type="text" required="false">
<label>Humidity Sensor-Type</label> <label>Humidity Sensor-Type</label>

View File

@ -1,29 +0,0 @@
humidity = Number:Dimensionless
absolutehumidity = Number:Density
dewpoint = Number:Temperature
temperature = Number:Temperature
light = Number:Illuminance
pressure = Number:Pressure
voltage = Number:ElectricPotential
supplyvoltage = Number:ElectricPotential
current = Number:ElectricCurrent
counter = Number
counter0 = Number
counter1 = Number
digital = Switch
digital0 = Switch
digital1 = Switch
digital2 = Switch
digital3 = Switch
digital4 = Switch
digital5 = Switch
digital6 = Switch
digital7 = Switch
digital8 = Switch
present = Switch
pwmduty1 = Number:Dimensionsless
pwmduty2 = Number:Dimensionsless
pwmduty3 = Number:Dimensionsless
pwmduty4 = Number:Dimensionsless
pwmfreq1 = Number:Frequency
pwmfreq2 = Number:Frequency

View File

@ -14,11 +14,8 @@ package org.openhab.binding.onewire;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -26,7 +23,6 @@ import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.openhab.binding.onewire.internal.OwBindingConstants; import org.openhab.binding.onewire.internal.OwBindingConstants;
import org.openhab.binding.onewire.internal.OwException;
import org.openhab.binding.onewire.internal.device.OwSensorType; import org.openhab.binding.onewire.internal.device.OwSensorType;
import org.openhab.binding.onewire.internal.handler.AdvancedMultisensorThingHandler; import org.openhab.binding.onewire.internal.handler.AdvancedMultisensorThingHandler;
import org.openhab.binding.onewire.internal.handler.BAE091xSensorThingHandler; import org.openhab.binding.onewire.internal.handler.BAE091xSensorThingHandler;
@ -42,9 +38,8 @@ import org.openhab.binding.onewire.internal.handler.EDSSensorThingHandler;
@NonNullByDefault @NonNullByDefault
public class CompletenessTest { public class CompletenessTest {
// internal/temporary types, DS2409 (MicroLAN Coupler), DS2431 (EEPROM) // internal/temporary types, DS2409 (MicroLAN Coupler), DS2431 (EEPROM)
private static final Set<OwSensorType> IGNORED_SENSOR_TYPES = Collections private static final Set<OwSensorType> IGNORED_SENSOR_TYPES = Set.of(OwSensorType.DS2409, OwSensorType.DS2431,
.unmodifiableSet(Stream.of(OwSensorType.DS2409, OwSensorType.DS2431, OwSensorType.EDS, OwSensorType.MS_TH_S, OwSensorType.EDS, OwSensorType.MS_TH_S, OwSensorType.BAE, OwSensorType.BAE0911, OwSensorType.UNKNOWN);
OwSensorType.BAE, OwSensorType.BAE0911, OwSensorType.UNKNOWN).collect(Collectors.toSet()));
private static final Set<OwSensorType> THINGHANDLER_SENSOR_TYPES = Collections.unmodifiableSet(Stream private static final Set<OwSensorType> THINGHANDLER_SENSOR_TYPES = Collections.unmodifiableSet(Stream
.of(AdvancedMultisensorThingHandler.SUPPORTED_SENSOR_TYPES, .of(AdvancedMultisensorThingHandler.SUPPORTED_SENSOR_TYPES,
@ -90,24 +85,4 @@ public class CompletenessTest {
} }
} }
} }
@Test
public void acceptedItemTypeMapCompleteness() throws OwException {
List<String> channels = Arrays.stream(OwBindingConstants.class.getDeclaredFields())
.filter(f -> Modifier.isStatic(f.getModifiers()))
.filter(f -> f.getName().startsWith("CHANNEL") && !f.getName().startsWith("CHANNEL_TYPE")).map(f -> {
try {
return (String) f.get(null);
} catch (IllegalAccessException e) {
fail("unexpected");
return null;
}
}).collect(Collectors.toList());
for (String channel : channels) {
if (!OwBindingConstants.ACCEPTED_ITEM_TYPES_MAP.containsKey(channel)) {
fail("missing accepted item type for channel " + channel);
}
}
}
} }

View File

@ -37,25 +37,26 @@ public class OwserverDeviceParameterTest {
assertEquals("/1F.0123456789ab/main/00.1234567890ab/humidity", owserverDeviceParameter.getPath(sensorId)); assertEquals("/1F.0123456789ab/main/00.1234567890ab/humidity", owserverDeviceParameter.getPath(sensorId));
} }
@Test
public void withPrefixTest() { public void withPrefixTest() {
OwserverDeviceParameter owserverDeviceParameter = new OwserverDeviceParameter("uncached", "/humidity"); OwserverDeviceParameter owserverDeviceParameter = new OwserverDeviceParameter("uncached", "/humidity");
assertEquals("/uncached/1F.0123456789ab/main/00.1234567890ab/humidity", assertEquals("uncached/1F.0123456789ab/main/00.1234567890ab/humidity",
owserverDeviceParameter.getPath(sensorId)); owserverDeviceParameter.getPath(sensorId));
owserverDeviceParameter = new OwserverDeviceParameter("uncached", "/humidity"); owserverDeviceParameter = new OwserverDeviceParameter("uncached", "/humidity");
assertEquals("/uncached/1F.0123456789ab/main/00.1234567890ab/humidity", assertEquals("uncached/1F.0123456789ab/main/00.1234567890ab/humidity",
owserverDeviceParameter.getPath(sensorId)); owserverDeviceParameter.getPath(sensorId));
owserverDeviceParameter = new OwserverDeviceParameter("/uncached", "/humidity"); owserverDeviceParameter = new OwserverDeviceParameter("/uncached", "/humidity");
assertEquals("/uncached/1F.0123456789ab/main/00.1234567890ab/humidity", assertEquals("uncached/1F.0123456789ab/main/00.1234567890ab/humidity",
owserverDeviceParameter.getPath(sensorId)); owserverDeviceParameter.getPath(sensorId));
owserverDeviceParameter = new OwserverDeviceParameter("/uncached/", "/humidity"); owserverDeviceParameter = new OwserverDeviceParameter("/uncached/", "/humidity");
assertEquals("/uncached/1F.0123456789ab/main/00.1234567890ab/humidity", assertEquals("uncached/1F.0123456789ab/main/00.1234567890ab/humidity",
owserverDeviceParameter.getPath(sensorId)); owserverDeviceParameter.getPath(sensorId));
owserverDeviceParameter = new OwserverDeviceParameter("uncached/", "/humidity"); owserverDeviceParameter = new OwserverDeviceParameter("uncached/", "/humidity");
assertEquals("/uncached/1F.0123456789ab/main/00.1234567890ab/humidity", assertEquals("uncached/1F.0123456789ab/main/00.1234567890ab/humidity",
owserverDeviceParameter.getPath(sensorId)); owserverDeviceParameter.getPath(sensorId));
} }
} }

View File

@ -71,7 +71,7 @@ public class SensorIdTest {
SensorId sensorId2 = new SensorId("1F.0123456789ab/aux/28.0123456789ab"); SensorId sensorId2 = new SensorId("1F.0123456789ab/aux/28.0123456789ab");
SensorId sensorId3 = new SensorId("1F.0123456789ab/aux/28.0123456789ac"); SensorId sensorId3 = new SensorId("1F.0123456789ab/aux/28.0123456789ac");
assertTrue(sensorId1.equals(sensorId2)); assertEquals(sensorId1, sensorId2);
assertFalse(sensorId1.equals(sensorId3)); assertNotEquals(sensorId1, sensorId3);
} }
} }

View File

@ -287,7 +287,7 @@ public class BAE0910Test extends DeviceTestParent<BAE0910> {
* *
* @param registerIndex number of register to return * @param registerIndex number of register to return
* @return this register's BitSet * @return this register's BitSet
* @throws OwException * @throws OwException in case an error occurs
*/ */
private BitSet checkConfiguration(int registerIndex) throws OwException { private BitSet checkConfiguration(int registerIndex) throws OwException {
ArgumentCaptor<BitSet> configArgumentCaptor = ArgumentCaptor.forClass(BitSet.class); ArgumentCaptor<BitSet> configArgumentCaptor = ArgumentCaptor.forClass(BitSet.class);

View File

@ -42,10 +42,13 @@ import org.openhab.core.library.types.OnOffType;
import org.openhab.core.test.java.JavaTest; import org.openhab.core.test.java.JavaTest;
import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel; import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing; import org.openhab.core.thing.Thing;
import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback; import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.BridgeBuilder; import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.type.ChannelTypeUID;
/** /**
* Base class for thing handler tests. * Base class for thing handler tests.
@ -99,6 +102,13 @@ public abstract class AbstractThingHandlerTest extends JavaTest {
return null; return null;
}).when(thingHandlerCallback).statusUpdated(any(), any()); }).when(thingHandlerCallback).statusUpdated(any(), any());
Mockito.when(thingHandlerCallback.createChannelBuilder(any(), any())).thenAnswer(invocation -> {
ChannelUID channelUID = (ChannelUID) invocation.getArguments()[0];
ChannelTypeUID channelTypeUID = (ChannelTypeUID) invocation.getArguments()[1];
return ChannelBuilder.create(channelUID).withType(channelTypeUID);
});
inOrder = Mockito.inOrder(bridgeHandler); inOrder = Mockito.inOrder(bridgeHandler);
} }