/// /// Copyright © 2016-2024 The Thingsboard Authors /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; export enum GetValueAction { DO_NOTHING = 'DO_NOTHING', EXECUTE_RPC = 'EXECUTE_RPC', GET_ATTRIBUTE = 'GET_ATTRIBUTE', GET_TIME_SERIES = 'GET_TIME_SERIES' } export const getValueActions = Object.keys(GetValueAction) as GetValueAction[]; export const getValueActionTranslations = new Map( [ [GetValueAction.DO_NOTHING, 'widgets.value-action.do-nothing'], [GetValueAction.EXECUTE_RPC, 'widgets.value-action.execute-rpc'], [GetValueAction.GET_ATTRIBUTE, 'widgets.value-action.get-attribute'], [GetValueAction.GET_TIME_SERIES, 'widgets.value-action.get-time-series'] ] ); export interface RpcSettings { method: string; requestTimeout: number; requestPersistent: boolean; persistentPollingInterval: number; } export interface TelemetryValueSettings { key: string; } export interface GetTelemetryValueSettings extends TelemetryValueSettings { subscribeForUpdates: boolean; } export interface GetAttributeValueSettings extends GetTelemetryValueSettings { scope: AttributeScope | null; } export interface SetAttributeValueSettings extends TelemetryValueSettings { scope: AttributeScope.SERVER_SCOPE | AttributeScope.SHARED_SCOPE; } export enum DataToValueType { NONE = 'NONE', FUNCTION = 'FUNCTION' } export interface DataToValueSettings { type: DataToValueType; dataToValueFunction: string; compareToValue?: any; } export interface ValueActionSettings { actionLabel?: string; } export interface GetValueSettings extends ValueActionSettings { action: GetValueAction; defaultValue: V; executeRpc: RpcSettings; getAttribute: GetAttributeValueSettings; getTimeSeries: GetTelemetryValueSettings; dataToValue: DataToValueSettings; } export enum SetValueAction { EXECUTE_RPC = 'EXECUTE_RPC', SET_ATTRIBUTE = 'SET_ATTRIBUTE', ADD_TIME_SERIES = 'ADD_TIME_SERIES' } export const setValueActions = Object.keys(SetValueAction) as SetValueAction[]; export const setValueActionTranslations = new Map( [ [SetValueAction.EXECUTE_RPC, 'widgets.value-action.execute-rpc'], [SetValueAction.SET_ATTRIBUTE, 'widgets.value-action.set-attribute'], [SetValueAction.ADD_TIME_SERIES, 'widgets.value-action.add-time-series'] ] ); export enum ValueToDataType { CONSTANT = 'CONSTANT', FUNCTION = 'FUNCTION', NONE = 'NONE' } export interface ValueToDataSettings { type: ValueToDataType; constantValue: any; valueToDataFunction: string; } export interface SetValueSettings extends ValueActionSettings { action: SetValueAction; executeRpc: RpcSettings; setAttribute: SetAttributeValueSettings; putTimeSeries: TelemetryValueSettings; valueToData: ValueToDataSettings; } /*export interface RpcStateBehaviourSettings { initialState: RpcInitialStateSettings; updateStateByValue: (value: V) => RpcUpdateStateSettings; } export interface RpcStateWidgetSettings { initialState: RpcInitialStateSettings; background: BackgroundSettings; }*/