mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Fix vacuum reproduce state calling the removed turn_on and turn_off (#188131)
This commit is contained in:
@@ -5,13 +5,7 @@ from collections.abc import Iterable
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import Context, HomeAssistant, State
|
||||
|
||||
from . import DOMAIN, VacuumActivity
|
||||
@@ -19,7 +13,6 @@ from .const import VacuumEntityStateAttribute, VacuumService
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
VALID_STATES_TOGGLE = {STATE_ON, STATE_OFF}
|
||||
VALID_STATES_STATE = {
|
||||
VacuumActivity.CLEANING,
|
||||
VacuumActivity.DOCKED,
|
||||
@@ -41,7 +34,7 @@ async def _async_reproduce_state(
|
||||
_LOGGER.warning("Unable to find entity %s", state.entity_id)
|
||||
return
|
||||
|
||||
if not (state.state in VALID_STATES_TOGGLE or state.state in VALID_STATES_STATE):
|
||||
if state.state not in VALID_STATES_STATE:
|
||||
_LOGGER.warning(
|
||||
"Invalid state specified for %s: %s", state.entity_id, state.state
|
||||
)
|
||||
@@ -57,11 +50,7 @@ async def _async_reproduce_state(
|
||||
|
||||
if cur_state.state != state.state:
|
||||
# Wrong state
|
||||
if state.state == STATE_ON:
|
||||
service = SERVICE_TURN_ON
|
||||
elif state.state == STATE_OFF:
|
||||
service = SERVICE_TURN_OFF
|
||||
elif state.state == VacuumActivity.CLEANING:
|
||||
if state.state == VacuumActivity.CLEANING:
|
||||
service = VacuumService.START
|
||||
elif state.state in [VacuumActivity.DOCKED, VacuumActivity.RETURNING]:
|
||||
service = VacuumService.RETURN_TO_BASE
|
||||
|
||||
@@ -13,7 +13,7 @@ from homeassistant.components.vacuum import (
|
||||
SERVICE_STOP,
|
||||
VacuumActivity,
|
||||
)
|
||||
from homeassistant.const import SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.state import async_reproduce_state
|
||||
|
||||
@@ -25,10 +25,10 @@ async def test_reproducing_states(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test reproducing Vacuum states."""
|
||||
hass.states.async_set("vacuum.entity_off", STATE_OFF, {})
|
||||
hass.states.async_set("vacuum.entity_on", STATE_ON, {})
|
||||
hass.states.async_set(
|
||||
"vacuum.entity_on_fan", STATE_ON, {ATTR_FAN_SPEED: FAN_SPEED_LOW}
|
||||
"vacuum.entity_cleaning_fan",
|
||||
VacuumActivity.CLEANING,
|
||||
{ATTR_FAN_SPEED: FAN_SPEED_LOW},
|
||||
)
|
||||
hass.states.async_set("vacuum.entity_cleaning", VacuumActivity.CLEANING, {})
|
||||
hass.states.async_set("vacuum.entity_docked", VacuumActivity.DOCKED, {})
|
||||
@@ -36,8 +36,6 @@ async def test_reproducing_states(
|
||||
hass.states.async_set("vacuum.entity_returning", VacuumActivity.RETURNING, {})
|
||||
hass.states.async_set("vacuum.entity_paused", VacuumActivity.PAUSED, {})
|
||||
|
||||
turn_on_calls = async_mock_service(hass, DOMAIN, SERVICE_TURN_ON)
|
||||
turn_off_calls = async_mock_service(hass, DOMAIN, SERVICE_TURN_OFF)
|
||||
start_calls = async_mock_service(hass, DOMAIN, SERVICE_START)
|
||||
pause_calls = async_mock_service(hass, DOMAIN, SERVICE_PAUSE)
|
||||
stop_calls = async_mock_service(hass, DOMAIN, SERVICE_STOP)
|
||||
@@ -48,9 +46,11 @@ async def test_reproducing_states(
|
||||
await async_reproduce_state(
|
||||
hass,
|
||||
[
|
||||
State("vacuum.entity_off", STATE_OFF),
|
||||
State("vacuum.entity_on", STATE_ON),
|
||||
State("vacuum.entity_on_fan", STATE_ON, {ATTR_FAN_SPEED: FAN_SPEED_LOW}),
|
||||
State(
|
||||
"vacuum.entity_cleaning_fan",
|
||||
VacuumActivity.CLEANING,
|
||||
{ATTR_FAN_SPEED: FAN_SPEED_LOW},
|
||||
),
|
||||
State("vacuum.entity_cleaning", VacuumActivity.CLEANING),
|
||||
State("vacuum.entity_docked", VacuumActivity.DOCKED),
|
||||
State("vacuum.entity_idle", VacuumActivity.IDLE),
|
||||
@@ -59,20 +59,27 @@ async def test_reproducing_states(
|
||||
],
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 0
|
||||
assert len(turn_off_calls) == 0
|
||||
assert len(start_calls) == 0
|
||||
assert len(pause_calls) == 0
|
||||
assert len(stop_calls) == 0
|
||||
assert len(return_calls) == 0
|
||||
assert len(fan_speed_calls) == 0
|
||||
|
||||
# Test invalid state is handled
|
||||
await async_reproduce_state(hass, [State("vacuum.entity_off", "not_supported")])
|
||||
# Test invalid states are handled, including on/off which vacuums no longer have
|
||||
await async_reproduce_state(
|
||||
hass,
|
||||
[
|
||||
State("vacuum.entity_docked", "not_supported"),
|
||||
State("vacuum.entity_idle", STATE_ON),
|
||||
State("vacuum.entity_cleaning", STATE_OFF),
|
||||
],
|
||||
)
|
||||
|
||||
assert "not_supported" in caplog.text
|
||||
assert len(turn_on_calls) == 0
|
||||
assert len(turn_off_calls) == 0
|
||||
assert (
|
||||
"Invalid state specified for vacuum.entity_docked: not_supported" in caplog.text
|
||||
)
|
||||
assert "Invalid state specified for vacuum.entity_idle: on" in caplog.text
|
||||
assert "Invalid state specified for vacuum.entity_cleaning: off" in caplog.text
|
||||
assert len(start_calls) == 0
|
||||
assert len(pause_calls) == 0
|
||||
assert len(stop_calls) == 0
|
||||
@@ -83,27 +90,21 @@ async def test_reproducing_states(
|
||||
await async_reproduce_state(
|
||||
hass,
|
||||
[
|
||||
State("vacuum.entity_off", STATE_ON),
|
||||
State("vacuum.entity_on", STATE_OFF),
|
||||
State("vacuum.entity_on_fan", STATE_ON, {ATTR_FAN_SPEED: FAN_SPEED_HIGH}),
|
||||
State(
|
||||
"vacuum.entity_cleaning_fan",
|
||||
VacuumActivity.CLEANING,
|
||||
{ATTR_FAN_SPEED: FAN_SPEED_HIGH},
|
||||
),
|
||||
State("vacuum.entity_cleaning", VacuumActivity.PAUSED),
|
||||
State("vacuum.entity_docked", VacuumActivity.CLEANING),
|
||||
State("vacuum.entity_idle", VacuumActivity.DOCKED),
|
||||
State("vacuum.entity_returning", VacuumActivity.CLEANING),
|
||||
State("vacuum.entity_paused", VacuumActivity.IDLE),
|
||||
# Should not raise
|
||||
State("vacuum.non_existing", STATE_ON),
|
||||
State("vacuum.non_existing", VacuumActivity.CLEANING),
|
||||
],
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
assert turn_on_calls[0].domain == "vacuum"
|
||||
assert turn_on_calls[0].data == {"entity_id": "vacuum.entity_off"}
|
||||
|
||||
assert len(turn_off_calls) == 1
|
||||
assert turn_off_calls[0].domain == "vacuum"
|
||||
assert turn_off_calls[0].data == {"entity_id": "vacuum.entity_on"}
|
||||
|
||||
assert len(start_calls) == 2
|
||||
entities = [
|
||||
{"entity_id": "vacuum.entity_docked"},
|
||||
@@ -129,6 +130,6 @@ async def test_reproducing_states(
|
||||
assert len(fan_speed_calls) == 1
|
||||
assert fan_speed_calls[0].domain == "vacuum"
|
||||
assert fan_speed_calls[0].data == {
|
||||
"entity_id": "vacuum.entity_on_fan",
|
||||
"entity_id": "vacuum.entity_cleaning_fan",
|
||||
ATTR_FAN_SPEED: FAN_SPEED_HIGH,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user