Skip to content

Commit

Permalink
Merge pull request #63 from tetele/fix-unavailable-sensor-state
Browse files Browse the repository at this point in the history
Account for unavailable temperature sensor
  • Loading branch information
tetele authored Feb 7, 2024
2 parents 8ea1a99 + 4c134d3 commit 42b0c72
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions custom_components/hvac_group/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
CONF_NAME,
PRECISION_HALVES,
PRECISION_TENTHS,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers import entity_registry as er
Expand Down Expand Up @@ -211,6 +213,21 @@ def __init__(
self._require_actuator_mass_refresh: bool = False
self._old_state: State | None = None

@property
def available(self) -> bool:
"""Return climate group availability."""
return (
(self._current_temperature is not None)
and (len(self._attr_hvac_modes) > 0)
and (
self._target_temperature is not None
or (
self._target_temp_high is not None
and self._target_temp_low is not None
)
)
)

@property
def current_temperature(self) -> float | None:
"""Return the sensor temperature."""
Expand Down Expand Up @@ -566,6 +583,9 @@ async def async_update_temperature_sensor(
if new_state is None:
return

if new_state.state in (None, STATE_UNAVAILABLE, STATE_UNKNOWN):
return

# Current temperature can be retrieved from a `climate` or `sensor` entity
new_temperature = (
new_state.attributes.get(ATTR_CURRENT_TEMPERATURE)
Expand Down

0 comments on commit 42b0c72

Please sign in to comment.