Skip to content

Commit

Permalink
State pattern for dB, Percent and Microgram/m3 added
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
  • Loading branch information
weymann committed Oct 2, 2023
1 parent afda8c5 commit fdfda11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
<channel-type id="pm25-channel">
<item-type>Number:Density</item-type>
<label>Particulate Matter category 2.5</label>
<state pattern="%.1f %unit%" readOnly="true"/>
<state pattern="%.1f µg/m³" readOnly="true"/>
</channel-type>
<channel-type id="pm100-channel">
<item-type>Number:Density</item-type>
<label>Particulate Matter category 10.0</label>
<state pattern="%.1f %unit%" readOnly="true"/>
<state pattern="%.1f µg/m³" readOnly="true"/>
</channel-type>
<channel-type id="temp-channel">
<item-type>Number:Temperature</item-type>
Expand All @@ -93,7 +93,7 @@
<item-type>Number:Dimensionless</item-type>
<label>Humidity</label>
<description>Humidity from the selected Sensor ID</description>
<state pattern="%.1f %unit%" readOnly="true"/>
<state pattern="%.1f %%" readOnly="true"/>
</channel-type>
<channel-type id="pressure-channel">
<item-type>Number:Pressure</item-type>
Expand All @@ -111,18 +111,18 @@
<item-type>Number:Dimensionless</item-type>
<label>Average Noise</label>
<description>Average noise level from the selected Sensor ID</description>
<state pattern="%.1f %unit%" readOnly="true"/>
<state pattern="%.1f dB" readOnly="true"/>
</channel-type>
<channel-type id="noise-min-channel">
<item-type>Number:Dimensionless</item-type>
<label>Minimum Noise</label>
<description>Minimum noise level (last 2.5 minutes) from the selected Sensor ID</description>
<state pattern="%.1f %unit%" readOnly="true"/>
<state pattern="%.1f dB" readOnly="true"/>
</channel-type>
<channel-type id="noise-max-channel">
<item-type>Number:Dimensionless</item-type>
<label>Maximum Noise</label>
<description>Maximum noise level (last 2.5 minutes) from the selected Sensor ID</description>
<state pattern="%.1f %unit%" readOnly="true"/>
<state pattern="%.1f dB" readOnly="true"/>
</channel-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import javax.measure.quantity.Dimensionless;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.openhab.binding.sensorcommunity.internal.utils.NumberUtils;
import org.openhab.core.library.dimension.Density;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;

/**
* The {@link NumberTest} Test rounding and converting Numbers
Expand Down Expand Up @@ -58,4 +63,18 @@ public void testStringNumbers() {
// System.out.println("D1R1 " + d1r1);
assertEquals("1.9", Double.toString(d1r1), "Double 1.94, 1 place");
}

@Test
public void testDecibelPattern() {
String d1 = "1.94 dB";
QuantityType<Dimensionless> dbQt = (QuantityType<Dimensionless>) QuantityType.valueOf(d1);
assertEquals(Units.DECIBEL, dbQt.getUnit());
}

@Test
public void testMicrogramQubicMeterPattern() {
String d1 = "1.94 µg/m³";
QuantityType<Density> pressureQt = (QuantityType<Density>) QuantityType.valueOf(d1);
assertEquals(Units.MICROGRAM_PER_CUBICMETRE, pressureQt.getUnit());
}
}

0 comments on commit fdfda11

Please sign in to comment.