Add context to scripts and automations (#16415)
* Add context to script helper * Update script component * Add context to automations * Lint
This commit is contained in:
1 parent
e1501c83f8
commit
746f4ac158
17 files changed
+164
-144
No files matched your search
@@ -3,7 +3,7 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import Context, callback
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.components import script
|
||||
|
||||
@@ -134,6 +134,7 @@ class TestScriptComponent(unittest.TestCase):
|
||||
def test_passing_variables(self):
|
||||
"""Test different ways of passing in variables."""
|
||||
calls = []
|
||||
context = Context()
|
||||
|
||||
@callback
|
||||
def record_call(service):
|
||||
@@ -157,21 +158,23 @@ class TestScriptComponent(unittest.TestCase):
|
||||
|
||||
script.turn_on(self.hass, ENTITY_ID, {
|
||||
'greeting': 'world'
|
||||
})
|
||||
}, context=context)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[-1].data['hello'] == 'world'
|
||||
assert calls[0].context is context
|
||||
assert calls[0].data['hello'] == 'world'
|
||||
|
||||
self.hass.services.call('script', 'test', {
|
||||
'greeting': 'universe',
|
||||
})
|
||||
}, context=context)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(calls) == 2
|
||||
assert calls[-1].data['hello'] == 'universe'
|
||||
assert calls[1].context is context
|
||||
assert calls[1].data['hello'] == 'universe'
|
||||
|
||||
def test_reload_service(self):
|
||||
"""Verify that the turn_on service."""
|
||||
|
||||
Reference in new issue
Block a user