Roomba timeout (#12645)

* Roomba timeout

* PlatformNotReady
pull/12687/head
Johann Kellerman 2018-02-26 09:43:26 +02:00 committed by Paulus Schoutsen
parent e96ac74b11
commit 6d5fb49687
1 changed files with 10 additions and 1 deletions

View File

@ -8,12 +8,15 @@ import asyncio
import logging
import voluptuous as vol
import async_timeout
from homeassistant.components.vacuum import (
VacuumDevice, PLATFORM_SCHEMA, SUPPORT_BATTERY, SUPPORT_FAN_SPEED,
SUPPORT_PAUSE, SUPPORT_RETURN_HOME, SUPPORT_SEND_COMMAND, SUPPORT_STATUS,
SUPPORT_STOP, SUPPORT_TURN_OFF, SUPPORT_TURN_ON)
from homeassistant.const import (
CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME)
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
@ -90,7 +93,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
)
_LOGGER.info("Initializing communication with host %s (username: %s)",
host, username)
yield from hass.async_add_job(roomba.connect)
try:
with async_timeout.timeout(9):
yield from hass.async_add_job(roomba.connect)
except asyncio.TimeoutError:
raise PlatformNotReady
roomba_vac = RoombaVacuum(name, roomba)
hass.data[PLATFORM][host] = roomba_vac