Switch components.sensor.zha to await syntax. (#16619)

This commit is contained in:
Alexei Chetroi 2018-09-14 15:29:10 -04:00 committed by Aaron Bach
parent 7705666061
commit 0d0bda9658

View File

@ -4,7 +4,6 @@ Sensors on Zigbee Home Automation networks.
For more details on this platform, please refer to the documentation For more details on this platform, please refer to the documentation
at https://home-assistant.io/components/sensor.zha/ at https://home-assistant.io/components/sensor.zha/
""" """
import asyncio
import logging import logging
from homeassistant.components.sensor import DOMAIN from homeassistant.components.sensor import DOMAIN
@ -17,20 +16,18 @@ _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['zha'] DEPENDENCIES = ['zha']
@asyncio.coroutine async def async_setup_platform(hass, config, async_add_entities,
def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
discovery_info=None):
"""Set up Zigbee Home Automation sensors.""" """Set up Zigbee Home Automation sensors."""
discovery_info = zha.get_discovery_info(hass, discovery_info) discovery_info = zha.get_discovery_info(hass, discovery_info)
if discovery_info is None: if discovery_info is None:
return return
sensor = yield from make_sensor(discovery_info) sensor = await make_sensor(discovery_info)
async_add_entities([sensor], update_before_add=True) async_add_entities([sensor], update_before_add=True)
@asyncio.coroutine async def make_sensor(discovery_info):
def make_sensor(discovery_info):
"""Create ZHA sensors factory.""" """Create ZHA sensors factory."""
from zigpy.zcl.clusters.measurement import ( from zigpy.zcl.clusters.measurement import (
RelativeHumidity, TemperatureMeasurement, PressureMeasurement, RelativeHumidity, TemperatureMeasurement, PressureMeasurement,
@ -57,7 +54,7 @@ def make_sensor(discovery_info):
if discovery_info['new_join']: if discovery_info['new_join']:
cluster = list(in_clusters.values())[0] cluster = list(in_clusters.values())[0]
yield from zha.configure_reporting( await zha.configure_reporting(
sensor.entity_id, cluster, sensor.value_attribute, sensor.entity_id, cluster, sensor.value_attribute,
reportable_change=sensor.min_reportable_change reportable_change=sensor.min_reportable_change
) )