Skip to content

Commit

Permalink
Fix an issue where the stop command didn't take variables into account
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Apr 18, 2024
1 parent eef3add commit d69c68b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 14 additions & 1 deletion api/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 7 additions & 8 deletions lib/api/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down

0 comments on commit d69c68b

Please sign in to comment.