-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Restore for automation entities #6254
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
Merged
Merged
Changes from 3 commits
Commits
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,17 +1,19 @@ | ||
| """The tests for the automation component.""" | ||
| import unittest | ||
| import asyncio | ||
| from datetime import timedelta | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant.core import callback | ||
| from homeassistant.bootstrap import setup_component | ||
| from homeassistant.core import State | ||
| from homeassistant.bootstrap import setup_component, async_setup_component | ||
| import homeassistant.components.automation as automation | ||
| from homeassistant.const import ATTR_ENTITY_ID | ||
| from homeassistant.const import ATTR_ENTITY_ID, STATE_ON, STATE_OFF | ||
| from homeassistant.exceptions import HomeAssistantError | ||
| import homeassistant.util.dt as dt_util | ||
|
|
||
| from tests.common import get_test_home_assistant, assert_setup_component, \ | ||
| fire_time_changed, mock_component | ||
| from tests.common import ( | ||
| assert_setup_component, get_test_home_assistant, fire_time_changed, | ||
| mock_component, mock_service, mock_restore_cache) | ||
|
|
||
|
|
||
| # pylint: disable=invalid-name | ||
|
|
@@ -22,14 +24,7 @@ def setUp(self): | |
| """Setup things to be run when tests are started.""" | ||
| self.hass = get_test_home_assistant() | ||
| mock_component(self.hass, 'group') | ||
| self.calls = [] | ||
|
|
||
| @callback | ||
| def record_call(service): | ||
| """Helper to record calls.""" | ||
| self.calls.append(service) | ||
|
|
||
| self.hass.services.register('test', 'automation', record_call) | ||
| self.calls = mock_service(self.hass, 'test', 'automation') | ||
|
|
||
| def tearDown(self): | ||
| """Stop everything that was started.""" | ||
|
|
@@ -572,3 +567,55 @@ def test_reload_config_handles_load_fails(self): | |
| self.hass.bus.fire('test_event') | ||
| self.hass.block_till_done() | ||
| assert len(self.calls) == 2 | ||
|
|
||
|
|
||
| @asyncio.coroutine | ||
| def test_automation_restore_state(hass): | ||
| """Ensure states are restored on startup.""" | ||
| time = dt_util.utcnow() | ||
|
|
||
| mock_restore_cache(hass, ( | ||
| State('automation.hello', STATE_ON), | ||
| State('automation.bye', STATE_OFF, {'last_triggered': time}), | ||
| )) | ||
|
|
||
| config = {automation.DOMAIN: [{ | ||
| 'alias': 'hello', | ||
| 'trigger': { | ||
| 'platform': 'event', | ||
| 'event_type': 'test_event_hello', | ||
| }, | ||
| 'action': {'service': 'test.automation'} | ||
| }, { | ||
| 'alias': 'bye', | ||
| 'trigger': { | ||
| 'platform': 'event', | ||
| 'event_type': 'test_event_bye', | ||
| }, | ||
| 'action': {'service': 'test.automation'} | ||
| }]} | ||
|
|
||
| assert (yield from async_setup_component(hass, automation.DOMAIN, config)) | ||
|
|
||
| state = hass.states.get('automation.hello') | ||
| assert state | ||
| assert state.state == STATE_ON | ||
|
|
||
| state = hass.states.get('automation.bye') | ||
| assert state | ||
| assert state.state == STATE_OFF | ||
| assert state.attributes.get('last_triggered') == time | ||
|
|
||
| calls = mock_service(hass, 'test', 'automation') | ||
|
|
||
| hass.bus.fire('test_event_bye') | ||
| yield from hass.async_block_till_done() | ||
| assert len(calls) == 0 | ||
|
|
||
| hass.bus.fire('test_event_hello') | ||
| yield from hass.async_block_till_done() | ||
|
|
||
| import time | ||
| time.sleep(1) | ||
|
|
||
| assert len(calls) == 1 | ||
|
Member
Author
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. This seems to fail for py3.5 & 3.6, but always passes on 3.4 @pvizeli any ideas? |
||
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.
I prefer if we make an
async_mock_serviceand havemock_servicecall that