Restore target temperature for generic thermostat (#10635)

* Restore target temp for generic thermostat

* Fix lint
This commit is contained in:
Lukas Barth 2017-11-17 17:32:58 +01:00 committed by Daniel Høyer Iversen
parent be5f0fb3ac
commit 68d2076b56
2 changed files with 37 additions and 2 deletions

View file

@ -21,6 +21,7 @@ from homeassistant.helpers import condition
from homeassistant.helpers.event import (
async_track_state_change, async_track_time_interval)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import async_get_last_state
_LOGGER = logging.getLogger(__name__)
@ -117,6 +118,17 @@ class GenericThermostat(ClimateDevice):
if sensor_state:
self._async_update_temp(sensor_state)
@asyncio.coroutine
def async_added_to_hass(self):
"""Run when entity about to be added."""
# If we have an old state and no target temp, restore
if self._target_temp is None:
old_state = yield from async_get_last_state(self.hass,
self.entity_id)
if old_state is not None:
self._target_temp = float(
old_state.attributes[ATTR_TEMPERATURE])
@property
def should_poll(self):
"""Return the polling state."""