-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Restore manual alarm-control-panel state using async_get_last_state #17521
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 2 commits
a14f501
5db3d4f
25a5d6b
f53f964
3b9ca94
802b81a
65a8be9
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 |
|---|---|---|
|
|
@@ -3,18 +3,18 @@ | |
| import unittest | ||
| from unittest.mock import patch, MagicMock | ||
| from homeassistant.components.alarm_control_panel import demo | ||
|
|
||
|
|
||
| from homeassistant.setup import setup_component | ||
| import asyncio | ||
| from homeassistant.setup import setup_component, async_setup_component | ||
| from homeassistant.const import ( | ||
| STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY, | ||
| STATE_ALARM_ARMED_NIGHT, STATE_ALARM_ARMED_CUSTOM_BYPASS, | ||
| STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED) | ||
| from homeassistant.components import alarm_control_panel | ||
| import homeassistant.util.dt as dt_util | ||
|
|
||
| from tests.common import fire_time_changed, get_test_home_assistant | ||
| from tests.common import (fire_time_changed, get_test_home_assistant, | ||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
| mock_component, mock_restore_cache) | ||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
| from tests.components.alarm_control_panel import common | ||
| from homeassistant.core import State, CoreState | ||
|
|
||
| CODE = 'HELLO_CODE' | ||
|
|
||
|
|
@@ -1319,3 +1319,50 @@ def test_arm_away_after_disabled_disarmed(self): | |
|
|
||
| state = self.hass.states.get(entity_id) | ||
| self.assertEqual(STATE_ALARM_TRIGGERED, state.state) | ||
|
|
||
| @asyncio.coroutine | ||
|
liaanvdm marked this conversation as resolved.
Outdated
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. We've migrated to
Contributor
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. I've change the syntax as requested. I based my tests on the tests i found in the input variable components, those are still using the asyncio decorator.
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. I know. Those need to be updated too. For now we just make sure we don't add new ones. |
||
| def test_restore_armed_state(hass): | ||
| """Ensure armed state is restored on startup.""" | ||
| mock_restore_cache(hass, ( | ||
| State('alarm_control_panel.test', STATE_ALARM_ARMED_AWAY), | ||
| )) | ||
|
|
||
| hass.state = CoreState.starting | ||
| mock_component(hass, 'recorder') | ||
|
|
||
| yield from async_setup_component(hass, alarm_control_panel.DOMAIN, | ||
| {'alarm_control_panel': { | ||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
| 'platform': 'manual', | ||
| 'name': 'test', | ||
| 'pending_time': 0, | ||
| 'trigger_time': 0, | ||
| 'disarm_after_trigger': False | ||
| }}) | ||
|
|
||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
| state = hass.states.get('alarm_control_panel.test') | ||
| assert state | ||
| assert state.state == STATE_ALARM_ARMED_AWAY | ||
|
|
||
| @asyncio.coroutine | ||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
| def test_restore_disarmed_state(hass): | ||
| """Ensure disarmed state is restored on startup.""" | ||
| mock_restore_cache(hass, ( | ||
| State('alarm_control_panel.test', STATE_ALARM_DISARMED), | ||
| )) | ||
|
|
||
| hass.state = CoreState.starting | ||
| mock_component(hass, 'recorder') | ||
|
|
||
| yield from async_setup_component(hass, alarm_control_panel.DOMAIN, | ||
| {'alarm_control_panel': { | ||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
| 'platform': 'manual', | ||
| 'name': 'test', | ||
| 'pending_time': 0, | ||
| 'trigger_time': 0, | ||
| 'disarm_after_trigger': False | ||
| }}) | ||
|
|
||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
| state = hass.states.get('alarm_control_panel.test') | ||
| assert state | ||
| assert state.state == STATE_ALARM_DISARMED | ||
|
|
||
|
liaanvdm marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.