mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Async cleanups with new handling and executor (#4234)
This commit is contained in:
parent
ad8645baf4
commit
382ac5c3b5
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user