Add recent context (#15989)
* Add recent context * Add async_set_context to components not using new services
This commit is contained in:
parent
d1e1b9b38a
commit
1be61df9c0
11 changed files with 211 additions and 11 deletions
|
@ -5,7 +5,7 @@ import unittest
|
|||
|
||||
from tests.common import get_test_home_assistant, mock_restore_cache
|
||||
|
||||
from homeassistant.core import State
|
||||
from homeassistant.core import State, Context
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.components.input_select import (
|
||||
ATTR_OPTIONS, DOMAIN, SERVICE_SET_OPTIONS,
|
||||
|
@ -276,3 +276,30 @@ def test_initial_state_overrules_restore_state(hass):
|
|||
state = hass.states.get('input_select.s2')
|
||||
assert state
|
||||
assert state.state == 'middle option'
|
||||
|
||||
|
||||
async def test_input_select_context(hass):
|
||||
"""Test that input_select context works."""
|
||||
assert await async_setup_component(hass, 'input_select', {
|
||||
'input_select': {
|
||||
's1': {
|
||||
'options': [
|
||||
'first option',
|
||||
'middle option',
|
||||
'last option',
|
||||
],
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
state = hass.states.get('input_select.s1')
|
||||
assert state is not None
|
||||
|
||||
await hass.services.async_call('input_select', 'select_next', {
|
||||
'entity_id': state.entity_id,
|
||||
}, True, Context(user_id='abcd'))
|
||||
|
||||
state2 = hass.states.get('input_select.s1')
|
||||
assert state2 is not None
|
||||
assert state.state != state2.state
|
||||
assert state2.context.user_id == 'abcd'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue