From 58c5ce1c77d51acb95f24e6a48bc457361ccf554 Mon Sep 17 00:00:00 2001 From: Bouke Haarsma Date: Wed, 18 Aug 2021 09:52:28 +0200 Subject: [PATCH 1/3] Mark thermostat unavailable if not recently seen --- custom_components/e_thermostaat/climate.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/custom_components/e_thermostaat/climate.py b/custom_components/e_thermostaat/climate.py index eee301a..4654205 100644 --- a/custom_components/e_thermostaat/climate.py +++ b/custom_components/e_thermostaat/climate.py @@ -4,6 +4,8 @@ For more details about this platform, please refer to the documentation at https://github.com/custom-components/climate.e_thermostaat """ +import datetime + import logging import requests @@ -118,6 +120,7 @@ def __init__(self, name, username, password, comfort_temp, saving_temp, away_tem self._current_temperature = None self._target_temperature = None + self._last_seen = None self._old_conf = None self._current_operation_mode = None @@ -165,6 +168,10 @@ def current_temperature(self): def target_temperature(self): """Return the temperature we try to reach.""" return self._target_temperature + + @property + def available() -> bool: + return self._last_seen and datetime.datetime.now() - self._last_seen < datetime.timedelta(seconds=600) @property def hvac_mode(self): @@ -303,6 +310,8 @@ def _get_data(self): self._target_temperature = data["temperature1"] self._current_temperature = data["temperature2"] + + self._last_seen = datetime.datetime.strptime(data["last-seen"], '%Y-%m-%d %H:%M:%S') self._old_conf = data["configuration"] self._current_operation_mode = self.map_int_to_operation_mode( From 6e5db75e92d6fa45dc83eb68ef97c7af164db98a Mon Sep 17 00:00:00 2001 From: Bouke Haarsma Date: Wed, 18 Aug 2021 10:07:28 +0200 Subject: [PATCH 2/3] Update climate.py --- custom_components/e_thermostaat/climate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/e_thermostaat/climate.py b/custom_components/e_thermostaat/climate.py index 4654205..21327fb 100644 --- a/custom_components/e_thermostaat/climate.py +++ b/custom_components/e_thermostaat/climate.py @@ -170,7 +170,7 @@ def target_temperature(self): return self._target_temperature @property - def available() -> bool: + def available(self) -> bool: return self._last_seen and datetime.datetime.now() - self._last_seen < datetime.timedelta(seconds=600) @property From d475c29091212dd00ccec03af44b49c95c38ae9a Mon Sep 17 00:00:00 2001 From: Gerard Date: Fri, 20 Aug 2021 21:46:30 +0200 Subject: [PATCH 3/3] Update custom_components/e_thermostaat/climate.py --- custom_components/e_thermostaat/climate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/e_thermostaat/climate.py b/custom_components/e_thermostaat/climate.py index 21327fb..6cd3b41 100644 --- a/custom_components/e_thermostaat/climate.py +++ b/custom_components/e_thermostaat/climate.py @@ -171,6 +171,7 @@ def target_temperature(self): @property def available(self) -> bool: + """Return True if entity is available.""" return self._last_seen and datetime.datetime.now() - self._last_seen < datetime.timedelta(seconds=600) @property