Async cleanups with new handling and executor (#4234)

This commit is contained in:
Pascal Vizeli 2016-11-06 01:01:03 +01:00 committed by GitHub
parent ad8645baf4
commit 382ac5c3b5
8 changed files with 15 additions and 17 deletions

View File

@ -63,7 +63,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
_LOGGER.error('No sensors added')
return False
hass.loop.create_task(async_add_devices(sensors, True))
yield from async_add_devices(sensors, True)
return True
@ -84,7 +84,7 @@ class BinarySensorTemplate(BinarySensorDevice):
@callback
def template_bsensor_state_listener(entity, old_state, new_state):
"""Called when the target device changes state."""
hass.loop.create_task(self.async_update_ha_state(True))
hass.async_add_job(self.async_update_ha_state, True)
async_track_state_change(
hass, entity_ids, template_bsensor_state_listener)

View File

@ -58,8 +58,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
name = config.get(CONF_NAME)
sensor_type = config.get(CONF_TYPE)
hass.loop.create_task(async_add_devices(
[MinMaxSensor(hass, entity_ids, name, sensor_type)], True))
yield from async_add_devices(
[MinMaxSensor(hass, entity_ids, name, sensor_type)], True)
return True
@ -100,7 +100,7 @@ class MinMaxSensor(Entity):
_LOGGER.warning("Unable to store state. "
"Only numerical states are supported")
hass.loop.create_task(self.async_update_ha_state(True))
hass.async_add_job(self.async_update_ha_state, True)
async_track_state_change(
hass, entity_ids, async_min_max_sensor_state_listener)

View File

@ -36,8 +36,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
minimum = config.get(CONF_MINIMUM)
maximum = config.get(CONF_MAXIMUM)
hass.loop.create_task(async_add_devices(
[RandomSensor(name, minimum, maximum)], True))
yield from async_add_devices([RandomSensor(name, minimum, maximum)], True)
return True

View File

@ -50,8 +50,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
name = config.get(CONF_NAME)
sampling_size = config.get(CONF_SAMPLING_SIZE)
hass.loop.create_task(async_add_devices(
[StatisticsSensor(hass, entity_id, name, sampling_size)], True))
yield from async_add_devices(
[StatisticsSensor(hass, entity_id, name, sampling_size)], True)
return True
@ -90,7 +90,7 @@ class StatisticsSensor(Entity):
except ValueError:
self.count = self.count + 1
hass.loop.create_task(self.async_update_ha_state(True))
hass.async_add_job(self.async_update_ha_state, True)
async_track_state_change(
hass, entity_id, async_stats_sensor_state_listener)

View File

@ -61,7 +61,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
_LOGGER.error("No sensors added")
return False
hass.loop.create_task(async_add_devices(sensors, True))
yield from async_add_devices(sensors, True)
return True
@ -82,7 +82,7 @@ class SensorTemplate(Entity):
@callback
def template_sensor_state_listener(entity, old_state, new_state):
"""Called when the target device changes state."""
hass.loop.create_task(self.async_update_ha_state(True))
hass.async_add_job(self.async_update_ha_state, True)
async_track_state_change(
hass, entity_ids, template_sensor_state_listener)

View File

@ -46,7 +46,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
for variable in config[CONF_DISPLAY_OPTIONS]:
devices.append(TimeDateSensor(variable))
hass.loop.create_task(async_add_devices(devices, True))
yield from async_add_devices(devices, True)
return True

View File

@ -35,8 +35,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
name = config.get(CONF_NAME)
time_zone = dt_util.get_time_zone(config.get(CONF_TIME_ZONE))
hass.loop.create_task(async_add_devices(
[WorldClockSensor(time_zone, name)], True))
yield from async_add_devices([WorldClockSensor(time_zone, name)], True)
return True

View File

@ -70,7 +70,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
_LOGGER.error("No switches added")
return False
hass.loop.create_task(async_add_devices(switches, True))
yield from async_add_devices(switches, True)
return True
@ -92,7 +92,7 @@ class SwitchTemplate(SwitchDevice):
@callback
def template_switch_state_listener(entity, old_state, new_state):
"""Called when the target device changes state."""
hass.loop.create_task(self.async_update_ha_state(True))
hass.async_add_job(self.async_update_ha_state, True)
async_track_state_change(
hass, entity_ids, template_switch_state_listener)