mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Update litejet and zwave tests to use async_add_executor_job (#41927)
* Update litejet and zwave tests to use async_add_executor_job * await
This commit is contained in:
parent
0a192947ed
commit
6f113e981b
@ -73,7 +73,7 @@ async def simulate_press(hass, mock_lj, number):
|
|||||||
return_value=mock_lj.start_time + mock_lj.last_delta,
|
return_value=mock_lj.start_time + mock_lj.last_delta,
|
||||||
):
|
):
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
await hass.async_add_job(callback)
|
await hass.async_add_executor_job(callback)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ async def simulate_release(hass, mock_lj, number):
|
|||||||
return_value=mock_lj.start_time + mock_lj.last_delta,
|
return_value=mock_lj.start_time + mock_lj.last_delta,
|
||||||
):
|
):
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
await hass.async_add_job(callback)
|
await hass.async_add_executor_job(callback)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,13 +80,13 @@ async def test_trigger_sensor_value_changed(hass, mock_openzwave):
|
|||||||
assert not device.is_on
|
assert not device.is_on
|
||||||
|
|
||||||
value.data = True
|
value.data = True
|
||||||
await hass.async_add_job(value_changed, value)
|
await hass.async_add_executor_job(value_changed, value)
|
||||||
assert device.invalidate_after is None
|
assert device.invalidate_after is None
|
||||||
|
|
||||||
device.hass = hass
|
device.hass = hass
|
||||||
|
|
||||||
value.data = True
|
value.data = True
|
||||||
await hass.async_add_job(value_changed, value)
|
await hass.async_add_executor_job(value_changed, value)
|
||||||
assert device.is_on
|
assert device.is_on
|
||||||
|
|
||||||
test_time = device.invalidate_after - datetime.timedelta(seconds=1)
|
test_time = device.invalidate_after - datetime.timedelta(seconds=1)
|
||||||
|
@ -298,7 +298,7 @@ async def test_node_discovery(hass, mock_openzwave):
|
|||||||
assert len(mock_receivers) == 1
|
assert len(mock_receivers) == 1
|
||||||
|
|
||||||
node = MockNode(node_id=14)
|
node = MockNode(node_id=14)
|
||||||
hass.async_add_job(mock_receivers[0], node)
|
await hass.async_add_executor_job(mock_receivers[0], node)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("zwave.mock_node").state == "unknown"
|
assert hass.states.get("zwave.mock_node").state == "unknown"
|
||||||
@ -335,7 +335,7 @@ async def test_unparsed_node_discovery(hass, mock_openzwave):
|
|||||||
with patch("homeassistant.components.zwave.dt_util.utcnow", new=utcnow):
|
with patch("homeassistant.components.zwave.dt_util.utcnow", new=utcnow):
|
||||||
with patch("asyncio.sleep", new=sleep):
|
with patch("asyncio.sleep", new=sleep):
|
||||||
with patch.object(zwave, "_LOGGER") as mock_logger:
|
with patch.object(zwave, "_LOGGER") as mock_logger:
|
||||||
hass.async_add_job(mock_receivers[0], node)
|
await hass.async_add_executor_job(mock_receivers[0], node)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(sleeps) == const.NODE_READY_WAIT_SECS
|
assert len(sleeps) == const.NODE_READY_WAIT_SECS
|
||||||
@ -367,7 +367,7 @@ async def test_node_ignored(hass, mock_openzwave):
|
|||||||
assert len(mock_receivers) == 1
|
assert len(mock_receivers) == 1
|
||||||
|
|
||||||
node = MockNode(node_id=14)
|
node = MockNode(node_id=14)
|
||||||
hass.async_add_job(mock_receivers[0], node)
|
await hass.async_add_executor_job(mock_receivers[0], node)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("zwave.mock_node") is None
|
assert hass.states.get("zwave.mock_node") is None
|
||||||
@ -397,7 +397,7 @@ async def test_value_discovery(hass, mock_openzwave):
|
|||||||
type=const.TYPE_BOOL,
|
type=const.TYPE_BOOL,
|
||||||
genre=const.GENRE_USER,
|
genre=const.GENRE_USER,
|
||||||
)
|
)
|
||||||
hass.async_add_job(mock_receivers[0], node, value)
|
await hass.async_add_executor_job(mock_receivers[0], node, value)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("binary_sensor.mock_node_mock_value").state == "off"
|
assert hass.states.get("binary_sensor.mock_node_mock_value").state == "off"
|
||||||
@ -421,7 +421,9 @@ async def test_value_entities(hass, mock_openzwave):
|
|||||||
|
|
||||||
assert mock_receivers
|
assert mock_receivers
|
||||||
|
|
||||||
hass.async_add_job(mock_receivers[MockNetwork.SIGNAL_ALL_NODES_QUERIED])
|
await hass.async_add_executor_job(
|
||||||
|
mock_receivers[MockNetwork.SIGNAL_ALL_NODES_QUERIED]
|
||||||
|
)
|
||||||
node = MockNode(node_id=11, generic=const.GENERIC_TYPE_SENSOR_BINARY)
|
node = MockNode(node_id=11, generic=const.GENERIC_TYPE_SENSOR_BINARY)
|
||||||
zwave_network.nodes = {node.node_id: node}
|
zwave_network.nodes = {node.node_id: node}
|
||||||
value = MockValue(
|
value = MockValue(
|
||||||
@ -446,9 +448,15 @@ async def test_value_entities(hass, mock_openzwave):
|
|||||||
)
|
)
|
||||||
node.values[value2.value_id] = value2
|
node.values[value2.value_id] = value2
|
||||||
|
|
||||||
hass.async_add_job(mock_receivers[MockNetwork.SIGNAL_NODE_ADDED], node)
|
await hass.async_add_executor_job(
|
||||||
hass.async_add_job(mock_receivers[MockNetwork.SIGNAL_VALUE_ADDED], node, value)
|
mock_receivers[MockNetwork.SIGNAL_NODE_ADDED], node
|
||||||
hass.async_add_job(mock_receivers[MockNetwork.SIGNAL_VALUE_ADDED], node, value2)
|
)
|
||||||
|
await hass.async_add_executor_job(
|
||||||
|
mock_receivers[MockNetwork.SIGNAL_VALUE_ADDED], node, value
|
||||||
|
)
|
||||||
|
await hass.async_add_executor_job(
|
||||||
|
mock_receivers[MockNetwork.SIGNAL_VALUE_ADDED], node, value2
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("binary_sensor.mock_node_mock_value").state == "off"
|
assert hass.states.get("binary_sensor.mock_node_mock_value").state == "off"
|
||||||
@ -594,7 +602,7 @@ async def test_value_discovery_existing_entity(hass, mock_openzwave):
|
|||||||
genre=const.GENRE_USER,
|
genre=const.GENRE_USER,
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.async_add_job(mock_receivers[0], node, thermostat_mode)
|
await hass.async_add_executor_job(mock_receivers[0], node, thermostat_mode)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
def mock_update(self):
|
def mock_update(self):
|
||||||
@ -603,7 +611,7 @@ async def test_value_discovery_existing_entity(hass, mock_openzwave):
|
|||||||
with patch.object(
|
with patch.object(
|
||||||
zwave.node_entity.ZWaveBaseEntity, "maybe_schedule_update", new=mock_update
|
zwave.node_entity.ZWaveBaseEntity, "maybe_schedule_update", new=mock_update
|
||||||
):
|
):
|
||||||
hass.async_add_job(mock_receivers[0], node, setpoint_heating)
|
await hass.async_add_executor_job(mock_receivers[0], node, setpoint_heating)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -628,7 +636,7 @@ async def test_value_discovery_existing_entity(hass, mock_openzwave):
|
|||||||
genre=const.GENRE_USER,
|
genre=const.GENRE_USER,
|
||||||
units="C",
|
units="C",
|
||||||
)
|
)
|
||||||
hass.async_add_job(mock_receivers[0], node, temperature)
|
await hass.async_add_executor_job(mock_receivers[0], node, temperature)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -670,7 +678,7 @@ async def test_value_discovery_legacy_thermostat(hass, mock_openzwave):
|
|||||||
genre=const.GENRE_USER,
|
genre=const.GENRE_USER,
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.async_add_job(mock_receivers[0], node, setpoint_heating)
|
await hass.async_add_executor_job(mock_receivers[0], node, setpoint_heating)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -703,7 +711,7 @@ async def test_power_schemes(hass, mock_openzwave):
|
|||||||
genre=const.GENRE_USER,
|
genre=const.GENRE_USER,
|
||||||
type=const.TYPE_BOOL,
|
type=const.TYPE_BOOL,
|
||||||
)
|
)
|
||||||
await hass.async_add_job(mock_receivers[0], node, switch)
|
await hass.async_add_executor_job(mock_receivers[0], node, switch)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -727,7 +735,7 @@ async def test_power_schemes(hass, mock_openzwave):
|
|||||||
command_class=const.COMMAND_CLASS_SENSOR_MULTILEVEL,
|
command_class=const.COMMAND_CLASS_SENSOR_MULTILEVEL,
|
||||||
genre=const.GENRE_USER, # to avoid exception
|
genre=const.GENRE_USER, # to avoid exception
|
||||||
)
|
)
|
||||||
await hass.async_add_job(mock_receivers[0], node, power)
|
await hass.async_add_executor_job(mock_receivers[0], node, power)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -757,7 +765,7 @@ async def test_network_ready(hass, mock_openzwave):
|
|||||||
|
|
||||||
hass.bus.async_listen(const.EVENT_NETWORK_COMPLETE, listener)
|
hass.bus.async_listen(const.EVENT_NETWORK_COMPLETE, listener)
|
||||||
|
|
||||||
hass.async_add_job(mock_receivers[0])
|
await hass.async_add_executor_job(mock_receivers[0])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
@ -784,7 +792,7 @@ async def test_network_complete(hass, mock_openzwave):
|
|||||||
|
|
||||||
hass.bus.async_listen(const.EVENT_NETWORK_READY, listener)
|
hass.bus.async_listen(const.EVENT_NETWORK_READY, listener)
|
||||||
|
|
||||||
hass.async_add_job(mock_receivers[0])
|
await hass.async_add_executor_job(mock_receivers[0])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
@ -811,7 +819,7 @@ async def test_network_complete_some_dead(hass, mock_openzwave):
|
|||||||
|
|
||||||
hass.bus.async_listen(const.EVENT_NETWORK_COMPLETE_SOME_DEAD, listener)
|
hass.bus.async_listen(const.EVENT_NETWORK_COMPLETE_SOME_DEAD, listener)
|
||||||
|
|
||||||
hass.async_add_job(mock_receivers[0])
|
await hass.async_add_executor_job(mock_receivers[0])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user