Skip to content

Commit

Permalink
Add data detection for heap sensor (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya authored Jan 17, 2024
1 parent 2b80fb7 commit 66b0299
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ecowitt2mqtt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
DATA_POINT_FEELSLIKE: Final = "feelslike"
DATA_POINT_FROST_POINT: Final = "frostpoint"
DATA_POINT_FROST_RISK: Final = "frostrisk"
DATA_POINT_HEAP: Final = "heap"
DATA_POINT_HEATINDEX: Final = "heatindex"
DATA_POINT_HOURLY_RAIN: Final = "hourlyrain"
DATA_POINT_HRAIN_PIEZO: Final = "hrain_piezo"
Expand Down Expand Up @@ -237,6 +238,9 @@
# Lightning units:
STRIKES: Final = "strikes"

# Memory units:
MEMORY_BYTES: Final = "bytes"

# Percentage units
PERCENTAGE: Final = "%"

Expand Down
3 changes: 3 additions & 0 deletions ecowitt2mqtt/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DATA_POINT_GLOB_WETNESS,
DATA_POINT_GLOB_WIND,
DATA_POINT_GLOB_WINDDIR,
DATA_POINT_HEAP,
DATA_POINT_HEATINDEX,
DATA_POINT_HUMI_CO2,
DATA_POINT_HUMIDEX,
Expand Down Expand Up @@ -71,6 +72,7 @@
SimpleCalculator,
)
from ecowitt2mqtt.helpers.calculator.battery import BatteryCalculator
from ecowitt2mqtt.helpers.calculator.heap import HeapCalculator
from ecowitt2mqtt.helpers.calculator.humidity import (
AbsoluteHumidityCalculator,
RelativeHumidityCalculator,
Expand Down Expand Up @@ -147,6 +149,7 @@
DATA_POINT_GLOB_WETNESS: RelativeHumidityCalculator,
DATA_POINT_GLOB_WIND: WindSpeedCalculator,
DATA_POINT_GLOB_WINDDIR: WindDirCalculator,
DATA_POINT_HEAP: HeapCalculator,
DATA_POINT_HEATINDEX: HeatIndexCalculator,
DATA_POINT_HUMIDEX: HumidexCalculator,
DATA_POINT_HUMIDEX_PERCEPTION: HumidexPerceptionCalculator,
Expand Down
18 changes: 18 additions & 0 deletions ecowitt2mqtt/helpers/calculator/heap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Define time calculators."""
from __future__ import annotations

from ecowitt2mqtt.const import MEMORY_BYTES
from ecowitt2mqtt.helpers.calculator import SimpleCalculator


class HeapCalculator(SimpleCalculator):
"""Define a data update interval calculator."""

@property
def output_unit(self) -> str:
"""Get the output unit of measurement for this calculation.
Returns:
A unit string.
"""
return MEMORY_BYTES
6 changes: 6 additions & 0 deletions ecowitt2mqtt/helpers/publisher/mqtt/hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
DATA_POINT_GLOB_WETNESS,
DATA_POINT_GLOB_WIND,
DATA_POINT_GLOB_WINDDIR,
DATA_POINT_HEAP,
DATA_POINT_HEATINDEX,
DATA_POINT_HOURLY_RAIN,
DATA_POINT_HRAIN_PIEZO,
Expand Down Expand Up @@ -300,6 +301,11 @@ class HassDiscoveryInfo:
DATA_POINT_GLOB_WINDDIR: EntityDescription(
icon="mdi:compass",
),
DATA_POINT_HEAP: EntityDescription(
icon="mdi:memory",
entity_category=EntityCategory.DIAGNOSTIC,
state_class=StateClass.MEASUREMENT,
),
DATA_POINT_HEATINDEX: EntityDescription(
device_class=DeviceClass.TEMPERATURE,
state_class=StateClass.MEASUREMENT,
Expand Down
15 changes: 15 additions & 0 deletions tests/data/test_data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ELECTRIC_POTENTIAL_VOLT,
ILLUMINANCE_WATTS_PER_SQUARE_METER,
LENGTH_MILES,
MEMORY_BYTES,
PERCENTAGE,
PRECIPITATION_INCHES,
PRECIPITATION_INCHES_PER_HOUR,
Expand Down Expand Up @@ -645,6 +646,13 @@ def test_missing_distance(device_data: dict[str, Any], ecowitt: Ecowitt) -> None
attributes={},
data_type=DataPointType.NON_BOOLEAN,
),
"heap": CalculatedDataPoint(
data_point_key="heap",
value=18604.0,
unit=MEMORY_BYTES,
attributes={},
data_type=DataPointType.NON_BOOLEAN,
),
}


Expand Down Expand Up @@ -2914,6 +2922,13 @@ def test_precision(device_data: dict[str, Any], ecowitt: Ecowitt) -> None:
attributes={},
data_type=DataPointType.NON_BOOLEAN,
),
"heap": CalculatedDataPoint(
data_point_key="heap",
value=18604.0,
unit=MEMORY_BYTES,
attributes={},
data_type=DataPointType.NON_BOOLEAN,
),
},
),
(
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/payload_gw2000a_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
"leafwetness_ch1": "14",
"leaf_batt1": "1.78",
"freq": "868M",
"model": "GW2000A"
"model": "GW2000A",
"heap": "18604"
}

0 comments on commit 66b0299

Please sign in to comment.