Skip to content

Commit

Permalink
Merge pull request #128 from Olen/unknownunavailable2
Browse files Browse the repository at this point in the history
Set state unknown if all sensors are unknown
  • Loading branch information
Olen authored Jan 2, 2024
2 parents 157263c + 217b4cf commit d756046
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions custom_components/plant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ def update(self) -> None:
"""Run on every update of the entities"""

new_state = STATE_OK
known_state = False

if self.sensor_moisture is not None:
moisture = self._hass.states.get(self.sensor_moisture.entity_id).state
Expand All @@ -634,6 +635,7 @@ def update(self) -> None:
and moisture != STATE_UNKNOWN
and moisture != STATE_UNAVAILABLE
):
known_state = True
if float(moisture) < float(self.min_moisture.state):
self.moisture_status = STATE_LOW
if self.moisture_trigger:
Expand All @@ -654,6 +656,7 @@ def update(self) -> None:
and conductivity != STATE_UNKNOWN
and conductivity != STATE_UNAVAILABLE
):
known_state = True
if float(conductivity) < float(self.min_conductivity.state):
self.conductivity_status = STATE_LOW
if self.conductivity_trigger:
Expand All @@ -672,6 +675,7 @@ def update(self) -> None:
and temperature != STATE_UNKNOWN
and temperature != STATE_UNAVAILABLE
):
known_state = True
if float(temperature) < float(self.min_temperature.state):
self.temperature_status = STATE_LOW
if self.temperature_trigger:
Expand All @@ -690,6 +694,7 @@ def update(self) -> None:
and humidity != STATE_UNKNOWN
and humidity != STATE_UNAVAILABLE
):
known_state = True
if float(humidity) < float(self.min_humidity.state):
self.humidity_status = STATE_LOW
if self.humidity_trigger:
Expand All @@ -710,6 +715,7 @@ def update(self) -> None:
and illuminance != STATE_UNKNOWN
and illuminance != STATE_UNAVAILABLE
):
known_state = True
if float(illuminance) > float(self.max_illuminance.state):
self.illuminance_status = STATE_HIGH
if self.illuminance_trigger:
Expand All @@ -725,6 +731,7 @@ def update(self) -> None:
and self.dli.native_value != STATE_UNAVAILABLE
and self.dli.state is not None
):
known_state = True
if float(self.dli.extra_state_attributes["last_period"]) > 0 and float(
self.dli.extra_state_attributes["last_period"]
) < float(self.min_dli.state):
Expand All @@ -740,6 +747,9 @@ def update(self) -> None:
else:
self.dli_status = STATE_OK

if not known_state:
new_state = STATE_UNKNOWN

self._attr_state = new_state
self.update_registry()

Expand Down

0 comments on commit d756046

Please sign in to comment.