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') _LOGGER.error('No sensors added')
return False return False
hass.loop.create_task(async_add_devices(sensors, True)) yield from async_add_devices(sensors, True)
return True return True
@ -84,7 +84,7 @@ class BinarySensorTemplate(BinarySensorDevice):
@callback @callback
def template_bsensor_state_listener(entity, old_state, new_state): def template_bsensor_state_listener(entity, old_state, new_state):
"""Called when the target device changes 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( async_track_state_change(
hass, entity_ids, template_bsensor_state_listener) 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) name = config.get(CONF_NAME)
sensor_type = config.get(CONF_TYPE) sensor_type = config.get(CONF_TYPE)
hass.loop.create_task(async_add_devices( yield from async_add_devices(
[MinMaxSensor(hass, entity_ids, name, sensor_type)], True)) [MinMaxSensor(hass, entity_ids, name, sensor_type)], True)
return True return True
@ -100,7 +100,7 @@ class MinMaxSensor(Entity):
_LOGGER.warning("Unable to store state. " _LOGGER.warning("Unable to store state. "
"Only numerical states are supported") "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( async_track_state_change(
hass, entity_ids, async_min_max_sensor_state_listener) 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) minimum = config.get(CONF_MINIMUM)
maximum = config.get(CONF_MAXIMUM) maximum = config.get(CONF_MAXIMUM)
hass.loop.create_task(async_add_devices( yield from async_add_devices([RandomSensor(name, minimum, maximum)], True)
[RandomSensor(name, minimum, maximum)], True))
return 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) name = config.get(CONF_NAME)
sampling_size = config.get(CONF_SAMPLING_SIZE) sampling_size = config.get(CONF_SAMPLING_SIZE)
hass.loop.create_task(async_add_devices( yield from async_add_devices(
[StatisticsSensor(hass, entity_id, name, sampling_size)], True)) [StatisticsSensor(hass, entity_id, name, sampling_size)], True)
return True return True
@ -90,7 +90,7 @@ class StatisticsSensor(Entity):
except ValueError: except ValueError:
self.count = self.count + 1 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( async_track_state_change(
hass, entity_id, async_stats_sensor_state_listener) 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") _LOGGER.error("No sensors added")
return False return False
hass.loop.create_task(async_add_devices(sensors, True)) yield from async_add_devices(sensors, True)
return True return True
@ -82,7 +82,7 @@ class SensorTemplate(Entity):
@callback @callback
def template_sensor_state_listener(entity, old_state, new_state): def template_sensor_state_listener(entity, old_state, new_state):
"""Called when the target device changes 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( async_track_state_change(
hass, entity_ids, template_sensor_state_listener) 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]: for variable in config[CONF_DISPLAY_OPTIONS]:
devices.append(TimeDateSensor(variable)) devices.append(TimeDateSensor(variable))
hass.loop.create_task(async_add_devices(devices, True)) yield from async_add_devices(devices, True)
return 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) name = config.get(CONF_NAME)
time_zone = dt_util.get_time_zone(config.get(CONF_TIME_ZONE)) time_zone = dt_util.get_time_zone(config.get(CONF_TIME_ZONE))
hass.loop.create_task(async_add_devices( yield from async_add_devices([WorldClockSensor(time_zone, name)], True)
[WorldClockSensor(time_zone, name)], True))
return 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") _LOGGER.error("No switches added")
return False return False
hass.loop.create_task(async_add_devices(switches, True)) yield from async_add_devices(switches, True)
return True return True
@ -92,7 +92,7 @@ class SwitchTemplate(SwitchDevice):
@callback @callback
def template_switch_state_listener(entity, old_state, new_state): def template_switch_state_listener(entity, old_state, new_state):
"""Called when the target device changes 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( async_track_state_change(
hass, entity_ids, template_switch_state_listener) hass, entity_ids, template_switch_state_listener)