-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add srain_piezo of WS90 for rain state detection
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |