-
-
Notifications
You must be signed in to change notification settings - Fork 38.1k
Fix issues with generic thermostat #11805
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,8 @@ | |
| SUPPORT_AWAY_MODE, SUPPORT_TARGET_TEMPERATURE, PLATFORM_SCHEMA) | ||
| from homeassistant.const import ( | ||
| ATTR_UNIT_OF_MEASUREMENT, STATE_ON, STATE_OFF, ATTR_TEMPERATURE, | ||
| CONF_NAME, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF) | ||
| CONF_NAME, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF, | ||
| STATE_UNKNOWN) | ||
| from homeassistant.helpers import condition | ||
| from homeassistant.helpers.event import ( | ||
| async_track_state_change, async_track_time_interval) | ||
|
|
@@ -30,7 +31,6 @@ | |
|
|
||
| DEFAULT_TOLERANCE = 0.3 | ||
| DEFAULT_NAME = 'Generic Thermostat' | ||
| DEFAULT_AWAY_TEMP = 16 | ||
|
|
||
| CONF_HEATER = 'heater' | ||
| CONF_SENSOR = 'target_sensor' | ||
|
|
@@ -44,7 +44,7 @@ | |
| CONF_KEEP_ALIVE = 'keep_alive' | ||
| CONF_INITIAL_OPERATION_MODE = 'initial_operation_mode' | ||
| CONF_AWAY_TEMP = 'away_temp' | ||
| SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_AWAY_MODE | | ||
| SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | | ||
| SUPPORT_OPERATION_MODE) | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
|
|
@@ -64,8 +64,7 @@ | |
| cv.time_period, cv.positive_timedelta), | ||
| vol.Optional(CONF_INITIAL_OPERATION_MODE): | ||
| vol.In([STATE_AUTO, STATE_OFF]), | ||
| vol.Optional(CONF_AWAY_TEMP, | ||
| default=DEFAULT_AWAY_TEMP): vol.Coerce(float) | ||
| vol.Optional(CONF_AWAY_TEMP): vol.Coerce(float) | ||
| }) | ||
|
|
||
|
|
||
|
|
@@ -119,6 +118,7 @@ def __init__(self, hass, name, heater_entity_id, sensor_entity_id, | |
| self._operation_list = [STATE_HEAT, STATE_OFF] | ||
| if initial_operation_mode == STATE_OFF: | ||
| self._enabled = False | ||
| self._current_operation = STATE_OFF | ||
| else: | ||
| self._enabled = True | ||
| self._active = False | ||
|
|
@@ -127,6 +127,9 @@ def __init__(self, hass, name, heater_entity_id, sensor_entity_id, | |
| self._max_temp = max_temp | ||
| self._target_temp = target_temp | ||
| self._unit = hass.config.units.temperature_unit | ||
| self._support_flags = SUPPORT_FLAGS | ||
| if away_temp is not None: | ||
| self._support_flags = SUPPORT_FLAGS | SUPPORT_AWAY_MODE | ||
| self._away_temp = away_temp | ||
| self._is_away = False | ||
|
|
||
|
|
@@ -139,6 +142,10 @@ def __init__(self, hass, name, heater_entity_id, sensor_entity_id, | |
| async_track_time_interval( | ||
| hass, self._async_keep_alive, self._keep_alive) | ||
|
|
||
| sensor_state = hass.states.get(sensor_entity_id) | ||
| if sensor_state and sensor_state.state != STATE_UNKNOWN: | ||
| self._async_update_temp(sensor_state) | ||
|
|
||
| @asyncio.coroutine | ||
| def async_added_to_hass(self): | ||
| """Run when entity about to be added.""" | ||
|
|
@@ -154,19 +161,33 @@ def async_added_to_hass(self): | |
| self._target_temp = self.max_temp | ||
| else: | ||
| self._target_temp = self.min_temp | ||
| _LOGGER.warning('Undefined target temperature, \ | ||
| falling back to %s', self._target_temp) | ||
| _LOGGER.warning('Undefined target temperature,' | ||
| 'falling back to %s', self._target_temp) | ||
| else: | ||
| self._target_temp = float( | ||
| old_state.attributes[ATTR_TEMPERATURE]) | ||
| self._is_away = True if str( | ||
| old_state.attributes[ATTR_AWAY_MODE]) == STATE_ON else False | ||
| if old_state.attributes[ATTR_AWAY_MODE] is not None: | ||
| self._is_away = True if str( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self._is_away = str(
old_state.attributes[ATTR_AWAY_MODE]) == STATE_ON |
||
| old_state.attributes[ATTR_AWAY_MODE]) == STATE_ON \ | ||
| else False | ||
| if old_state.attributes[ATTR_OPERATION_MODE] == STATE_OFF: | ||
| self._current_operation = STATE_OFF | ||
| self._enabled = False | ||
| if self._initial_operation_mode is None: | ||
| if old_state.attributes[ATTR_OPERATION_MODE] == STATE_OFF: | ||
| self._enabled = False | ||
| if old_state.attributes[ATTR_OPERATION_MODE] is not None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Join this with the statement on the previous line using |
||
| self._current_operation = \ | ||
| old_state.attributes[ATTR_OPERATION_MODE] | ||
| if self._current_operation != STATE_OFF: | ||
| self._enabled = True | ||
| else: | ||
| # No previous state, try and restore defaults | ||
| if self._target_temp is None: | ||
| if self.ac_mode: | ||
| self._target_temp = self.max_temp | ||
| else: | ||
| self._target_temp = self.min_temp | ||
| _LOGGER.warning("No previously saved temperature, setting to %s", | ||
| self._target_temp) | ||
|
|
||
| @property | ||
| def state(self): | ||
|
|
@@ -308,7 +329,8 @@ def _async_control_heating(self): | |
| self._target_temp): | ||
| self._active = True | ||
| _LOGGER.info('Obtained current and target temperature. ' | ||
| 'Generic thermostat active.') | ||
| 'Generic thermostat active. %s, %s', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use double quotes. |
||
| self._cur_temp, self._target_temp) | ||
|
|
||
| if not self._active: | ||
| return | ||
|
|
@@ -365,7 +387,7 @@ def _is_device_active(self): | |
| @property | ||
| def supported_features(self): | ||
| """Return the list of supported features.""" | ||
| return SUPPORT_FLAGS | ||
| return self._support_flags | ||
|
|
||
| @callback | ||
| def _heater_turn_on(self): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use double quotes for log messages.