Skip to content

Commit b6366ab

Browse files
authored
[fineoffsetweatherstation] Implement new Measurand free-heap-size (openhab#16461)
Signed-off-by: Andreas Berger <[email protected]>
1 parent 021fb19 commit b6366ab

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

bundles/org.openhab.binding.fineoffsetweatherstation/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ Here is a product picture of how this Weather Station looks like:
1919

2020
![WH2650](doc/WH2650.png)
2121

22-
This binding works offline by [implementing the wire protocol](https://osswww.ecowitt.net/uploads/20220407/WN1900%20GW1000,1100%20WH2680,2650%20telenet%20v1.6.4.pdf) of the WiFi gateway device.
22+
This binding works offline by [implementing the wire protocol](https://community.openhab.org/uploads/short-url/cuV8oOaCYHZhdm0hVJUN7hxMMfe.pdf) of the WiFi gateway device.
2323

2424
## Discussion
2525

2626
If you have any issues or feedback, please feel free to [get in touch via the community forum](https://community.openhab.org/t/fine-offset-weather-station-binding-discussion/134167)
2727

2828
## Supported Things
2929

30-
- `weatherstation`: A Fine Offset gateway device with the ThingTypeUID `fineoffsetweatherstation:weatherstation` which supports the [wire protocol](https://osswww.ecowitt.net/uploads/20220407/WN1900%20GW1000,1100%20WH2680,2650%20telenet%20v1.6.4.pdf) e.g.:
30+
- `weatherstation`: A Fine Offset gateway device with the ThingTypeUID `fineoffsetweatherstation:weatherstation` which supports the [wire protocol](https://community.openhab.org/uploads/short-url/cuV8oOaCYHZhdm0hVJUN7hxMMfe.pdf) e.g.:
3131
- HP2550
3232
- HP3500
3333
- GW1000
@@ -280,6 +280,7 @@ Valid sensors:
280280
| piezo-rain-week | Number:Length | R | Piezo - Rainfall this Week |
281281
| piezo-rain-month | Number:Length | R | Piezo - Rainfall this Month |
282282
| piezo-rain-year | Number:Length | R | Piezo - Rainfall this Year |
283+
| free-heap-size | Number:DataAmount | R | Free Heap Size |
283284

284285
NOTE: Not every gateway provides all available data, even if they are displayed in the WS-View app.
285286
Especially the channels `temperature-dew-point` or `temperature-wind-chill` are derived from other measured values.

bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationBindingConstants.java

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class FineOffsetWeatherStationBindingConstants {
5454
public static final ChannelTypeUID CHANNEL_TYPE_LIGHTNING_DISTANCE = new ChannelTypeUID(BINDING_ID,
5555
"lightning-distance");
5656

57+
public static final ChannelTypeUID CHANNEL_TYPE_FREE_HEAP_SIZE = new ChannelTypeUID(BINDING_ID, "free-heap-size");
58+
5759
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_GATEWAY, THING_TYPE_SENSOR);
5860

5961
public static final String SENSOR_CHANNEL_SIGNAL = "signal";

bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/Measurand.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package org.openhab.binding.fineoffsetweatherstation.internal.domain;
1414

15+
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_FREE_HEAP_SIZE;
1516
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MAX_WIND_SPEED;
1617
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MOISTURE;
1718
import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_UV_INDEX;
@@ -131,9 +132,9 @@ public enum Measurand {
131132
LEAK_CHX("water-leak-channel", new int[] { 0x58, 0x59, 0x5A, 0x5B }, "Leak", MeasureType.WATER_LEAK_DETECTION),
132133

133134
// `LIGHTNING` is the name in the spec, so we keep it here as it
134-
LIGHTNING("lightning-distance", 0x60, "lightning distance 1~40KM", MeasureType.LIGHTNING_DISTANCE),
135+
LIGHTNING("lightning-distance", 0x60, "Lightning distance 1~40KM", MeasureType.LIGHTNING_DISTANCE),
135136

136-
LIGHTNING_TIME("lightning-time", 0x61, "lightning happened time", MeasureType.LIGHTNING_TIME),
137+
LIGHTNING_TIME("lightning-time", 0x61, "Lightning happened time", MeasureType.LIGHTNING_TIME),
137138

138139
// `LIGHTNING_POWER` is the name in the spec, so we keep it here as it
139140
LIGHTNING_POWER("lightning-counter", 0x62, "lightning counter for the day", MeasureType.LIGHTNING_COUNTER),
@@ -143,6 +144,9 @@ public enum Measurand {
143144
// skip battery-level, since it is read via Command.CMD_READ_SENSOR_ID_NEW
144145
new Skip(1)),
145146

147+
// This is for heap : the available stack top. If it is reducing, it means the stack is using up.
148+
ITEM_HEAP_FREE("free-heap-size", 0x6c, "Free Heap Size", MeasureType.MEMORY, CHANNEL_TYPE_FREE_HEAP_SIZE),
149+
146150
ITEM_SENSOR_CO2(0x70,
147151
new MeasurandParser("sensor-co2-temperature", "Temperature (CO₂-Sensor)", MeasureType.TEMPERATURE),
148152
new MeasurandParser("sensor-co2-humidity", "Humidity (CO₂-Sensor)", MeasureType.PERCENTAGE),

bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/MeasureType.java

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public enum MeasureType {
122122
(data, offset) -> Utils.toUInt16(data, offset) / 10.),
123123

124124
BYTE(1, null, (data, offset, context) -> new DecimalType(toUInt8(data[offset]))),
125+
MEMORY(Units.BYTE, 4, null, Utils::toUInt32),
125126

126127
DATE_TIME2(6, null, (data, offset, context) -> new DateTimeType(
127128
ZonedDateTime.ofInstant(Instant.ofEpochSecond(toUInt32(data, offset)), context.getZoneId())));

bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/i18n/fineoffsetweatherstation.properties

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ channel-type.fineoffsetweatherstation.battery-voltage.label = Battery Voltage
3030
channel-type.fineoffsetweatherstation.battery-voltage.description = The voltage of the battery
3131
channel-type.fineoffsetweatherstation.co2.label = CO₂
3232
channel-type.fineoffsetweatherstation.co2.description = Air Quality Indicator
33+
channel-type.fineoffsetweatherstation.free-heap-size.description = The available heap size. If it is reducing, it means the heap is using up.
34+
channel-type.fineoffsetweatherstation.free-heap-size.label = Free Heap Size
3335
channel-type.fineoffsetweatherstation.humidity.label = Humidity
3436
channel-type.fineoffsetweatherstation.illumination.label = Illumination
3537
channel-type.fineoffsetweatherstation.lightning-counter.label = Lightning Counter
@@ -136,3 +138,4 @@ gateway.dynamic-channel.piezo-rain-day.label = Rain Day
136138
gateway.dynamic-channel.piezo-rain-week.label = Rain Week
137139
gateway.dynamic-channel.piezo-rain-month.label = Rain Month
138140
gateway.dynamic-channel.piezo-rain-year.label = Rain Year
141+
gateway.dynamic-channel.free-heap-size.label = Free Stack Size

bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/gateway.xml

+7
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,11 @@
180180
<label>Lightning Distance</label>
181181
<state pattern="%.0f %unit%" readOnly="true"/>
182182
</channel-type>
183+
184+
<channel-type id="free-heap-size" advanced="true">
185+
<item-type>Number:DataAmount</item-type>
186+
<label>Free Heap Size</label>
187+
<description>The available heap size. If it is reducing, it means the heap is using up.</description>
188+
<state pattern="%.0f %unit%" readOnly="true"/>
189+
</channel-type>
183190
</thing:thing-descriptions>

bundles/org.openhab.binding.fineoffsetweatherstation/src/test/java/org/openhab/binding/fineoffsetweatherstation/internal/service/FineOffsetDataParserTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ void testLiveDataWH34AndWh45() {
123123
new Tuple("sensor-co2-co2-24-hour-average", "891 ppm"));
124124
}
125125

126+
@Test
127+
void testLiveDataWithHeapFreeMeasurand() {
128+
byte[] bytes = HexUtils.hexToBytes(
129+
"FFFF27002F01010B062A0826C10926C1020011074D0A004C0B000C0C000D15000226C816006317011900136C0001FED864");
130+
DebugDetails debugDetails = new DebugDetails(bytes, Command.CMD_GW1000_LIVEDATA, Protocol.DEFAULT);
131+
List<MeasuredValue> data = new FineOffsetDataParser(Protocol.DEFAULT).getMeasuredValues(bytes,
132+
new ConversionContext(ZoneOffset.UTC), debugDetails);
133+
Assertions.assertThat(data)
134+
.extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
135+
.containsExactly(new Tuple("temperature-indoor", "26.7 °C"), new Tuple("humidity-indoor", "42 %"),
136+
new Tuple("pressure-absolute", "992.1 hPa"), new Tuple("pressure-relative", "992.1 hPa"),
137+
new Tuple("temperature-outdoor", "1.7 °C"), new Tuple("humidity-outdoor", "77 %"),
138+
new Tuple("direction-wind", "76 °"), new Tuple("speed-wind", "1.2 m/s"),
139+
new Tuple("speed-gust", "1.3 m/s"), new Tuple("illumination", "14100 lx"),
140+
new Tuple("irradiation-uv", "9.9 mW/m²"), new Tuple("uv-index", "1"),
141+
new Tuple("wind-max-day", "1.9 m/s"), new Tuple("free-heap-size", "130776 B"));
142+
}
143+
126144
@Test
127145
void testLiveDataELV() {
128146
byte[] data = HexUtils.hexToBytes(

0 commit comments

Comments
 (0)