diff --git a/ecowitt2mqtt/const.py b/ecowitt2mqtt/const.py index 40a46fa3..547f6274 100644 --- a/ecowitt2mqtt/const.py +++ b/ecowitt2mqtt/const.py @@ -117,6 +117,7 @@ DATA_POINT_SIMMER_ZONE: Final = "simmerzone" DATA_POINT_SOLARRADIATION: Final = "solarradiation" DATA_POINT_SOLARRADIATION_PERCEIVED: Final = "solarradiation_perceived" +DATA_POINT_S_RAIN_PIEZO: Final = "srain_piezo" DATA_POINT_TEMP: Final = "temp" DATA_POINT_TEMPIN: Final = "tempin" DATA_POINT_TF_CO2: Final = "tf_co2" diff --git a/ecowitt2mqtt/data.py b/ecowitt2mqtt/data.py index 7cf530ba..de12f396 100644 --- a/ecowitt2mqtt/data.py +++ b/ecowitt2mqtt/data.py @@ -49,6 +49,7 @@ DATA_POINT_RELATIVE_STRAIN_INDEX, DATA_POINT_RELATIVE_STRAIN_INDEX_PERCEPTION, DATA_POINT_RUNTIME, + DATA_POINT_S_RAIN_PIEZO, DATA_POINT_SAFE_EXPOSURE_TIME_SKIN_TYPE_1, DATA_POINT_SAFE_EXPOSURE_TIME_SKIN_TYPE_2, DATA_POINT_SAFE_EXPOSURE_TIME_SKIN_TYPE_3, @@ -95,6 +96,7 @@ PrecipitationRateCalculator, ) from ecowitt2mqtt.helpers.calculator.pressure import PressureCalculator +from ecowitt2mqtt.helpers.calculator.rainstate import RainStateCalculator from ecowitt2mqtt.helpers.calculator.temperature import ( DewPointCalculator, FeelsLikeCalculator, @@ -170,6 +172,7 @@ DATA_POINT_RELATIVE_STRAIN_INDEX_PERCEPTION: RsiPerceptionCalculator, DATA_POINT_RUNTIME: RuntimeCalculator, DATA_POINT_R_RAIN_PIEZO: PrecipitationRateCalculator, + DATA_POINT_S_RAIN_PIEZO: RainStateCalculator, DATA_POINT_SAFE_EXPOSURE_TIME_SKIN_TYPE_1: SafeExposureCalculator, DATA_POINT_SAFE_EXPOSURE_TIME_SKIN_TYPE_2: SafeExposureCalculator, DATA_POINT_SAFE_EXPOSURE_TIME_SKIN_TYPE_3: SafeExposureCalculator, diff --git a/ecowitt2mqtt/helpers/calculator/rainstate.py b/ecowitt2mqtt/helpers/calculator/rainstate.py new file mode 100644 index 00000000..8ac77e71 --- /dev/null +++ b/ecowitt2mqtt/helpers/calculator/rainstate.py @@ -0,0 +1,41 @@ +"""Define rain state calculators.""" + +from __future__ import annotations + +from ecowitt2mqtt.backports.enum import StrEnum +from ecowitt2mqtt.helpers.calculator import ( + CalculatedDataPoint, + Calculator, + DataPointType, +) +from ecowitt2mqtt.helpers.typing import PreCalculatedValueType + + +class RainState(StrEnum): + """Define types of rain state configuration.""" + + OFF = "Dry" + ON = "Wet" + + +class RainStateCalculator(Calculator): + """Define a boolean rain state calculator.""" + + def calculate_from_value( + self, value: PreCalculatedValueType + ) -> CalculatedDataPoint: + """Perform the calculation. + + Args: + value: calculated value. + + Returns: + A parsed CalculatedDataPoint object. + """ + if value == 0.0: + return self.get_calculated_data_point( + RainState.OFF, data_type=DataPointType.BOOLEAN + ) + return self.get_calculated_data_point( + RainState.ON, data_type=DataPointType.BOOLEAN + )