]> git.basschouten.com Git - openhab-addons.git/commitdiff
[fineoffsetweatherstation] Implement new Measurand `free-heap-size` (#16461)
authorAndreas Berger <Andy2003@users.noreply.github.com>
Tue, 27 Feb 2024 09:57:56 +0000 (10:57 +0100)
committerGitHub <noreply@github.com>
Tue, 27 Feb 2024 09:57:56 +0000 (10:57 +0100)
Signed-off-by: Andreas Berger <andreas@berger-freelancer.com>
bundles/org.openhab.binding.fineoffsetweatherstation/README.md
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationBindingConstants.java
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/Measurand.java
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/MeasureType.java
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/i18n/fineoffsetweatherstation.properties
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/gateway.xml
bundles/org.openhab.binding.fineoffsetweatherstation/src/test/java/org/openhab/binding/fineoffsetweatherstation/internal/service/FineOffsetDataParserTest.java

index fa4bb744e67e38dc88bc538494e50ae486fb54b3..7cc93307a58bee0c09150dc3538715b3eee18252 100644 (file)
@@ -19,7 +19,7 @@ Here is a product picture of how this Weather Station looks like:
 
 ![WH2650](doc/WH2650.png)
 
-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.
+This binding works offline by [implementing the wire protocol](https://community.openhab.org/uploads/short-url/cuV8oOaCYHZhdm0hVJUN7hxMMfe.pdf) of the WiFi gateway device.
 
 ## Discussion
 
@@ -27,7 +27,7 @@ If you have any issues or feedback, please feel free to [get in touch via the co
 
 ## Supported Things
 
-- `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.:
+- `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.:
   - HP2550
   - HP3500
   - GW1000
@@ -280,6 +280,7 @@ Valid sensors:
 | piezo-rain-week                       | Number:Length        | R          | Piezo - Rainfall this Week                     |
 | piezo-rain-month                      | Number:Length        | R          | Piezo - Rainfall this Month                    |
 | piezo-rain-year                       | Number:Length        | R          | Piezo - Rainfall this Year                     |
+| free-heap-size                        | Number:DataAmount    | R          | Free Heap Size                                 |
 
 NOTE: Not every gateway provides all available data, even if they are displayed in the WS-View app.
 Especially the channels `temperature-dew-point` or `temperature-wind-chill` are derived from other measured values.
index f9faff1c9c5b8a7ef3c1e6baa394fc8d7830ca0a..52f86726a6d92886cce7e44425a178b92bb36328 100644 (file)
@@ -54,6 +54,8 @@ public class FineOffsetWeatherStationBindingConstants {
     public static final ChannelTypeUID CHANNEL_TYPE_LIGHTNING_DISTANCE = new ChannelTypeUID(BINDING_ID,
             "lightning-distance");
 
+    public static final ChannelTypeUID CHANNEL_TYPE_FREE_HEAP_SIZE = new ChannelTypeUID(BINDING_ID, "free-heap-size");
+
     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_GATEWAY, THING_TYPE_SENSOR);
 
     public static final String SENSOR_CHANNEL_SIGNAL = "signal";
index d520787d7bd849d395dbc7cc8d9a75dc98ae5296..12d97a3baf063a948080ac66880a7cc7dbfb20e7 100644 (file)
@@ -12,6 +12,7 @@
  */
 package org.openhab.binding.fineoffsetweatherstation.internal.domain;
 
+import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_FREE_HEAP_SIZE;
 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MAX_WIND_SPEED;
 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_MOISTURE;
 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.CHANNEL_TYPE_UV_INDEX;
@@ -131,9 +132,9 @@ public enum Measurand {
     LEAK_CHX("water-leak-channel", new int[] { 0x58, 0x59, 0x5A, 0x5B }, "Leak", MeasureType.WATER_LEAK_DETECTION),
 
     // `LIGHTNING` is the name in the spec, so we keep it here as it
-    LIGHTNING("lightning-distance", 0x60, "lightning distance 1~40KM", MeasureType.LIGHTNING_DISTANCE),
+    LIGHTNING("lightning-distance", 0x60, "Lightning distance 1~40KM", MeasureType.LIGHTNING_DISTANCE),
 
-    LIGHTNING_TIME("lightning-time", 0x61, "lightning happened time", MeasureType.LIGHTNING_TIME),
+    LIGHTNING_TIME("lightning-time", 0x61, "Lightning happened time", MeasureType.LIGHTNING_TIME),
 
     // `LIGHTNING_POWER` is the name in the spec, so we keep it here as it
     LIGHTNING_POWER("lightning-counter", 0x62, "lightning counter for the day", MeasureType.LIGHTNING_COUNTER),
@@ -143,6 +144,9 @@ public enum Measurand {
             // skip battery-level, since it is read via Command.CMD_READ_SENSOR_ID_NEW
             new Skip(1)),
 
+    // This is for heap : the available stack top. If it is reducing, it means the stack is using up.
+    ITEM_HEAP_FREE("free-heap-size", 0x6c, "Free Heap Size", MeasureType.MEMORY, CHANNEL_TYPE_FREE_HEAP_SIZE),
+
     ITEM_SENSOR_CO2(0x70,
             new MeasurandParser("sensor-co2-temperature", "Temperature (CO₂-Sensor)", MeasureType.TEMPERATURE),
             new MeasurandParser("sensor-co2-humidity", "Humidity (CO₂-Sensor)", MeasureType.PERCENTAGE),
index c5085977766360feadff65bc2a51976fe43b0246..8a3fbc6855000dd7b5ac624370b8bb3312225920 100644 (file)
@@ -122,6 +122,7 @@ public enum MeasureType {
             (data, offset) -> Utils.toUInt16(data, offset) / 10.),
 
     BYTE(1, null, (data, offset, context) -> new DecimalType(toUInt8(data[offset]))),
+    MEMORY(Units.BYTE, 4, null, Utils::toUInt32),
 
     DATE_TIME2(6, null, (data, offset, context) -> new DateTimeType(
             ZonedDateTime.ofInstant(Instant.ofEpochSecond(toUInt32(data, offset)), context.getZoneId())));
index 63424679a6e7ffb0f77170c12b50c22e61f77e36..b7f032095b9469b78191992e6c882941720d002e 100644 (file)
@@ -30,6 +30,8 @@ channel-type.fineoffsetweatherstation.battery-voltage.label = Battery Voltage
 channel-type.fineoffsetweatherstation.battery-voltage.description = The voltage of the battery
 channel-type.fineoffsetweatherstation.co2.label = CO₂
 channel-type.fineoffsetweatherstation.co2.description = Air Quality Indicator
+channel-type.fineoffsetweatherstation.free-heap-size.description = The available heap size. If it is reducing, it means the heap is using up.
+channel-type.fineoffsetweatherstation.free-heap-size.label = Free Heap Size
 channel-type.fineoffsetweatherstation.humidity.label = Humidity
 channel-type.fineoffsetweatherstation.illumination.label = Illumination
 channel-type.fineoffsetweatherstation.lightning-counter.label = Lightning Counter
@@ -136,3 +138,4 @@ gateway.dynamic-channel.piezo-rain-day.label = Rain Day
 gateway.dynamic-channel.piezo-rain-week.label = Rain Week
 gateway.dynamic-channel.piezo-rain-month.label = Rain Month
 gateway.dynamic-channel.piezo-rain-year.label = Rain Year
+gateway.dynamic-channel.free-heap-size.label = Free Stack Size
index 3b798ecf743d5e3e8a9d5b8780e909659a5fadfa..067475fe756af8c3f59a9918c6e92c3dd9247365 100644 (file)
                <label>Lightning Distance</label>
                <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
+
+       <channel-type id="free-heap-size" advanced="true">
+               <item-type>Number:DataAmount</item-type>
+               <label>Free Heap Size</label>
+               <description>The available heap size. If it is reducing, it means the heap is using up.</description>
+               <state pattern="%.0f %unit%" readOnly="true"/>
+       </channel-type>
 </thing:thing-descriptions>
index 0c550479f75851e6860e7852b20d870cb5561059..4ab4c236708e0ea3619bd02bf1bf86fe6acf5c66 100644 (file)
@@ -123,6 +123,24 @@ class FineOffsetDataParserTest {
                         new Tuple("sensor-co2-co2-24-hour-average", "891 ppm"));
     }
 
+    @Test
+    void testLiveDataWithHeapFreeMeasurand() {
+        byte[] bytes = HexUtils.hexToBytes(
+                "FFFF27002F01010B062A0826C10926C1020011074D0A004C0B000C0C000D15000226C816006317011900136C0001FED864");
+        DebugDetails debugDetails = new DebugDetails(bytes, Command.CMD_GW1000_LIVEDATA, Protocol.DEFAULT);
+        List<MeasuredValue> data = new FineOffsetDataParser(Protocol.DEFAULT).getMeasuredValues(bytes,
+                new ConversionContext(ZoneOffset.UTC), debugDetails);
+        Assertions.assertThat(data)
+                .extracting(MeasuredValue::getChannelId, measuredValue -> measuredValue.getState().toString())
+                .containsExactly(new Tuple("temperature-indoor", "26.7 °C"), new Tuple("humidity-indoor", "42 %"),
+                        new Tuple("pressure-absolute", "992.1 hPa"), new Tuple("pressure-relative", "992.1 hPa"),
+                        new Tuple("temperature-outdoor", "1.7 °C"), new Tuple("humidity-outdoor", "77 %"),
+                        new Tuple("direction-wind", "76 °"), new Tuple("speed-wind", "1.2 m/s"),
+                        new Tuple("speed-gust", "1.3 m/s"), new Tuple("illumination", "14100 lx"),
+                        new Tuple("irradiation-uv", "9.9 mW/m²"), new Tuple("uv-index", "1"),
+                        new Tuple("wind-max-day", "1.9 m/s"), new Tuple("free-heap-size", "130776 B"));
+    }
+
     @Test
     void testLiveDataELV() {
         byte[] data = HexUtils.hexToBytes(