Add recent context (#15989)
* Add recent context * Add async_set_context to components not using new services
This commit is contained in:
1 parent
d1e1b9b38a
commit
1be61df9c0
11 files changed
+211
-11
No files matched your search
@@ -4,7 +4,7 @@ import asyncio
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
from homeassistant.core import CoreState, State
|
||||
from homeassistant.core import CoreState, State, Context
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.components.input_datetime import (
|
||||
DOMAIN, ATTR_ENTITY_ID, ATTR_DATE, ATTR_TIME, SERVICE_SET_DATETIME)
|
||||
@@ -208,3 +208,27 @@ def test_restore_state(hass):
|
||||
|
||||
state_bogus = hass.states.get('input_datetime.test_bogus_data')
|
||||
assert state_bogus.state == str(initial)
|
||||
|
||||
|
||||
async def test_input_datetime_context(hass):
|
||||
"""Test that input_datetime context works."""
|
||||
assert await async_setup_component(hass, 'input_datetime', {
|
||||
'input_datetime': {
|
||||
'only_date': {
|
||||
'has_date': True,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
state = hass.states.get('input_datetime.only_date')
|
||||
assert state is not None
|
||||
|
||||
await hass.services.async_call('input_datetime', 'set_datetime', {
|
||||
'entity_id': state.entity_id,
|
||||
'date': '2018-01-02'
|
||||
}, True, Context(user_id='abcd'))
|
||||
|
||||
state2 = hass.states.get('input_datetime.only_date')
|
||||
assert state2 is not None
|
||||
assert state.state != state2.state
|
||||
assert state2.context.user_id == 'abcd'
|
||||
Reference in new issue
Block a user