mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Support this variable in template vacuum actions (#71800)
This commit is contained in:
parent
9eca91afc9
commit
6f7a465347
@ -204,42 +204,42 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity):
|
|||||||
|
|
||||||
async def async_start(self):
|
async def async_start(self):
|
||||||
"""Start or resume the cleaning task."""
|
"""Start or resume the cleaning task."""
|
||||||
await self._start_script.async_run(context=self._context)
|
await self.async_run_script(self._start_script, context=self._context)
|
||||||
|
|
||||||
async def async_pause(self):
|
async def async_pause(self):
|
||||||
"""Pause the cleaning task."""
|
"""Pause the cleaning task."""
|
||||||
if self._pause_script is None:
|
if self._pause_script is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
await self._pause_script.async_run(context=self._context)
|
await self.async_run_script(self._pause_script, context=self._context)
|
||||||
|
|
||||||
async def async_stop(self, **kwargs):
|
async def async_stop(self, **kwargs):
|
||||||
"""Stop the cleaning task."""
|
"""Stop the cleaning task."""
|
||||||
if self._stop_script is None:
|
if self._stop_script is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
await self._stop_script.async_run(context=self._context)
|
await self.async_run_script(self._stop_script, context=self._context)
|
||||||
|
|
||||||
async def async_return_to_base(self, **kwargs):
|
async def async_return_to_base(self, **kwargs):
|
||||||
"""Set the vacuum cleaner to return to the dock."""
|
"""Set the vacuum cleaner to return to the dock."""
|
||||||
if self._return_to_base_script is None:
|
if self._return_to_base_script is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
await self._return_to_base_script.async_run(context=self._context)
|
await self.async_run_script(self._return_to_base_script, context=self._context)
|
||||||
|
|
||||||
async def async_clean_spot(self, **kwargs):
|
async def async_clean_spot(self, **kwargs):
|
||||||
"""Perform a spot clean-up."""
|
"""Perform a spot clean-up."""
|
||||||
if self._clean_spot_script is None:
|
if self._clean_spot_script is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
await self._clean_spot_script.async_run(context=self._context)
|
await self.async_run_script(self._clean_spot_script, context=self._context)
|
||||||
|
|
||||||
async def async_locate(self, **kwargs):
|
async def async_locate(self, **kwargs):
|
||||||
"""Locate the vacuum cleaner."""
|
"""Locate the vacuum cleaner."""
|
||||||
if self._locate_script is None:
|
if self._locate_script is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
await self._locate_script.async_run(context=self._context)
|
await self.async_run_script(self._locate_script, context=self._context)
|
||||||
|
|
||||||
async def async_set_fan_speed(self, fan_speed, **kwargs):
|
async def async_set_fan_speed(self, fan_speed, **kwargs):
|
||||||
"""Set fan speed."""
|
"""Set fan speed."""
|
||||||
@ -248,8 +248,10 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity):
|
|||||||
|
|
||||||
if fan_speed in self._attr_fan_speed_list:
|
if fan_speed in self._attr_fan_speed_list:
|
||||||
self._attr_fan_speed = fan_speed
|
self._attr_fan_speed = fan_speed
|
||||||
await self._set_fan_speed_script.async_run(
|
await self.async_run_script(
|
||||||
{ATTR_FAN_SPEED: fan_speed}, context=self._context
|
self._set_fan_speed_script,
|
||||||
|
run_variables={ATTR_FAN_SPEED: fan_speed},
|
||||||
|
context=self._context,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -342,7 +342,7 @@ async def test_unused_services(hass):
|
|||||||
_verify(hass, STATE_UNKNOWN, None)
|
_verify(hass, STATE_UNKNOWN, None)
|
||||||
|
|
||||||
|
|
||||||
async def test_state_services(hass):
|
async def test_state_services(hass, calls):
|
||||||
"""Test state services."""
|
"""Test state services."""
|
||||||
await _register_components(hass)
|
await _register_components(hass)
|
||||||
|
|
||||||
@ -353,6 +353,9 @@ async def test_state_services(hass):
|
|||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_CLEANING
|
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_CLEANING
|
||||||
_verify(hass, STATE_CLEANING, None)
|
_verify(hass, STATE_CLEANING, None)
|
||||||
|
assert len(calls) == 1
|
||||||
|
assert calls[-1].data["action"] == "start"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
|
||||||
# Pause vacuum
|
# Pause vacuum
|
||||||
await common.async_pause(hass, _TEST_VACUUM)
|
await common.async_pause(hass, _TEST_VACUUM)
|
||||||
@ -361,6 +364,9 @@ async def test_state_services(hass):
|
|||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_PAUSED
|
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_PAUSED
|
||||||
_verify(hass, STATE_PAUSED, None)
|
_verify(hass, STATE_PAUSED, None)
|
||||||
|
assert len(calls) == 2
|
||||||
|
assert calls[-1].data["action"] == "pause"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
|
||||||
# Stop vacuum
|
# Stop vacuum
|
||||||
await common.async_stop(hass, _TEST_VACUUM)
|
await common.async_stop(hass, _TEST_VACUUM)
|
||||||
@ -369,6 +375,9 @@ async def test_state_services(hass):
|
|||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_IDLE
|
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_IDLE
|
||||||
_verify(hass, STATE_IDLE, None)
|
_verify(hass, STATE_IDLE, None)
|
||||||
|
assert len(calls) == 3
|
||||||
|
assert calls[-1].data["action"] == "stop"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
|
||||||
# Return vacuum to base
|
# Return vacuum to base
|
||||||
await common.async_return_to_base(hass, _TEST_VACUUM)
|
await common.async_return_to_base(hass, _TEST_VACUUM)
|
||||||
@ -377,9 +386,12 @@ async def test_state_services(hass):
|
|||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_RETURNING
|
assert hass.states.get(_STATE_INPUT_SELECT).state == STATE_RETURNING
|
||||||
_verify(hass, STATE_RETURNING, None)
|
_verify(hass, STATE_RETURNING, None)
|
||||||
|
assert len(calls) == 4
|
||||||
|
assert calls[-1].data["action"] == "return_to_base"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
|
||||||
|
|
||||||
async def test_clean_spot_service(hass):
|
async def test_clean_spot_service(hass, calls):
|
||||||
"""Test clean spot service."""
|
"""Test clean spot service."""
|
||||||
await _register_components(hass)
|
await _register_components(hass)
|
||||||
|
|
||||||
@ -389,9 +401,12 @@ async def test_clean_spot_service(hass):
|
|||||||
|
|
||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_SPOT_CLEANING_INPUT_BOOLEAN).state == STATE_ON
|
assert hass.states.get(_SPOT_CLEANING_INPUT_BOOLEAN).state == STATE_ON
|
||||||
|
assert len(calls) == 1
|
||||||
|
assert calls[-1].data["action"] == "clean_spot"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
|
||||||
|
|
||||||
async def test_locate_service(hass):
|
async def test_locate_service(hass, calls):
|
||||||
"""Test locate service."""
|
"""Test locate service."""
|
||||||
await _register_components(hass)
|
await _register_components(hass)
|
||||||
|
|
||||||
@ -401,9 +416,12 @@ async def test_locate_service(hass):
|
|||||||
|
|
||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_LOCATING_INPUT_BOOLEAN).state == STATE_ON
|
assert hass.states.get(_LOCATING_INPUT_BOOLEAN).state == STATE_ON
|
||||||
|
assert len(calls) == 1
|
||||||
|
assert calls[-1].data["action"] == "locate"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
|
||||||
|
|
||||||
async def test_set_fan_speed(hass):
|
async def test_set_fan_speed(hass, calls):
|
||||||
"""Test set valid fan speed."""
|
"""Test set valid fan speed."""
|
||||||
await _register_components(hass)
|
await _register_components(hass)
|
||||||
|
|
||||||
@ -413,6 +431,10 @@ async def test_set_fan_speed(hass):
|
|||||||
|
|
||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_FAN_SPEED_INPUT_SELECT).state == "high"
|
assert hass.states.get(_FAN_SPEED_INPUT_SELECT).state == "high"
|
||||||
|
assert len(calls) == 1
|
||||||
|
assert calls[-1].data["action"] == "set_fan_speed"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
assert calls[-1].data["option"] == "high"
|
||||||
|
|
||||||
# Set fan's speed to medium
|
# Set fan's speed to medium
|
||||||
await common.async_set_fan_speed(hass, "medium", _TEST_VACUUM)
|
await common.async_set_fan_speed(hass, "medium", _TEST_VACUUM)
|
||||||
@ -420,9 +442,13 @@ async def test_set_fan_speed(hass):
|
|||||||
|
|
||||||
# verify
|
# verify
|
||||||
assert hass.states.get(_FAN_SPEED_INPUT_SELECT).state == "medium"
|
assert hass.states.get(_FAN_SPEED_INPUT_SELECT).state == "medium"
|
||||||
|
assert len(calls) == 2
|
||||||
|
assert calls[-1].data["action"] == "set_fan_speed"
|
||||||
|
assert calls[-1].data["caller"] == _TEST_VACUUM
|
||||||
|
assert calls[-1].data["option"] == "medium"
|
||||||
|
|
||||||
|
|
||||||
async def test_set_invalid_fan_speed(hass):
|
async def test_set_invalid_fan_speed(hass, calls):
|
||||||
"""Test set invalid fan speed when fan has valid speed."""
|
"""Test set invalid fan speed when fan has valid speed."""
|
||||||
await _register_components(hass)
|
await _register_components(hass)
|
||||||
|
|
||||||
@ -522,37 +548,107 @@ async def _register_components(hass):
|
|||||||
test_vacuum_config = {
|
test_vacuum_config = {
|
||||||
"value_template": "{{ states('input_select.state') }}",
|
"value_template": "{{ states('input_select.state') }}",
|
||||||
"fan_speed_template": "{{ states('input_select.fan_speed') }}",
|
"fan_speed_template": "{{ states('input_select.fan_speed') }}",
|
||||||
"start": {
|
"start": [
|
||||||
"service": "input_select.select_option",
|
{
|
||||||
"data": {"entity_id": _STATE_INPUT_SELECT, "option": STATE_CLEANING},
|
"service": "input_select.select_option",
|
||||||
},
|
"data": {
|
||||||
"pause": {
|
"entity_id": _STATE_INPUT_SELECT,
|
||||||
"service": "input_select.select_option",
|
"option": STATE_CLEANING,
|
||||||
"data": {"entity_id": _STATE_INPUT_SELECT, "option": STATE_PAUSED},
|
},
|
||||||
},
|
|
||||||
"stop": {
|
|
||||||
"service": "input_select.select_option",
|
|
||||||
"data": {"entity_id": _STATE_INPUT_SELECT, "option": STATE_IDLE},
|
|
||||||
},
|
|
||||||
"return_to_base": {
|
|
||||||
"service": "input_select.select_option",
|
|
||||||
"data": {"entity_id": _STATE_INPUT_SELECT, "option": STATE_RETURNING},
|
|
||||||
},
|
|
||||||
"clean_spot": {
|
|
||||||
"service": "input_boolean.turn_on",
|
|
||||||
"entity_id": _SPOT_CLEANING_INPUT_BOOLEAN,
|
|
||||||
},
|
|
||||||
"locate": {
|
|
||||||
"service": "input_boolean.turn_on",
|
|
||||||
"entity_id": _LOCATING_INPUT_BOOLEAN,
|
|
||||||
},
|
|
||||||
"set_fan_speed": {
|
|
||||||
"service": "input_select.select_option",
|
|
||||||
"data_template": {
|
|
||||||
"entity_id": _FAN_SPEED_INPUT_SELECT,
|
|
||||||
"option": "{{ fan_speed }}",
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "start",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"pause": [
|
||||||
|
{
|
||||||
|
"service": "input_select.select_option",
|
||||||
|
"data": {"entity_id": _STATE_INPUT_SELECT, "option": STATE_PAUSED},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "pause",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"stop": [
|
||||||
|
{
|
||||||
|
"service": "input_select.select_option",
|
||||||
|
"data": {"entity_id": _STATE_INPUT_SELECT, "option": STATE_IDLE},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "stop",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"return_to_base": [
|
||||||
|
{
|
||||||
|
"service": "input_select.select_option",
|
||||||
|
"data": {
|
||||||
|
"entity_id": _STATE_INPUT_SELECT,
|
||||||
|
"option": STATE_RETURNING,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "return_to_base",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"clean_spot": [
|
||||||
|
{
|
||||||
|
"service": "input_boolean.turn_on",
|
||||||
|
"entity_id": _SPOT_CLEANING_INPUT_BOOLEAN,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "clean_spot",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"locate": [
|
||||||
|
{
|
||||||
|
"service": "input_boolean.turn_on",
|
||||||
|
"entity_id": _LOCATING_INPUT_BOOLEAN,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "locate",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"set_fan_speed": [
|
||||||
|
{
|
||||||
|
"service": "input_select.select_option",
|
||||||
|
"data_template": {
|
||||||
|
"entity_id": _FAN_SPEED_INPUT_SELECT,
|
||||||
|
"option": "{{ fan_speed }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"service": "test.automation",
|
||||||
|
"data_template": {
|
||||||
|
"action": "set_fan_speed",
|
||||||
|
"caller": "{{ this.entity_id }}",
|
||||||
|
"option": "{{ fan_speed }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
"fan_speeds": ["low", "medium", "high"],
|
"fan_speeds": ["low", "medium", "high"],
|
||||||
"attribute_templates": {
|
"attribute_templates": {
|
||||||
"test_attribute": "It {{ states.sensor.test_state.state }}."
|
"test_attribute": "It {{ states.sensor.test_state.state }}."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user