diff --git a/package.json b/package.json index b2c7347..94e6ce1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generic-emberplus", - "version": "2.3.3", + "version": "2.4.0", "main": "dist/index.js", "scripts": { "prepare": "husky", diff --git a/src/index.ts b/src/index.ts index 272a58f..12423bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { type EmberPlusConfig, GetConfigFields } from './config' import { GetPresetsList } from './presets' import { FeedbackId, GetFeedbacksList } from './feedback' import { EmberPlusState } from './state' -import { EmberClient } from 'emberplus-connection' // note - emberplus-conn is in parent repo, not sure if it needs to be defined as dependency +import { EmberClient, Model as EmberModel } from 'emberplus-connection' // note - emberplus-conn is in parent repo, not sure if it needs to be defined as dependency import { ElementType } from 'emberplus-connection/dist/model' import type { TreeElement, EmberElement } from 'emberplus-connection/dist/model' import { GetVariablesList } from './variables' @@ -22,6 +22,7 @@ class EmberPlusInstance extends InstanceBase { private state!: EmberPlusState private emberQueue!: PQueue private reconnectTimer!: ReturnType | undefined + private isRecordingActions!: boolean // Override base types to make types stricter public checkFeedbacks(...feedbackTypes: string[]): void { @@ -196,6 +197,10 @@ class EmberPlusInstance extends InstanceBase { }) } } + // Track whether actions are being recorded + public handleStartStopRecordActions(isRecording: boolean) { + this.isRecordingActions = isRecording + } private async handleChangedValue(path: string, node: TreeElement) { if (node.contents.type == ElementType.Parameter) { this.log('debug', 'Got parameter value for ' + path + ': ' + (node.contents.value?.toString() ?? '')) @@ -203,6 +208,38 @@ class EmberPlusInstance extends InstanceBase { this.checkFeedbacks(FeedbackId.Parameter, FeedbackId.String) this.setVariableValues(Object.fromEntries(this.state.parameters.entries())) + if (this.isRecordingActions) { + let actionType: string + let actionValue: any + if (node.contents.parameterType === EmberModel.ParameterType.Integer) { + actionType = 'setValueInt' + actionValue = Number(node.contents.value) + if (isNaN(actionValue)) return + } else if (node.contents.parameterType === EmberModel.ParameterType.Boolean) { + actionType = 'setValueBoolean' + actionValue = !!node.contents.value + } else if (node.contents.parameterType === EmberModel.ParameterType.Enum) { + actionType = 'setValueEnum' + actionValue = Number(node.contents.value) + if (isNaN(actionValue)) return + } else if (node.contents.parameterType === EmberModel.ParameterType.Real) { + actionType = 'setValueReal' + actionValue = Number(node.contents.value) + if (isNaN(actionValue)) return + } else if (node.contents.parameterType === EmberModel.ParameterType.String) { + actionType = 'setValueString' + actionValue = node.contents.value?.toString() + } else { + return + } + this.recordAction( + { + actionId: actionType, + options: { path: path, value: actionValue }, + }, + `${path}`, + ) + } } } }