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.Illuminance;
19 import javax.measure.quantity.Pressure;
20 import javax.measure.quantity.Temperature;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.onewire.internal.OwException;
24 import org.openhab.binding.onewire.internal.SensorId;
25 import org.openhab.binding.onewire.internal.Util;
26 import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
27 import org.openhab.binding.onewire.internal.handler.OwserverBridgeHandler;
28 import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter;
29 import org.openhab.core.library.types.DecimalType;
30 import org.openhab.core.library.types.QuantityType;
31 import org.openhab.core.library.unit.MetricPrefix;
32 import org.openhab.core.library.unit.SIUnits;
33 import org.openhab.core.library.unit.Units;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * The {@link EDS006x} class defines an EDS006x device
40 * @author Jan N. Klug - Initial contribution
43 public class EDS006x extends AbstractOwDevice {
44 private final Logger logger = LoggerFactory.getLogger(EDS006x.class);
45 private OwserverDeviceParameter temperatureParameter = new OwserverDeviceParameter("/temperature");
46 private OwserverDeviceParameter humidityParameter = new OwserverDeviceParameter("/humidity");
47 private OwserverDeviceParameter pressureParameter = new OwserverDeviceParameter("/pressure");
48 private OwserverDeviceParameter lightParameter = new OwserverDeviceParameter("/light");
50 public EDS006x(SensorId sensorId, OwSensorType sensorType, OwBaseThingHandler callback) {
51 super(sensorId, callback);
53 String sensorTypeName = sensorType.name();
54 temperatureParameter = new OwserverDeviceParameter("/" + sensorTypeName + "/temperature");
55 humidityParameter = new OwserverDeviceParameter("/" + sensorTypeName + "/humidity");
56 pressureParameter = new OwserverDeviceParameter("/" + sensorTypeName + "/pressure");
57 lightParameter = new OwserverDeviceParameter("/" + sensorTypeName + "/light");
61 public void configureChannels() {
66 public void refresh(OwserverBridgeHandler bridgeHandler, Boolean forcedRefresh) throws OwException {
68 logger.trace("refresh of sensor {} started", sensorId);
69 if (enabledChannels.contains(CHANNEL_TEMPERATURE) || enabledChannels.contains(CHANNEL_HUMIDITY)
70 || enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)
71 || enabledChannels.contains(CHANNEL_DEWPOINT)) {
72 QuantityType<Temperature> temperature = new QuantityType<>(
73 (DecimalType) bridgeHandler.readDecimalType(sensorId, temperatureParameter), SIUnits.CELSIUS);
75 if (enabledChannels.contains(CHANNEL_TEMPERATURE)) {
76 callback.postUpdate(CHANNEL_TEMPERATURE, temperature);
79 if (enabledChannels.contains(CHANNEL_HUMIDITY) || enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)
80 || enabledChannels.contains(CHANNEL_DEWPOINT)) {
81 QuantityType<Dimensionless> humidity = new QuantityType<>(
82 (DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter), Units.PERCENT);
84 if (enabledChannels.contains(CHANNEL_HUMIDITY)) {
85 callback.postUpdate(CHANNEL_HUMIDITY, humidity);
88 if (enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)) {
89 callback.postUpdate(CHANNEL_ABSOLUTE_HUMIDITY,
90 Util.calculateAbsoluteHumidity(temperature, humidity));
93 if (enabledChannels.contains(CHANNEL_DEWPOINT)) {
94 callback.postUpdate(CHANNEL_DEWPOINT, Util.calculateDewpoint(temperature, humidity));
99 if (enabledChannels.contains(CHANNEL_LIGHT)) {
100 QuantityType<Illuminance> light = new QuantityType<>(
101 (DecimalType) bridgeHandler.readDecimalType(sensorId, lightParameter), Units.LUX);
102 callback.postUpdate(CHANNEL_LIGHT, light);
105 if (enabledChannels.contains(CHANNEL_PRESSURE)) {
106 QuantityType<Pressure> pressure = new QuantityType<>(
107 (DecimalType) bridgeHandler.readDecimalType(sensorId, pressureParameter),
108 MetricPrefix.HECTO(SIUnits.PASCAL));
109 callback.postUpdate(CHANNEL_PRESSURE, pressure);