Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improves stale duration docs #211

Merged
merged 2 commits into from
May 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: ensures sensor stale logic turns device back on
  • Loading branch information
= committed May 30, 2024
commit 92f6aaed839004ee959970a3814b50ca3f0691c1
2 changes: 1 addition & 1 deletion custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
@@ -933,8 +933,8 @@ async def _async_sensor_not_responding(self, now: datetime | None = None) -> Non
"Sensor has not been updated for %s",
now - state.last_updated if now and state else "---",
)
_LOGGER.warning("Sensor is stalled, call the emergency stop")
if self._is_device_active:
_LOGGER.warning("Sensor is stalled, call the emergency stop")
await self.hvac_device.async_turn_off()
self._hvac_action_reason = HVACActionReason.TEMPERATURE_SENSOR_STALLED
self.async_write_ha_state()
Original file line number Diff line number Diff line change
@@ -64,9 +64,6 @@ def hvac_action(self) -> HVACAction:
async def async_control_hvac(self, time=None, force=False):
_LOGGER.debug({self.__class__.__name__})
_LOGGER.debug("async_control_hvac")
_LOGGER.debug(
"sensor safety timed out: %s", self.environment.is_sensor_safety_timed_out
)
self._set_self_active()

if not self._needs_control(time, force):
Original file line number Diff line number Diff line change
@@ -10,17 +10,9 @@
DEFAULT_MIN_TEMP,
)
from homeassistant.components.climate.const import PRESET_NONE, HVACMode
from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_WHOLE,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
UnitOfTemperature,
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, UnitOfTemperature
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers import condition
from homeassistant.helpers.typing import ConfigType
import homeassistant.util.dt as dt_util
from homeassistant.util.unit_conversion import TemperatureConverter

from custom_components.dual_smart_thermostat.const import (
@@ -394,50 +386,6 @@ def is_floor_cold(self) -> bool:
return True
return False

@property
def is_sensor_safety_timed_out(self) -> bool:
"""If the sensor safety delay has timed out."""
sensor_state = self.hass.states.get(self._sensor)

if self._sensor_stale_duration is None or sensor_state is None:
return False

"""Checks when the sensor was last updated. If the sensor has not been
updated in the last sensor_stale_duration seconds, the sensor is considered
timed out."""

time_diff = dt_util.utcnow() - sensor_state.last_changed
is_value_state = sensor_state not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
timed_out_temp = is_value_state and (
time_diff.total_seconds() > self._sensor_stale_duration.total_seconds()
)

_LOGGER.debug(
"time diff: %s, delay: %s", time_diff, self._sensor_stale_duration
)
_LOGGER.debug(
"timed out temp: %s, dif_seconds: %s, delay_seconds: %s",
timed_out_temp,
time_diff.total_seconds(),
self._sensor_stale_duration.total_seconds(),
)

return (
timed_out_temp
or condition.state(
self.hass,
self._sensor,
STATE_UNKNOWN,
self._sensor_stale_duration,
)
or condition.state(
self.hass,
self._sensor,
STATE_UNAVAILABLE,
self._sensor_stale_duration,
)
)

@callback
def update_temp_from_state(self, state: State) -> None:
"""Update thermostat with latest state from sensor."""
11 changes: 11 additions & 0 deletions tests/test_dry_mode.py
Original file line number Diff line number Diff line change
@@ -885,6 +885,17 @@ async def test_sensor_unknown_secure_ac_dry_off_outside_stale_duration(
assert call.service == SERVICE_TURN_OFF
assert call.data["entity_id"] == common.ENT_DRYER

# Turns back on if sensor is restored
calls = setup_switch_dual(hass, common.ENT_DRYER, False, False)
setup_humidity_sensor(hass, 71)
await hass.async_block_till_done()

assert len(calls) == 1
call = calls[0]
assert call.domain == HASS_DOMAIN
assert call.service == SERVICE_TURN_ON
assert call.data["entity_id"] == common.ENT_DRYER


@pytest.mark.parametrize(
"sensor_state",
11 changes: 11 additions & 0 deletions tests/test_heater_mode.py
Original file line number Diff line number Diff line change
@@ -769,6 +769,17 @@ async def test_sensor_unknown_secure_heater_off_outside_stale_duration(
assert call.service == SERVICE_TURN_OFF
assert call.data["entity_id"] == common.ENT_SWITCH

# Turns back on if sensor is restored
calls = setup_switch(hass, False)
setup_sensor(hass, 19)
await hass.async_block_till_done()

assert len(calls) == 1
call = calls[0]
assert call.domain == HASS_DOMAIN
assert call.service == SERVICE_TURN_ON
assert call.data["entity_id"] == common.ENT_SWITCH


@pytest.mark.parametrize(
"sensor_state",