Async syntax 3/8 (#17017)
* Async syntax 3, device_tracker & fan & hassio & image_processing & input * Pylint fixes
This commit is contained in:
1 parent
134eeecd65
commit
b24f9f5dfa
23 files changed
+194
-286
No files matched your search
@@ -4,7 +4,6 @@ Component to offer a way to select an option from a list.
|
||||
For more details about this component, please refer to the documentation
|
||||
at https://home-assistant.io/components/input_select/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
@@ -77,8 +76,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 select."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
||||
@@ -114,7 +112,7 @@ def async_setup(hass, config):
|
||||
'async_set_options'
|
||||
)
|
||||
|
||||
yield from component.async_add_entities(entities)
|
||||
await component.async_add_entities(entities)
|
||||
return True
|
||||
|
||||
|
||||
@@ -129,13 +127,12 @@ class InputSelect(Entity):
|
||||
self._options = options
|
||||
self._icon = icon
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Run when entity about to be added."""
|
||||
if self._current_option 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)
|
||||
if not state or state.state not in self._options:
|
||||
self._current_option = self._options[0]
|
||||
else:
|
||||
@@ -168,27 +165,24 @@ class InputSelect(Entity):
|
||||
ATTR_OPTIONS: self._options,
|
||||
}
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_select_option(self, option):
|
||||
async def async_select_option(self, option):
|
||||
"""Select new option."""
|
||||
if option not in self._options:
|
||||
_LOGGER.warning('Invalid option: %s (possible options: %s)',
|
||||
option, ', '.join(self._options))
|
||||
return
|
||||
self._current_option = option
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_offset_index(self, offset):
|
||||
async def async_offset_index(self, offset):
|
||||
"""Offset current index."""
|
||||
current_index = self._options.index(self._current_option)
|
||||
new_index = (current_index + offset) % len(self._options)
|
||||
self._current_option = self._options[new_index]
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_set_options(self, options):
|
||||
async def async_set_options(self, options):
|
||||
"""Set options."""
|
||||
self._current_option = options[0]
|
||||
self._options = options
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
Reference in new issue
Block a user