From 0129df9f0f8a250af1edb6e10b248d556507a10c Mon Sep 17 00:00:00 2001 From: dkadioglu <1633773+dkadioglu@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:50:07 +0200 Subject: [PATCH] add tests for WS90 rain state detection --- tests/data/test_data_processing.py | 386 ++++++++++++++++++++++++++ tests/fixtures/payload_gw2000a_3.json | 33 +++ 2 files changed, 419 insertions(+) create mode 100644 tests/fixtures/payload_gw2000a_3.json diff --git a/tests/data/test_data_processing.py b/tests/data/test_data_processing.py index c0e2ed27..930f90f5 100644 --- a/tests/data/test_data_processing.py +++ b/tests/data/test_data_processing.py @@ -35,6 +35,7 @@ from ecowitt2mqtt.helpers.calculator import CalculatedDataPoint, DataPointType from ecowitt2mqtt.helpers.calculator.battery import BooleanBatteryState from ecowitt2mqtt.helpers.calculator.leak import LeakState +from ecowitt2mqtt.helpers.calculator.rainstate import RainState from ecowitt2mqtt.helpers.calculator.temperature import ( FrostRisk, HumidexPerception, @@ -222,6 +223,13 @@ def test_disable_calculated_data(device_data: dict[str, Any], ecowitt: Ecowitt) attributes={}, data_type=DataPointType.BOOLEAN, ), + "srain_piezo": CalculatedDataPoint( + "rain_piezo", + RainState.OFF, + unit=None, + attributes={}, + data_type=DataPointType.BOOLEAN, + ), } @@ -923,6 +931,13 @@ def test_nonnumeric_value(device_data: dict[str, Any], ecowitt: Ecowitt) -> None attributes={}, data_type=DataPointType.BOOLEAN, ), + "srain_piezo": CalculatedDataPoint( + "rain_piezo", + RainState.OFF, + unit=None, + attributes={}, + data_type=DataPointType.BOOLEAN, + ), "dewpoint": CalculatedDataPoint( "dewpoint", 79.19328776816637, @@ -1318,6 +1333,13 @@ def test_precision(device_data: dict[str, Any], ecowitt: Ecowitt) -> None: attributes={}, data_type=DataPointType.BOOLEAN, ), + "srain_piezo": CalculatedDataPoint( + "rain_piezo", + RainState.ON, + unit=None, + attributes={}, + data_type=DataPointType.BOOLEAN, + ), "dewpoint": CalculatedDataPoint( "dewpoint", 79.19, @@ -2972,6 +2994,370 @@ def test_precision(device_data: dict[str, Any], ecowitt: Ecowitt) -> None: ), }, ), + ( + "payload_gw2000a_3.json", + { + "ws90_ver": CalculatedDataPoint( + data_point_key="ws90_ver", + value=147, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "runtime": CalculatedDataPoint( + "runtime", + 1574073, + unit=UnitOfTime.SECONDS, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "tempin": CalculatedDataPoint( + "temp", + 71.78, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "humidityin": CalculatedDataPoint( + "humidity", + 59, + unit=PERCENTAGE, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "baromrel": CalculatedDataPoint( + "barom", + 28.476, + unit=UnitOfPressure.INHG, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "baromabs": CalculatedDataPoint( + "barom", + 28.476, + unit=UnitOfPressure.INHG, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "temp": CalculatedDataPoint( + "temp", + 51.44, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "humidity": CalculatedDataPoint( + "humidity", + 76, + unit=PERCENTAGE, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "winddir": CalculatedDataPoint( + "winddir", + 181, + unit=DEGREE, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "windspeed": CalculatedDataPoint( + "wind", + 1.79, + unit=UnitOfSpeed.MILES_PER_HOUR, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "windgust": CalculatedDataPoint( + "gust", + 4.25, + unit=UnitOfSpeed.MILES_PER_HOUR, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "maxdailygust": CalculatedDataPoint( + "gust", + 12.75, + unit=UnitOfSpeed.MILES_PER_HOUR, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "solarradiation": CalculatedDataPoint( + "solarradiation", + 0.00, + unit=UnitOfIlluminance.WATTS_PER_SQUARE_METER, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "solarradiation_perceived": CalculatedDataPoint( + "solarradiation_perceived", + 0.0, + unit=PERCENTAGE, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "uv": CalculatedDataPoint( + "uv", + 0, + unit=UV_INDEX, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "safe_exposure_time_skin_type_1": CalculatedDataPoint( + "safe_exposure_time_skin_type_1", + None, + unit=UnitOfTime.MINUTES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "safe_exposure_time_skin_type_2": CalculatedDataPoint( + "safe_exposure_time_skin_type_2", + None, + unit=UnitOfTime.MINUTES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "safe_exposure_time_skin_type_3": CalculatedDataPoint( + "safe_exposure_time_skin_type_3", + None, + unit=UnitOfTime.MINUTES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "safe_exposure_time_skin_type_4": CalculatedDataPoint( + "safe_exposure_time_skin_type_4", + None, + unit=UnitOfTime.MINUTES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "safe_exposure_time_skin_type_5": CalculatedDataPoint( + "safe_exposure_time_skin_type_5", + None, + unit=UnitOfTime.MINUTES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "safe_exposure_time_skin_type_6": CalculatedDataPoint( + "safe_exposure_time_skin_type_6", + None, + unit=UnitOfTime.MINUTES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "rrain_piezo": CalculatedDataPoint( + "rrain_piezo", + 0.000, + unit=UnitOfPrecipitationRate.INCHES_PER_HOUR, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "erain_piezo": CalculatedDataPoint( + "rain_piezo", + 0.000, + unit=UnitOfAccumulatedPrecipitation.INCHES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "hrain_piezo": CalculatedDataPoint( + "rain_piezo", + 0.000, + unit=UnitOfAccumulatedPrecipitation.INCHES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "drain_piezo": CalculatedDataPoint( + "rain_piezo", + 0.000, + unit=UnitOfAccumulatedPrecipitation.INCHES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "wrain_piezo": CalculatedDataPoint( + "rain_piezo", + 0.181, + unit=UnitOfAccumulatedPrecipitation.INCHES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "mrain_piezo": CalculatedDataPoint( + "rain_piezo", + 0.094, + unit=UnitOfAccumulatedPrecipitation.INCHES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "yrain_piezo": CalculatedDataPoint( + "rain_piezo", + 23.264, + unit=UnitOfAccumulatedPrecipitation.INCHES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "srain_piezo": CalculatedDataPoint( + "rain_piezo", + 0, + unit=None, + attributes={}, + data_type=DataPointType.BOOLEAN, + ), + "ws90cap_volt": CalculatedDataPoint( + "volt", + 5.0, + unit=UnitOfElectricPotential.VOLT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "lightning_num": CalculatedDataPoint( + "lightning_num", + 1, + unit=STRIKES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "wh90batt": CalculatedDataPoint( + "batt", + 3.04, + unit=UnitOfElectricPotential.VOLT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "dewpoint": CalculatedDataPoint( + "dewpoint", + 52.958965353493454, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "feelslike": CalculatedDataPoint( + "feelslike", + 74.5, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "heatindex": CalculatedDataPoint( + "heatindex", + 73.85900000000001, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "windchill": CalculatedDataPoint( + "windchill", + None, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "humidityabs": CalculatedDataPoint( + data_point_key="humidityabs", + value=0.0006244952780717129, + unit=UnitOfVolume.POUNDS_PER_CUBIC_FOOT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "humidityabsin": CalculatedDataPoint( + data_point_key="humidityabsin", + value=0.0005861001233730504, + unit=UnitOfVolume.POUNDS_PER_CUBIC_FOOT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "thermalperception": CalculatedDataPoint( + data_point_key="thermalperception", + value=ThermalPerception.VERY_COMFORTABLE, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "frostpoint": CalculatedDataPoint( + data_point_key="frostpoint", + value=47.136193624907584, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "frostrisk": CalculatedDataPoint( + data_point_key="frostrisk", + value=FrostRisk.NO_RISK, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "simmerindex": CalculatedDataPoint( + data_point_key="simmerindex", + value=81.156695, + unit=UnitOfTemperature.FAHRENHEIT, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "simmerzone": CalculatedDataPoint( + data_point_key="simmerzone", + value=SimmerZone.COMFORTABLE, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "beaufortscale": CalculatedDataPoint( + data_point_key="beaufortscale", + value=1, + unit=None, + attributes={ + "description": "Light air", + "sea_conditions": ( + "Ripples with appearance of scales are formed, without " + "foam crests" + ), + "land_conditions": ( + "Direction shown by smoke drift but not by wind vanes" + ), + }, + data_type=DataPointType.NON_BOOLEAN, + ), + "humidex": CalculatedDataPoint( + data_point_key="humidex", + value=26, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "humidex_perception": CalculatedDataPoint( + data_point_key="humidex_perception", + value=HumidexPerception.LITTLE_TO_NO_DISCOMFORT, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "relative_strain_index": CalculatedDataPoint( + data_point_key="relative_strain_index", + value=None, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "relative_strain_index_perception": CalculatedDataPoint( + data_point_key="relative_strain_index_perception", + value=None, + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "heap": CalculatedDataPoint( + data_point_key="heap", + value=1574073.0, + unit=UnitOfMemory.BYTES, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + "winddir_name": CalculatedDataPoint( + data_point_key="winddir_name", + value="S", + unit=None, + attributes={}, + data_type=DataPointType.NON_BOOLEAN, + ), + }, + ), ( "payload_gw2000a_2.json", { diff --git a/tests/fixtures/payload_gw2000a_3.json b/tests/fixtures/payload_gw2000a_3.json new file mode 100644 index 00000000..a7a927f0 --- /dev/null +++ b/tests/fixtures/payload_gw2000a_3.json @@ -0,0 +1,33 @@ +{ + "PASSKEY": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "stationtype": "GW2000A_V3.1.5", + "runtime": "1574073", + "heap": "156456", + "dateutc": "2024-10-03 19:42:19", + "tempinf": "71.78", + "humidityin": "59", + "baromrelin": "30.035", + "baromabsin": "29.394", + "tempf": "51.44", + "humidity": "76", + "winddir": "181", + "windspeedmph": "1.79", + "windgustmph": "4.25", + "maxdailygust": "12.75", + "solarradiation": "0.00", + "uv": "0", + "rrain_piezo": "0.000", + "erain_piezo": "0.000", + "hrain_piezo": "0.000", + "drain_piezo": "0.000", + "wrain_piezo": "0.181", + "mrain_piezo": "0.094", + "yrain_piezo": "23.264", + "ws90cap_volt": "5.0", + "ws90_ver": "147", + "srain_piezo": "0", + "wh90batt": "3.04", + "freq": "868M", + "model": "GW2000A", + "interval": "16" +}