Skip to content

Commit

Permalink
add srain_piezo of WS90 for rain state detection
Browse files Browse the repository at this point in the history
  • Loading branch information
dkadioglu committed Oct 2, 2024
1 parent 9f0de4b commit 382ae4c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions ecowitt2mqtt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions ecowitt2mqtt/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
41 changes: 41 additions & 0 deletions ecowitt2mqtt/helpers/calculator/rainstate.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 382ae4c

Please sign in to comment.