Skip to content

Commit

Permalink
turn leaf wetness into a percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
siku2 committed May 11, 2021
1 parent c8fa359 commit 89389db
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions custom_components/weatherlink/sensor_moisture.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ class Soil4(
...


_WETNESS2PERCENTAGE = 100.0 / 15.0


class LeafABC(MoistureSensor, abc=True):
_sensor_id: int

def __init_subclass__(cls, *, sensor_id: int, **kwargs) -> None:
super().__init_subclass__(
sensor_name=f"Leaf {sensor_id}",
unit_of_measurement=None,
unit_of_measurement="%",
device_class=None,
**kwargs,
)
Expand All @@ -162,7 +165,15 @@ def icon(self):

@property
def state(self):
return round_optional(self._wet_leaf(self._moisture_condition), 1)
if wetness := self._wet_leaf(self._moisture_condition):
return round(_WETNESS2PERCENTAGE * wetness, 0)
return None

@property
def device_state_attributes(self):
return {
"raw": round_optional(self._wet_leaf(self._moisture_condition), 1),
}


class Leaf1(
Expand Down

0 comments on commit 89389db

Please sign in to comment.