2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.onewire.internal.device;
15 import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
17 import javax.measure.quantity.Dimensionless;
18 import javax.measure.quantity.Temperature;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.onewire.internal.OwException;
22 import org.openhab.binding.onewire.internal.SensorId;
23 import org.openhab.binding.onewire.internal.Util;
24 import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
25 import org.openhab.binding.onewire.internal.handler.OwserverBridgeHandler;
26 import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter;
27 import org.openhab.core.library.types.DecimalType;
28 import org.openhab.core.library.types.QuantityType;
29 import org.openhab.core.library.unit.SIUnits;
30 import org.openhab.core.library.unit.Units;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * The {@link DS1923} class defines a DS1923 device
37 * @author Jan N. Klug - Initial contribution
38 * @author Michał Wójcik - Adapted to DS1923
41 public class DS1923 extends AbstractOwDevice {
42 private final Logger logger = LoggerFactory.getLogger(DS1923.class);
43 private final OwserverDeviceParameter temperatureParameter = new OwserverDeviceParameter("/temperature");
44 private final OwserverDeviceParameter humidityParameter = new OwserverDeviceParameter("/humidity");
46 public DS1923(SensorId sensorId, OwBaseThingHandler callback) {
47 super(sensorId, callback);
51 public void configureChannels() throws OwException {
56 public void refresh(OwserverBridgeHandler bridgeHandler, Boolean forcedRefresh) throws OwException {
58 logger.trace("refresh of sensor {} started", sensorId);
59 if (enabledChannels.contains(CHANNEL_TEMPERATURE) || enabledChannels.contains(CHANNEL_HUMIDITY)
60 || enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)
61 || enabledChannels.contains(CHANNEL_DEWPOINT)) {
62 QuantityType<Temperature> temperature = new QuantityType<>(
63 (DecimalType) bridgeHandler.readDecimalType(sensorId, temperatureParameter), SIUnits.CELSIUS);
64 callback.postUpdate(CHANNEL_TEMPERATURE, temperature);
66 if (enabledChannels.contains(CHANNEL_HUMIDITY) || enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)
67 || enabledChannels.contains(CHANNEL_DEWPOINT)) {
68 QuantityType<Dimensionless> humidity = new QuantityType<>(
69 (DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter), Units.PERCENT);
71 if (enabledChannels.contains(CHANNEL_HUMIDITY)) {
72 callback.postUpdate(CHANNEL_HUMIDITY, humidity);
75 if (enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)) {
76 callback.postUpdate(CHANNEL_ABSOLUTE_HUMIDITY,
77 Util.calculateAbsoluteHumidity(temperature, humidity));
80 if (enabledChannels.contains(CHANNEL_DEWPOINT)) {
81 callback.postUpdate(CHANNEL_DEWPOINT, Util.calculateDewpoint(temperature, humidity));