Fix lifx light async error (#22031)

This commit is contained in:
Jason Hu 2019-03-14 09:10:36 -07:00 committed by Anders Melchiorsen
parent 300384410f
commit e480f75d6d

View File

@ -24,7 +24,7 @@ from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.event import async_track_point_in_utc_time from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.helpers.service import extract_entity_ids from homeassistant.helpers.service import async_extract_entity_ids
import homeassistant.util.color as color_util import homeassistant.util.color as color_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -250,7 +250,7 @@ class LIFXManager:
async def service_handler(service): async def service_handler(service):
"""Apply a service.""" """Apply a service."""
tasks = [] tasks = []
for light in self.service_to_entities(service): for light in await self.async_service_to_entities(service):
if service.service == SERVICE_LIFX_SET_STATE: if service.service == SERVICE_LIFX_SET_STATE:
task = light.set_state(**service.data) task = light.set_state(**service.data)
tasks.append(self.hass.async_create_task(task)) tasks.append(self.hass.async_create_task(task))
@ -265,7 +265,7 @@ class LIFXManager:
"""Register the LIFX effects as hass service calls.""" """Register the LIFX effects as hass service calls."""
async def service_handler(service): async def service_handler(service):
"""Apply a service, i.e. start an effect.""" """Apply a service, i.e. start an effect."""
entities = self.service_to_entities(service) entities = await self.async_service_to_entities(service)
if entities: if entities:
await self.start_effect( await self.start_effect(
entities, service.service, **service.data) entities, service.service, **service.data)
@ -314,9 +314,9 @@ class LIFXManager:
elif service == SERVICE_EFFECT_STOP: elif service == SERVICE_EFFECT_STOP:
await self.effects_conductor.stop(bulbs) await self.effects_conductor.stop(bulbs)
def service_to_entities(self, service): async def async_service_to_entities(self, service):
"""Return the known entities that a service call mentions.""" """Return the known entities that a service call mentions."""
entity_ids = extract_entity_ids(self.hass, service) entity_ids = await async_extract_entity_ids(self.hass, service)
if entity_ids: if entity_ids:
entities = [entity for entity in self.entities.values() entities = [entity for entity in self.entities.values()
if entity.entity_id in entity_ids] if entity.entity_id in entity_ids]