mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add recent context (#15989)
* Add recent context * Add async_set_context to components not using new services
This commit is contained in:
@@ -4,7 +4,7 @@ import asyncio
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
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.counter import (
|
||||
DOMAIN, decrement, increment, reset, CONF_INITIAL, CONF_STEP, CONF_NAME,
|
||||
@@ -202,3 +202,24 @@ def test_no_initial_state_and_no_restore_state(hass):
|
||||
state = hass.states.get('counter.test1')
|
||||
assert state
|
||||
assert int(state.state) == 0
|
||||
|
||||
|
||||
async def test_counter_context(hass):
|
||||
"""Test that counter context works."""
|
||||
assert await async_setup_component(hass, 'counter', {
|
||||
'counter': {
|
||||
'test': {}
|
||||
}
|
||||
})
|
||||
|
||||
state = hass.states.get('counter.test')
|
||||
assert state is not None
|
||||
|
||||
await hass.services.async_call('counter', 'increment', {
|
||||
'entity_id': state.entity_id,
|
||||
}, True, Context(user_id='abcd'))
|
||||
|
||||
state2 = hass.states.get('counter.test')
|
||||
assert state2 is not None
|
||||
assert state.state != state2.state
|
||||
assert state2.context.user_id == 'abcd'
|
||||
|
||||
Reference in New Issue
Block a user