From d69c68b4c20451401eb9020222d1d95f8d3119e3 Mon Sep 17 00:00:00 2001 From: Axel Boberg Date: Thu, 18 Apr 2024 16:20:37 +0200 Subject: [PATCH] Fix an issue where the stop command didn't take variables into account Signed-off-by: Axel Boberg --- api/items.js | 15 ++++++++++++++- lib/api/items.js | 15 +++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/api/items.js b/api/items.js index 724d401..4acd510 100644 --- a/api/items.js +++ b/api/items.js @@ -239,6 +239,19 @@ exports.playItem = playItem * @param { String } id */ async function stopItem (id) { - commands.executeCommand('items.stopItem', id) + const item = await getItem(id) + + if (!item) { + return + } + + if (item?.data?.disabled) { + return + } + + const type = await types.getType(item.type) + const clone = populateVariablesMutable(deepClone(item), type) + + commands.executeCommand('items.stopItem', clone) } exports.stopItem = stopItem diff --git a/lib/api/items.js b/lib/api/items.js index e8a4c8f..08cbdba 100644 --- a/lib/api/items.js +++ b/lib/api/items.js @@ -69,19 +69,18 @@ function factory (api, workspace) { /** * Stop an item by its id - * @param { String } id + * @param { Item } item */ - function stopItem (id) { - api.commands.executeCommand('scheduler.abort', undefined, `play:${id}`) - - const item = getItem(id) - if (!item) { - return + function stopItem (item) { + if (!item?.id) { + throw new ApiError('Invalid item object', 'ERR_API_ITEMS_INVALID_ITEM') } + api.commands.executeCommand('scheduler.abort', undefined, `play:${item.id}`) + workspace.state.apply({ items: { - [id]: { + [item.id]: { state: 'stopped' } }