Fix threading error in demo vacuum (#62165)

pull/62196/head
Erik Montnemery 2021-12-17 12:45:53 +01:00 committed by GitHub
parent 8cde2e805b
commit 6b9447e3a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -22,6 +22,7 @@ from homeassistant.components.vacuum import (
StateVacuumEntity,
VacuumEntity,
)
from homeassistant.helpers import event
SUPPORT_MINIMAL_SERVICES = SUPPORT_TURN_ON | SUPPORT_TURN_OFF
@ -328,7 +329,7 @@ class StateDemoVacuum(StateVacuumEntity):
self._state = STATE_RETURNING
self.schedule_update_ha_state()
self.hass.loop.call_later(30, self.__set_state_to_dock)
event.call_later(self.hass, 30, self.__set_state_to_dock)
def clean_spot(self, **kwargs):
"""Perform a spot clean-up."""
@ -349,6 +350,6 @@ class StateDemoVacuum(StateVacuumEntity):
self._fan_speed = fan_speed
self.schedule_update_ha_state()
def __set_state_to_dock(self):
def __set_state_to_dock(self, _):
self._state = STATE_DOCKED
self.schedule_update_ha_state()

View File

@ -1,4 +1,6 @@
"""The tests for the Demo vacuum platform."""
from datetime import timedelta
import pytest
from homeassistant.components import vacuum
@ -35,8 +37,9 @@ from homeassistant.const import (
STATE_ON,
)
from homeassistant.setup import async_setup_component
from homeassistant.util import dt
from tests.common import async_mock_service
from tests.common import async_fire_time_changed, async_mock_service
from tests.components.vacuum import common
ENTITY_VACUUM_BASIC = f"{DOMAIN}.{DEMO_VACUUM_BASIC}".lower()
@ -175,6 +178,11 @@ async def test_methods(hass):
state = hass.states.get(ENTITY_VACUUM_STATE)
assert state.state == STATE_RETURNING
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=31))
await hass.async_block_till_done()
state = hass.states.get(ENTITY_VACUUM_STATE)
assert state.state == STATE_DOCKED
await common.async_set_fan_speed(
hass, FAN_SPEEDS[-1], entity_id=ENTITY_VACUUM_STATE
)