Skip to content

Commit 7185268

Browse files
committed
Changed type of VolumeSpecific to textinput with validation
1 parent 7ee3dbc commit 7185268

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

Diff for: src/actions.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,32 @@ export function GetActionsList(executeAction: (fcn: DoAction) => Promise<void>):
190190
name: 'Set Volume to Specific Value',
191191
options: [
192192
{
193-
type: 'number',
193+
type: 'textinput',
194194
label: 'Volume',
195195
id: 'value',
196-
default: 50,
197-
min: 0,
198-
max: 100,
199-
step: 1,
196+
default: '',
197+
useVariables: true,
200198
},
201199
],
202200
callback: async (action) => {
203201
await executeAction(async (instance, deviceId) => {
204-
if (deviceId) await ChangeVolume(instance, deviceId, true, Number(action.options.value))
202+
if (deviceId) {
203+
const value = await instance.parseVariablesInString(String(action.options.value))
204+
205+
if (!/^\d+$/.test(value)) {
206+
instance.log('warn', `Invalid volume value: ${value}`)
207+
return
208+
}
209+
210+
const intValue = Number(value)
211+
212+
if (intValue < 0 || intValue > 100) {
213+
instance.log('warn', `Volume value out of range: ${intValue}`)
214+
return
215+
}
216+
217+
await ChangeVolume(instance, deviceId, true, intValue)
218+
}
205219
})
206220
},
207221
},

0 commit comments

Comments
 (0)