--- alias: user-guide-automation-business-scenarios-building-structure-step-script-iotUtilities tags: - automation - connect iot description: "This documentation outlines methods for managing IoT entities within a scripting context" --- # IoTUtilities !!! note This is advanced documentation regarding a scope that can be accessed when executing a step of type `Script`. This document provides an overview of the public methods in the `ScriptScopeIoTUtilities` class. These methods facilitate the handling of IoT entities, events, properties, and related operations. ## Methods ### allEntityTypesFromController === "Declaration" `allEntityTypesFromController(automationController: Cmf.Foundation.BusinessObjects.AutomationController): string[]` === "Description" Retrieves all entity types used in the controller and associated drivers. === "Parameters" - `automationController`: The automation controller object. === "Returns" An array of entity type names. === "Example" ```json { "name": "Example AllEntityTypesFromController", "type": "Script", "resultKey": "iotEntityTypesWithStateModels", "settings": { "script": [ "(async () => {", " const entityTypes = await this.iotUtilities.allEntityTypesFromController(entityInstance);", " const entityTypesWithStateModels = await this.lboUtilities.entityTypesWithStateModel(entityTypes, true);", " if(entityTypesWithStateModels == null || entityTypesWithStateModels.length == 0) {", " throw new Error('No State Model found for Entity Types associated with this controller');", " }", "return entityTypesWithStateModels;", "})()" ] }, "next": "SelectEntityType" } ``` ### allDriversFromController === "Declaration" `allDriversFromController(automationController: Cmf.Foundation.BusinessObjects.AutomationController): Map` === "Description" Retrieves all friendly names and driver definitions from a controller. === "Parameters" - `automationController`: The automation controller object. === "Returns" A map of driver names to their definitions. === "Example" ```json { "name": "Example AllDriversFromController", "type": "Script", "resultKey": "iotControllerDrivers", "settings": { "script": [ "const iotDriversMap = this.iotUtilities.allDriversFromController(entityInstance);", "const iotDriversMapFiltered = new Map([...iotDriversMap].filter(([key, value]) => value.ObjectType.Name === this.answers.iotEntityType.Name));", "const iotDrivers = Array.from(iotDriversMapFiltered?.keys());", "this.lboUtilities.convertArrayOfStringsToEnum(iotDrivers);" ] }, "next": "CheckDrivers" } ``` ### allEventNamesFromDriver === "Declaration" `allEventNamesFromDriver(driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): string[] | undefined` === "Description" Retrieves all event names from a driver, merging template and driver definition events. === "Parameters" - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" An array of event names or `undefined` if inputs are invalid. === "Example" ```json { "name": "Example AllEventNamesFromDriver", "type": "Script", "resultKey": "iotControllerDriverEvents", "settings": { "script": [ "const driverEvents = this.iotUtilities.allEventNamesFromDriver(this.answers.iotControllerDriver, entityInstance);", "this.lboUtilities.convertArrayOfStringsToEnum(driverEvents);" ] }, "next": "AskWhichDriverEvent" } ``` ### getEventByName === "Declaration" `getEventByName(eventName: string, driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): Cmf.Foundation.BusinessObjects.AutomationEvent | undefined` === "Description" Retrieves an event by its name. === "Parameters" - `eventName`: The name of the event. - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" The event object or `undefined`. ### isTemplateEvent === "Declaration" `isTemplateEvent(eventName: string, driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): boolean | null | undefined` === "Description" Checks if an event is a template event. === "Parameters" - `eventName`: The name of the event. - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" - `true` if the event is a template event. - `false` if it is not. - `null` if no matching event or template event is found. - `undefined` for invalid inputs. ### allCommandNamesFromDriver === "Declaration" `allCommandNamesFromDriver(driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): string[] | undefined` === "Description" Retrieves all command names from a driver, merging template and driver definition commands. === "Parameters" - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" An array of command names or `undefined`. ### allPropertyNamesFromDriver === "Declaration" `allPropertyNamesFromDriver(driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): string[] | undefined` === "Description" Retrieves all property names from a driver, merging template and driver definition properties. === "Parameters" - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" An array of property names or `undefined`. ### allPropertyNamesFromAnEvent === "Declaration" `allPropertyNamesFromAnEvent(eventName: string, driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): string[] | undefined` === "Description" Retrieves all property names associated with an event. === "Parameters" - `eventName`: The name of the event. - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" An array of property names or `undefined`. === "Example" ```json { "name": "Example AllPropertyNamesFromAnEvent", "type": "Script", "resultKey": "iotControllerDriverEventProperties", "settings": { "script": [ "const driverEventProperties = this.iotUtilities.allPropertyNamesFromAnEvent(this.answers.iotControllerDriverEvent,this.answers.iotControllerDriver, entityInstance);", "this.lboUtilities.convertArrayOfStringsToEnum(driverEventProperties);" ] }, "next": "IsMultiProp" } ``` ### allPropertiesFromAnEvent === "Declaration" `allPropertiesFromAnEvent(eventName: string, driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): Cmf.Foundation.BusinessObjects.AutomationProperty[] | undefined` === "Description" Retrieves all properties associated with an event. === "Parameters" - `eventName`: The name of the event. - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" An array of property objects or `undefined`. ### getPropertyByName === "Declaration" `getPropertyByName(propertyName: string, driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): Cmf.Foundation.BusinessObjects.AutomationProperty | undefined` === "Description" Retrieves a property by its name. === "Parameters" - `propertyName`: The name of the property. - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" The property object or `undefined`. === "Example" ```json { "name": "Example GetPropertyByName", "type": "Script", "resultKey": "iotCurrentProp", "settings": { "script": [ "Object.assign({}, this.iotUtilities.getPropertyByName(this.answers.iotControllerDriverEventProperties[0].Id, this.answers.iotControllerDriver, entityInstance));" ] }, "next": "IsPropTypeValid" } ``` ### getPropertyDataType === "Declaration" `getPropertyDataType(dataType: string | number): { name: string, type: PropertyValueType }` === "Description" Converts a property data type into a structured format. === "Parameters" - `dataType`: The data type as a string or number. === "Returns" An object containing the name and type. ### generateOnEquipmentEventSettings === "Declaration" `generateOnEquipmentEventSettings(selectedEventName: string, driverName: string, automationController: Cmf.Foundation.BusinessObjects.AutomationController): any` === "Description" Generates settings for a task triggered by an equipment event. === "Parameters" - `selectedEventName`: The name of the selected event. - `driverName`: The name of the driver. - `automationController`: The automation controller object. === "Returns" An object containing the generated settings. === "Example" ```ts this.iotUtilities.generateOnEquipmentEventSettings( this.answers.iotControllerDriverEvent, driverAlias, automationController ); ```