Async syntax 3/8 (#17017)

* Async syntax 3, device_tracker & fan & hassio & image_processing & input

* Pylint fixes
This commit is contained in:
cdce8p 2018-10-01 08:59:45 +02:00 committed by Paulus Schoutsen
parent 134eeecd65
commit b24f9f5dfa
23 changed files with 194 additions and 286 deletions

View file

@ -4,7 +4,6 @@ Component to offer a way to enter a value into a text box.
For more details about this component, please refer to the documentation
at https://home-assistant.io/components/input_text/
"""
import asyncio
import logging
import voluptuous as vol
@ -73,8 +72,7 @@ CONFIG_SCHEMA = vol.Schema({
}, required=True, extra=vol.ALLOW_EXTRA)
@asyncio.coroutine
def async_setup(hass, config):
async def async_setup(hass, config):
"""Set up an input text box."""
component = EntityComponent(_LOGGER, DOMAIN, hass)
@ -102,7 +100,7 @@ def async_setup(hass, config):
'async_set_value'
)
yield from component.async_add_entities(entities)
await component.async_add_entities(entities)
return True
@ -157,25 +155,23 @@ class InputText(Entity):
ATTR_MODE: self._mode,
}
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Run when entity about to be added to hass."""
if self._current_value is not None:
return
state = yield from async_get_last_state(self.hass, self.entity_id)
state = await async_get_last_state(self.hass, self.entity_id)
value = state and state.state
# Check against None because value can be 0
if value is not None and self._minimum <= len(value) <= self._maximum:
self._current_value = value
@asyncio.coroutine
def async_set_value(self, value):
async def async_set_value(self, value):
"""Select new value."""
if len(value) < self._minimum or len(value) > self._maximum:
_LOGGER.warning("Invalid value: %s (length range %s - %s)",
value, self._minimum, self._maximum)
return
self._current_value = value
yield from self.async_update_ha_state()
await self.async_update_ha_state()