Skip to content

Commit

Permalink
Merge pull request #15 from Bouke/patch-1
Browse files Browse the repository at this point in the history
Mark thermostat unavailable if not recently seen
  • Loading branch information
gerard33 committed Aug 20, 2021
2 parents 679b819 + d475c29 commit 5133072
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions custom_components/e_thermostaat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -165,6 +168,11 @@ def current_temperature(self):
def target_temperature(self):
"""Return the temperature we try to reach."""
return self._target_temperature

@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
def hvac_mode(self):
Expand Down Expand Up @@ -303,6 +311,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(
Expand Down

0 comments on commit 5133072

Please sign in to comment.