mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Support this variable in template number actions (#71797)
This commit is contained in:
parent
adde9130a1
commit
66ec4564f4
@ -157,8 +157,10 @@ class TemplateNumber(TemplateEntity, NumberEntity):
|
|||||||
if self._optimistic:
|
if self._optimistic:
|
||||||
self._attr_value = value
|
self._attr_value = value
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
await self._command_set_value.async_run(
|
await self.async_run_script(
|
||||||
{ATTR_VALUE: value}, context=self._context
|
self._command_set_value,
|
||||||
|
run_variables={ATTR_VALUE: value},
|
||||||
|
context=self._context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ async def test_all_optional_config(hass):
|
|||||||
_verify(hass, 4, 1, 3, 5)
|
_verify(hass, 4, 1, 3, 5)
|
||||||
|
|
||||||
|
|
||||||
async def test_templates_with_entities(hass):
|
async def test_templates_with_entities(hass, calls):
|
||||||
"""Test templates with values from other entities."""
|
"""Test templates with values from other entities."""
|
||||||
with assert_setup_component(4, "input_number"):
|
with assert_setup_component(4, "input_number"):
|
||||||
assert await setup.async_setup_component(
|
assert await setup.async_setup_component(
|
||||||
@ -173,13 +173,23 @@ async def test_templates_with_entities(hass):
|
|||||||
"step": f"{{{{ states('{_STEP_INPUT_NUMBER}') }}}}",
|
"step": f"{{{{ states('{_STEP_INPUT_NUMBER}') }}}}",
|
||||||
"min": f"{{{{ states('{_MINIMUM_INPUT_NUMBER}') }}}}",
|
"min": f"{{{{ states('{_MINIMUM_INPUT_NUMBER}') }}}}",
|
||||||
"max": f"{{{{ states('{_MAXIMUM_INPUT_NUMBER}') }}}}",
|
"max": f"{{{{ states('{_MAXIMUM_INPUT_NUMBER}') }}}}",
|
||||||
"set_value": {
|
"set_value": [
|
||||||
"service": "input_number.set_value",
|
{
|
||||||
"data_template": {
|
"service": "input_number.set_value",
|
||||||
"entity_id": _VALUE_INPUT_NUMBER,
|
"data_template": {
|
||||||
"value": "{{ value }}",
|
"entity_id": _VALUE_INPUT_NUMBER,
|
||||||
|
"value": "{{ value }}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "set_value",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
"value": "{{ value }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
"optimistic": True,
|
"optimistic": True,
|
||||||
"unique_id": "a",
|
"unique_id": "a",
|
||||||
},
|
},
|
||||||
@ -247,6 +257,12 @@ async def test_templates_with_entities(hass):
|
|||||||
)
|
)
|
||||||
_verify(hass, 2, 2, 2, 6)
|
_verify(hass, 2, 2, 2, 6)
|
||||||
|
|
||||||
|
# Check this variable can be used in set_value script
|
||||||
|
assert len(calls) == 1
|
||||||
|
assert calls[-1].data["action"] == "set_value"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_NUMBER
|
||||||
|
assert calls[-1].data["value"] == 2
|
||||||
|
|
||||||
|
|
||||||
async def test_trigger_number(hass):
|
async def test_trigger_number(hass):
|
||||||
"""Test trigger based template number."""
|
"""Test trigger based template number."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user