Remove usage of async_add_job in tests (#113259)
This commit is contained in:
parent
c3b5e819c5
commit
c1f5c7c4b7
11 changed files with 22 additions and 22 deletions
|
@ -342,6 +342,6 @@ async def test_done_message_state_tracker_reset_on_cancel(hass: HomeAssistant) -
|
||||||
entity._cancel = lambda *args: None
|
entity._cancel = lambda *args: None
|
||||||
assert entity._send_done_message is False
|
assert entity._send_done_message is False
|
||||||
entity._send_done_message = True
|
entity._send_done_message = True
|
||||||
hass.async_add_job(entity.end_alerting)
|
await entity.end_alerting()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert entity._send_done_message is False
|
assert entity._send_done_message is False
|
||||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.loader import bind_hass
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_increment(hass, entity_id):
|
def async_increment(hass, entity_id):
|
||||||
"""Increment a counter."""
|
"""Increment a counter."""
|
||||||
hass.async_add_job(
|
hass.create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_INCREMENT, {ATTR_ENTITY_ID: entity_id})
|
hass.services.async_call(DOMAIN, SERVICE_INCREMENT, {ATTR_ENTITY_ID: entity_id})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ def async_increment(hass, entity_id):
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_decrement(hass, entity_id):
|
def async_decrement(hass, entity_id):
|
||||||
"""Decrement a counter."""
|
"""Decrement a counter."""
|
||||||
hass.async_add_job(
|
hass.create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_DECREMENT, {ATTR_ENTITY_ID: entity_id})
|
hass.services.async_call(DOMAIN, SERVICE_DECREMENT, {ATTR_ENTITY_ID: entity_id})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,6 +37,6 @@ def async_decrement(hass, entity_id):
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_reset(hass, entity_id):
|
def async_reset(hass, entity_id):
|
||||||
"""Reset a counter."""
|
"""Reset a counter."""
|
||||||
hass.async_add_job(
|
hass.create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_RESET, {ATTR_ENTITY_ID: entity_id})
|
hass.services.async_call(DOMAIN, SERVICE_RESET, {ATTR_ENTITY_ID: entity_id})
|
||||||
)
|
)
|
||||||
|
|
|
@ -50,4 +50,4 @@ def async_see(
|
||||||
}
|
}
|
||||||
if attributes:
|
if attributes:
|
||||||
data[ATTR_ATTRIBUTES] = attributes
|
data[ATTR_ATTRIBUTES] = attributes
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SEE, data))
|
hass.create_task(hass.services.async_call(DOMAIN, SERVICE_SEE, data))
|
||||||
|
|
|
@ -65,7 +65,7 @@ async def test_noise_setup_component_start_callback(mock_ffmpeg, hass: HomeAssis
|
||||||
entity = hass.states.get("binary_sensor.ffmpeg_noise")
|
entity = hass.states.get("binary_sensor.ffmpeg_noise")
|
||||||
assert entity.state == "off"
|
assert entity.state == "off"
|
||||||
|
|
||||||
hass.async_add_job(mock_ffmpeg.call_args[0][1], True)
|
mock_ffmpeg.call_args[0][1](True)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity = hass.states.get("binary_sensor.ffmpeg_noise")
|
entity = hass.states.get("binary_sensor.ffmpeg_noise")
|
||||||
|
@ -121,7 +121,7 @@ async def test_motion_setup_component_start_callback(mock_ffmpeg, hass: HomeAssi
|
||||||
entity = hass.states.get("binary_sensor.ffmpeg_motion")
|
entity = hass.states.get("binary_sensor.ffmpeg_motion")
|
||||||
assert entity.state == "off"
|
assert entity.state == "off"
|
||||||
|
|
||||||
hass.async_add_job(mock_ffmpeg.call_args[0][1], True)
|
mock_ffmpeg.call_args[0][1](True)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity = hass.states.get("binary_sensor.ffmpeg_motion")
|
entity = hass.states.get("binary_sensor.ffmpeg_motion")
|
||||||
|
|
|
@ -27,7 +27,7 @@ def async_start(hass, entity_id=None):
|
||||||
This is a legacy helper method. Do not use it for new tests.
|
This is a legacy helper method. Do not use it for new tests.
|
||||||
"""
|
"""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_START, data))
|
hass.create_task(hass.services.async_call(DOMAIN, SERVICE_START, data))
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -37,7 +37,7 @@ def async_stop(hass, entity_id=None):
|
||||||
This is a legacy helper method. Do not use it for new tests.
|
This is a legacy helper method. Do not use it for new tests.
|
||||||
"""
|
"""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_STOP, data))
|
hass.create_task(hass.services.async_call(DOMAIN, SERVICE_STOP, data))
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -47,7 +47,7 @@ def async_restart(hass, entity_id=None):
|
||||||
This is a legacy helper method. Do not use it for new tests.
|
This is a legacy helper method. Do not use it for new tests.
|
||||||
"""
|
"""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RESTART, data))
|
hass.create_task(hass.services.async_call(DOMAIN, SERVICE_RESTART, data))
|
||||||
|
|
||||||
|
|
||||||
class MockFFmpegDev(ffmpeg.FFmpegBase):
|
class MockFFmpegDev(ffmpeg.FFmpegBase):
|
||||||
|
|
|
@ -27,7 +27,7 @@ def reload(hass):
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_reload(hass):
|
def async_reload(hass):
|
||||||
"""Reload the automation from config."""
|
"""Reload the automation from config."""
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RELOAD))
|
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_RELOAD))
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
|
@ -74,7 +74,7 @@ def async_set_group(
|
||||||
if value is not None
|
if value is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SET, data))
|
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SET, data))
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -82,4 +82,4 @@ def async_set_group(
|
||||||
def async_remove(hass, object_id):
|
def async_remove(hass, object_id):
|
||||||
"""Remove a user group."""
|
"""Remove a user group."""
|
||||||
data = {ATTR_OBJECT_ID: object_id}
|
data = {ATTR_OBJECT_ID: object_id}
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_REMOVE, data))
|
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_REMOVE, data))
|
||||||
|
|
|
@ -1232,6 +1232,8 @@ async def test_group_vacuum_on(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
async def test_device_tracker_not_home(hass: HomeAssistant) -> None:
|
async def test_device_tracker_not_home(hass: HomeAssistant) -> None:
|
||||||
"""Test group of device_tracker not_home."""
|
"""Test group of device_tracker not_home."""
|
||||||
|
await async_setup_component(hass, "device_tracker", {})
|
||||||
|
await hass.async_block_till_done()
|
||||||
hass.states.async_set("device_tracker.one", "not_home")
|
hass.states.async_set("device_tracker.one", "not_home")
|
||||||
hass.states.async_set("device_tracker.two", "not_home")
|
hass.states.async_set("device_tracker.two", "not_home")
|
||||||
hass.states.async_set("device_tracker.three", "not_home")
|
hass.states.async_set("device_tracker.three", "not_home")
|
||||||
|
|
|
@ -101,7 +101,7 @@ async def test_hap_setup_connection_error() -> None:
|
||||||
):
|
):
|
||||||
assert not await hap.async_setup()
|
assert not await hap.async_setup()
|
||||||
|
|
||||||
assert not hass.async_add_job.mock_calls
|
assert not hass.async_add_hass_job.mock_calls
|
||||||
assert not hass.config_entries.flow.async_init.mock_calls
|
assert not hass.config_entries.flow.async_init.mock_calls
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,4 +21,4 @@ def scan(hass, entity_id=ENTITY_MATCH_ALL):
|
||||||
def async_scan(hass, entity_id=ENTITY_MATCH_ALL):
|
def async_scan(hass, entity_id=ENTITY_MATCH_ALL):
|
||||||
"""Force process of all cameras or given entity."""
|
"""Force process of all cameras or given entity."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SCAN, data))
|
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SCAN, data))
|
||||||
|
|
|
@ -159,10 +159,8 @@ async def test_waiting_for_client_not_loaded(
|
||||||
unsubs.append(await mqtt.async_subscribe(hass, "test_topic", lambda msg: None))
|
unsubs.append(await mqtt.async_subscribe(hass, "test_topic", lambda msg: None))
|
||||||
|
|
||||||
# Simulate some integration waiting for the client to become available
|
# Simulate some integration waiting for the client to become available
|
||||||
hass.async_add_job(_async_just_in_time_subscribe)
|
for _ in range(4):
|
||||||
hass.async_add_job(_async_just_in_time_subscribe)
|
hass.async_create_task(_async_just_in_time_subscribe())
|
||||||
hass.async_add_job(_async_just_in_time_subscribe)
|
|
||||||
hass.async_add_job(_async_just_in_time_subscribe)
|
|
||||||
|
|
||||||
assert entry.state == ConfigEntryState.NOT_LOADED
|
assert entry.state == ConfigEntryState.NOT_LOADED
|
||||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
@ -210,7 +208,7 @@ async def test_waiting_for_client_entry_fails(
|
||||||
async def _async_just_in_time_subscribe() -> Callable[[], None]:
|
async def _async_just_in_time_subscribe() -> Callable[[], None]:
|
||||||
assert not await mqtt.async_wait_for_mqtt_client(hass)
|
assert not await mqtt.async_wait_for_mqtt_client(hass)
|
||||||
|
|
||||||
hass.async_add_job(_async_just_in_time_subscribe)
|
hass.async_create_task(_async_just_in_time_subscribe())
|
||||||
assert entry.state == ConfigEntryState.NOT_LOADED
|
assert entry.state == ConfigEntryState.NOT_LOADED
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.mqtt.async_setup_entry",
|
"homeassistant.components.mqtt.async_setup_entry",
|
||||||
|
@ -238,7 +236,7 @@ async def test_waiting_for_client_setup_fails(
|
||||||
async def _async_just_in_time_subscribe() -> Callable[[], None]:
|
async def _async_just_in_time_subscribe() -> Callable[[], None]:
|
||||||
assert not await mqtt.async_wait_for_mqtt_client(hass)
|
assert not await mqtt.async_wait_for_mqtt_client(hass)
|
||||||
|
|
||||||
hass.async_add_job(_async_just_in_time_subscribe)
|
hass.async_create_task(_async_just_in_time_subscribe())
|
||||||
assert entry.state == ConfigEntryState.NOT_LOADED
|
assert entry.state == ConfigEntryState.NOT_LOADED
|
||||||
|
|
||||||
# Simulate MQTT setup fails before the client would become available
|
# Simulate MQTT setup fails before the client would become available
|
||||||
|
|
|
@ -250,7 +250,7 @@ for index, value in enumerate(["earth", "mars"]):
|
||||||
hass.states.set('hello.{}'.format(index), value)
|
hass.states.set('hello.{}'.format(index), value)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
await hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state("hello.0", "earth")
|
assert hass.states.is_state("hello.0", "earth")
|
||||||
|
|
Loading…
Add table
Reference in a new issue