-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
Optional persistence in generic_thermostat #10636
Closed
ziotibia81
wants to merge
12
commits into
home-assistant:dev
from
ziotibia81:generic_thermostat_persistence
Closed
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
43ae96b
Update generic_thermostat.py
ziotibia81 79b90a2
Fix code syle
ziotibia81 9ff4021
Fix spaces
ziotibia81 ad51e4b
Fix ATTR_OPERATION_MODE
ziotibia81 106c50b
Fix Tests
ziotibia81 b9cb475
More fix to tests
ziotibia81 30a11ec
Fix conflicts
ziotibia81 81f9121
Merge branch 'dev' into generic_thermostat_persistence
ziotibia81 0d9c404
Merge branch 'dev' into generic_thermostat_persistence
ziotibia81 ef8db94
Fix new line at the end of file
ziotibia81 56471bd
Fix blank space
ziotibia81 2b9625c
FIX redefinition of unused 'async_added_to_has
ziotibia81 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
from homeassistant.helpers import condition | ||
from homeassistant.helpers.event import ( | ||
async_track_state_change, async_track_time_interval) | ||
from homeassistant.helpers.restore_state import async_get_last_state | ||
import homeassistant.helpers.config_validation as cv | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
@@ -39,7 +40,11 @@ | |
CONF_COLD_TOLERANCE = 'cold_tolerance' | ||
CONF_HOT_TOLERANCE = 'hot_tolerance' | ||
CONF_KEEP_ALIVE = 'keep_alive' | ||
CONF_PERSISTENCE = 'persistence' | ||
|
||
ATTR_NONE = 'none' | ||
ATTR_BOTH = 'both' | ||
ATTR_OPERATION_MODE = 'operation_mode' | ||
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Required(CONF_HEATER): cv.entity_id, | ||
|
@@ -56,6 +61,8 @@ | |
vol.Optional(CONF_TARGET_TEMP): vol.Coerce(float), | ||
vol.Optional(CONF_KEEP_ALIVE): vol.All( | ||
cv.time_period, cv.positive_timedelta), | ||
vol.Optional(CONF_PERSISTENCE, default=ATTR_NONE): vol.In( | ||
[ATTR_NONE, ATTR_BOTH, CONF_TARGET_TEMP, ATTR_OPERATION_MODE]), | ||
}) | ||
|
||
|
||
|
@@ -73,19 +80,20 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): | |
cold_tolerance = config.get(CONF_COLD_TOLERANCE) | ||
hot_tolerance = config.get(CONF_HOT_TOLERANCE) | ||
keep_alive = config.get(CONF_KEEP_ALIVE) | ||
persistence = config.get(CONF_PERSISTENCE) | ||
|
||
async_add_devices([GenericThermostat( | ||
hass, name, heater_entity_id, sensor_entity_id, min_temp, max_temp, | ||
target_temp, ac_mode, min_cycle_duration, cold_tolerance, | ||
hot_tolerance, keep_alive)]) | ||
hot_tolerance, keep_alive, persistence)]) | ||
|
||
|
||
class GenericThermostat(ClimateDevice): | ||
"""Representation of a Generic Thermostat device.""" | ||
|
||
def __init__(self, hass, name, heater_entity_id, sensor_entity_id, | ||
min_temp, max_temp, target_temp, ac_mode, min_cycle_duration, | ||
cold_tolerance, hot_tolerance, keep_alive): | ||
cold_tolerance, hot_tolerance, keep_alive, persistence): | ||
"""Initialize the thermostat.""" | ||
self.hass = hass | ||
self._name = name | ||
|
@@ -102,6 +110,7 @@ def __init__(self, hass, name, heater_entity_id, sensor_entity_id, | |
self._min_temp = min_temp | ||
self._max_temp = max_temp | ||
self._target_temp = target_temp | ||
self._persistence = persistence | ||
self._unit = hass.config.units.temperature_unit | ||
|
||
async_track_state_change( | ||
|
@@ -214,6 +223,19 @@ def _async_sensor_changed(self, entity_id, old_state, new_state): | |
self._async_control_heating() | ||
yield from self.async_update_ha_state() | ||
|
||
@asyncio.coroutine | ||
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. redefinition of unused 'async_added_to_hass' from line 129 |
||
def async_added_to_hass(self): | ||
"""Handle all entity which are about to be added.""" | ||
state = yield from async_get_last_state(self.hass, self.entity_id) | ||
if not state: | ||
return | ||
if self._persistence in [ATTR_BOTH, CONF_TARGET_TEMP]: | ||
self._target_temp = state.attributes[ATTR_TEMPERATURE] | ||
if (self._persistence in [ATTR_BOTH, ATTR_OPERATION_MODE] and | ||
state.attributes[ATTR_OPERATION_MODE] == STATE_OFF): | ||
self.set_operation_mode(STATE_OFF) | ||
return | ||
|
||
@callback | ||
def _async_switch_changed(self, entity_id, old_state, new_state): | ||
"""Handle heater switch state changes.""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is available in
homeassistant.components.climate