From 17918998dbda8daee56a74fb0ee954678a1457c5 Mon Sep 17 00:00:00 2001 From: phillipivan Date: Tue, 17 Sep 2024 13:26:24 +1000 Subject: [PATCH 1/3] update companion-module-tools > 2.0.4 --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 95e5cee..e16a0a2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "emberplus-connection": "^0.2.1" }, "devDependencies": { - "@companion-module/tools": "^2.0.3", + "@companion-module/tools": "^2.0.4", "eslint": "^9.10.0", "husky": "^9.1.6", "lint-staged": "^15.2.0", diff --git a/yarn.lock b/yarn.lock index 1dadff1..8b97599 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,9 +22,9 @@ __metadata: languageName: node linkType: hard -"@companion-module/tools@npm:^2.0.3": - version: 2.0.3 - resolution: "@companion-module/tools@npm:2.0.3" +"@companion-module/tools@npm:^2.0.4": + version: 2.0.4 + resolution: "@companion-module/tools@npm:2.0.4" dependencies: "@eslint/js": "npm:^9.10.0" eslint-config-prettier: "npm:^9.1.0" @@ -52,7 +52,7 @@ __metadata: companion-generate-manifest: scripts/generate-manifest.js companion-module-build: scripts/build.js companion-module-check: scripts/check.js - checksum: 10c0/b69b27071442c92f1df1aa1ddc860556502e2774b12d1cdcae0db162f7b0ca534b1d2050894e188b5c48edcf34e67a3ca7843bd6bb7cc7352abe0bbf4508d543 + checksum: 10c0/ce795f8ede524b2984a5c4fc744267fc8b9dab8fa9602295f13348ce340cf9e8ec5ebbb1ab4cf415f8780ba8d89f4d67f936a4d5b9f0539ba9573cdbc129d6d4 languageName: node linkType: hard @@ -1533,7 +1533,7 @@ asn1@evs-broadcast/node-asn1: resolution: "generic-emberplus@workspace:." dependencies: "@companion-module/base": "npm:~1.10.0" - "@companion-module/tools": "npm:^2.0.3" + "@companion-module/tools": "npm:^2.0.4" "@types/node": "npm:^18.19.45" emberplus-connection: "npm:^0.2.1" eslint: "npm:^9.10.0" From 321bd0824bd4653b8a412181ef36700a076e0396 Mon Sep 17 00:00:00 2001 From: phillipivan Date: Tue, 17 Sep 2024 13:49:41 +1000 Subject: [PATCH 2/3] add action set enum value from variable, bounds check integer and enum variables, allow path input to include a description --- src/actions.ts | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/actions.ts b/src/actions.ts index b797fcf..1ceb9b8 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -18,6 +18,7 @@ export enum ActionId { SetValueString = 'setValueString', SetValueBoolean = 'setValueBoolean', SetValueEnum = 'setValueEnum', + SetValueEnumVariable = 'setValueEnumVariable', MatrixConnect = 'matrixConnect', MatrixDisconnect = 'matrixDisconnect', MatrixSetConnection = 'matrixSetConnection', @@ -32,6 +33,7 @@ const pathInput: CompanionInputFieldTextInput = { label: 'Path', id: 'path', useVariables: true, + tooltip: `Path may be supplied in decimals: 1.2.3, or with a descriptor and the decimals wrapped in brackets: path/to/ember/element[1.2.3.4]`, } const matrixInputs: Array = [ pathInput, @@ -53,10 +55,18 @@ const matrixInputs: Array, path: string): Promise { + const pathString: string = await self.parseVariablesInString(path) + if (pathString.includes('[') && pathString.includes(']')) { + return pathString.substring(pathString.indexOf('[') + 1, pathString.indexOf(']')) + } + return pathString +} + const setValue = (self: InstanceBase, emberClient: EmberClient, type: EmberModel.ParameterType) => async (action: CompanionActionEvent): Promise => { - const path = await self.parseVariablesInString(action.options['path']?.toString() ?? '') + const path = await resolvePath(self, action.options['path']?.toString() ?? '') const node = await emberClient.getElementByPath(path) // TODO - do we handle not found? if (node && node.contents.type === EmberModel.ElementType.Parameter) { @@ -72,7 +82,18 @@ const setValue = request.response?.catch(() => null) // Ensure the response is 'handled' } else if (type === EmberModel.ParameterType.Integer) { const value: number = parseInt(await self.parseVariablesInString(action.options['value']?.toString() ?? '')) - if (isNaN(value)) { + if (isNaN(value) || value > 4294967295 || value < -4294967295) { + return + } + const request = await emberClient.setValue( + node as EmberModel.NumberedTreeNode, + value, + false, + ) + request.response?.catch(() => null) // Ensure the response is 'handled' + } else if (type === EmberModel.ParameterType.Enum) { + const value: number = parseInt(await self.parseVariablesInString(action.options['value']?.toString() ?? '')) + if (isNaN(value) || value > 4294967295 || value < 0) { return } const request = await emberClient.setValue( @@ -107,7 +128,7 @@ const doMatrixAction = method: EmberClient['matrixConnect'] | EmberClient['matrixDisconnect'] | EmberClient['matrixSetConnection'], ) => async (action: CompanionActionEvent): Promise => { - const path = await self.parseVariablesInString(action.options['path']?.toString() ?? '') + const path = await resolvePath(self, action.options['path']?.toString() ?? '') self.log('debug', 'Get node ' + path) const node = await emberClient.getElementByPath(path) // TODO - do we handle not found? @@ -349,6 +370,22 @@ export function GetActionsList( ], callback: setValue(self, emberClient, EmberModel.ParameterType.Enum), }, + [ActionId.SetValueEnumVariable]: { + name: 'Set Value ENUM from Variable (as Integer)', + options: [ + pathInput, + { + type: 'textinput', + label: 'Value', + id: 'value', + required: true, + useVariables: true, + default: '0', + tooltip: 'Return an integer between 0 and 4294967295', + }, + ], + callback: setValue(self, emberClient, EmberModel.ParameterType.Enum), + }, [ActionId.SetValueString]: { name: 'Set Value String', options: [ From 101ac608c07120d480707c30ce0509c268daa185 Mon Sep 17 00:00:00 2001 From: phillipivan Date: Tue, 17 Sep 2024 13:50:31 +1000 Subject: [PATCH 3/3] version bump to 2.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e16a0a2..06ad4e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generic-emberplus", - "version": "2.3.0", + "version": "2.3.1", "main": "dist/index.js", "scripts": { "prepare": "husky",