Best JavaScript code snippet using best
smartStructureFields.js
Source:smartStructureFields.js
1/* Smart Fields Constants */2export class HUBCONFIGURATION {3 /**4 * Configuration5 * @smartType tab6 */7 static hub_config = "hub_config";8 /**9 * Identification10 * @smartType frame11 */12 static hub_station_id_frame = "hub_station_id_frame";13 /**14 * Hub Station15 * @smartType docid HUBINSTANCIATION16 */17 static hub_station_id = "hub_station_id";18 /**19 * Name20 * @smartType text21 */22 static hub_title = "hub_title";23 /**24 * Dock25 * @smartType frame26 */27 static hub_slot_parameters = "hub_slot_parameters";28 /**29 * Order in dock30 * @smartType int31 */32 static hub_order = "hub_order";33 /**34 * Dock position35 * @smartType enum Hub_DockerPos36 */37 static hub_docker_position = "hub_docker_position";38 /**39 * Hub element status40 * @smartType frame41 */42 static hub_activated_frame = "hub_activated_frame";43 /**44 * Element is default selected45 * @smartType enum Hub_YesNo46 */47 static hub_activated = "hub_activated";48 /**49 * Element is selectable50 * @smartType enum Hub_YesNo51 */52 static hub_selectable = "hub_selectable";53 /**54 * Element is expandable55 * @smartType enum Hub_YesNo56 */57 static hub_expandable = "hub_expandable";58 /**59 * Priority60 * @smartType int61 */62 static hub_activated_order = "hub_activated_order";63 /**64 * Element parameters65 * @smartType tab66 */67 static hub_component_tab = "hub_component_tab";68 /**69 * Parameters70 * @smartType frame71 */72 static hub_component_parameters = "hub_component_parameters";73 /**74 * Security75 * @smartType tab76 */77 static hub_security = "hub_security";78 /**79 * Security Roles80 * @smartType frame81 */82 static hub_security_frame = "hub_security_frame";83 /**84 * Roles to display hub element85 * @smartType account86 */87 static hub_visibility_roles = "hub_visibility_roles";88 /**89 * Roles to access hub element API90 * @smartType account91 */92 static hub_execution_roles = "hub_execution_roles";93 /**94 * Security access95 * @smartType frame96 */97 static hub_p_securityaccess = "hub_p_securityaccess";98 /**99 * Mandatory route role100 * @smartType text101 */102 static hub_p_routes_role = "hub_p_routes_role";103}104export class HUBINSTANCIATION {105 /**106 * Configuration107 * @smartType tab108 */109 static hub_instance_config = "hub_instance_config";110 /**111 * Information112 * @smartType frame113 */114 static hub_instance = "hub_instance";115 /**116 * Logical Name117 * @smartType text118 */119 static instance_logical_name = "instance_logical_name";120 /**121 * Router entry122 * @smartType text123 */124 static hub_instanciation_router_entry = "hub_instanciation_router_entry";125 /**126 * Fav icon127 * @smartType image128 */129 static hub_instanciation_icone = "hub_instanciation_icone";130 /**131 * Label132 * @smartType frame133 */134 static hub_instance_label_frame = "hub_instance_label_frame";135 /**136 * Hub Station Titles137 * @smartType array138 */139 static hub_instance_titles = "hub_instance_titles";140 /**141 * Title142 * @smartType text143 */144 static hub_instance_title = "hub_instance_title";145 /**146 * Language147 * @smartType text148 */149 static hub_instance_language = "hub_instance_language";150 /**151 * Advanced Settings152 * @smartType frame153 */154 static hub_instance_advanced_settings = "hub_instance_advanced_settings";155 /**156 * Left dock157 * @smartType enum collapsed_configuration158 */159 static hub_instanciation_dock_left = "hub_instanciation_dock_left";160 /**161 * Right dock162 * @smartType enum collapsed_configuration163 */164 static hub_instanciation_dock_right = "hub_instanciation_dock_right";165 /**166 * Top dock167 * @smartType enum collapsed_configuration168 */169 static hub_instanciation_dock_top = "hub_instanciation_dock_top";170 /**171 * Bottom dock172 * @smartType enum collapsed_configuration173 */174 static hub_instanciation_dock_bottom = "hub_instanciation_dock_bottom";175 /**176 * Global assets177 * @smartType tab178 */179 static hub_instance_tab_assets = "hub_instance_tab_assets";180 /**181 * Hub instance global assets182 * @smartType frame183 */184 static hub_instance_fr_assets = "hub_instance_fr_assets";185 /**186 * Javascript assets187 * @smartType array188 */189 static hub_instance_jsassets = "hub_instance_jsassets";190 /**191 * Asset type192 * @smartType enum hub_instance_asset_type193 */194 static hub_instance_jsasset_type = "hub_instance_jsasset_type";195 /**196 * Location197 * @smartType text198 */199 static hub_instance_jsasset = "hub_instance_jsasset";200 /**201 * CSS assets202 * @smartType array203 */204 static hub_instance_cssassets = "hub_instance_cssassets";205 /**206 * Asset type207 * @smartType enum hub_instance_asset_type208 */209 static hub_instance_cssasset_type = "hub_instance_cssasset_type";210 /**211 * Location212 * @smartType text213 */214 static hub_instance_cssasset = "hub_instance_cssasset";215 /**216 * Security217 * @smartType tab218 */219 static hub_security = "hub_security";220 /**221 *222 * @smartType frame223 */224 static hub_security_frame = "hub_security_frame";225 /**226 * Roles to access227 * @smartType account228 */229 static hub_access_roles = "hub_access_roles";230 /**231 * Role to access to any elements232 * @smartType account233 */234 static hub_super_role = "hub_super_role";235}236export class HUBCONFIGURATIONSLOT extends HUBCONFIGURATION {}237export class HUBCONFIGURATIONVUE extends HUBCONFIGURATION {238 /**239 * Router entry240 * @smartType text241 */242 static hub_vue_router_entry = "hub_vue_router_entry";243}244export class HUBCONFIGURATIONGENERIC extends HUBCONFIGURATIONVUE {245 /**246 * Assets247 * @smartType frame248 */249 static hge_fr_assets = "hge_fr_assets";250 /**251 * Javascript assets252 * @smartType array253 */254 static hge_jsassets = "hge_jsassets";255 /**256 * Asset type257 * @smartType enum hge_asset_type258 */259 static hge_jsasset_type = "hge_jsasset_type";260 /**261 * Location262 * @smartType text263 */264 static hge_jsasset = "hge_jsasset";265 /**266 * CSS assets267 * @smartType array268 */269 static hge_cssassets = "hge_cssassets";270 /**271 * Asset type272 * @smartType enum hge_asset_type273 */274 static hge_cssasset_type = "hge_cssasset_type";275 /**276 * Location277 * @smartType text278 */279 static hge_cssasset = "hge_cssasset";280 /**281 * Identification282 * @smartType frame283 */284 static hge_fr_identification = "hge_fr_identification";285 /**286 * Component tag287 * @smartType text288 */289 static hge_component_tag = "hge_component_tag";290 /**291 * Component properties292 * @smartType json293 */294 static hge_component_props = "hge_component_props";295}296export class HUBCONFIGURATIONIDENTITY extends HUBCONFIGURATIONSLOT {297 /**298 * Email alterable299 * @smartType enum Hub_YesNo300 */301 static email_alterable = "email_alterable";302 /**303 * Password alterable304 * @smartType enum Hub_YesNo305 */306 static password_alterable = "password_alterable";307}308export class HUBCONFIGURATIONLABEL extends HUBCONFIGURATIONSLOT {309 /**310 * Html label311 * @smartType longtext312 */313 static label = "label";314 /**315 * Extended Html label316 * @smartType longtext317 */318 static extended_label = "extended_label";319}320export class HUBCONFIGURATIONLOGOUT extends HUBCONFIGURATIONSLOT {321 /**322 * Title323 * @smartType text324 */325 static logout_title = "logout_title";...
index.ts
Source:index.ts
1// class to provide a Logitech Harmony Hub platform2import { API, DynamicPlatformPlugin, HAP, Logger, PlatformAccessory, PlatformConfig } from "homebridge";3import { AnekolHarmonyApi } from './harmony_api';4import { AnekolHarmonyHubDevicesHelper } from './devices';5import { AnekolHarmonyHubHelper } from './hub';6import { AnekolHarmonyHubVolumeHelper } from './volume';7module.exports = (api: API) => {8 api.registerPlatform(PLATFORM_NAME, AnekolHarmonyHub);9}10const PLATFORM_NAME = 'AnekolHarmonyHub';11const PLUGIN_NAME = 'homebridge-anekol-harmony-hub'; // Plugin name from package.json12export interface Activity { id: string, slug: string, label: string, isAVActivity: boolean }13export interface Device { id: string, slug: string, label: string }14export interface Hub { slug: string, activities: Activity[], devices: Device[] }[]15export interface HubConfig { slug: string, label: string, devices: string[] }16export class AnekolHarmonyHub implements DynamicPlatformPlugin {17 private configured: PlatformAccessory[] = []18 private hap: HAP19 private harmony_api: AnekolHarmonyApi20 private host: string21 private hubs_config: HubConfig[]22 private name: string23 private port: string = "8282"24 private restored: PlatformAccessory[] = []25 constructor(26 public readonly log: Logger,27 public readonly config: PlatformConfig,28 public readonly api: API,29 ) {30 this.hap = api.hap31 // user config32 this.name = config.name as string || PLATFORM_NAME33 this.host = config.host as string || "localhost"34 this.port = config.port as string || "8282"35 this.hubs_config = config.hubs as HubConfig[];36 this.harmony_api = new AnekolHarmonyApi(log, this.host, this.port)37 // wait for "didFinishLaunching" 38 api.on('didFinishLaunching', () => {39 this.log.info("Finished restoring cached accessories")40 // configure the hub and it's accessories41 this.discover_hubs().then((hubs) => {42 for (var hub of hubs) {43 const hub_config = this.config_for(hub.slug)44 // ignore discovered hubs that aren't present in the plugin config45 if (hub_config) {46 var uuid, accessory47 const hub_label = hub_config.label || ""48 // configure the main hub accessory49 uuid = this.hap.uuid.generate(PLUGIN_NAME + "_" + hub.slug + "_hub")50 accessory = this.find_restored(uuid)51 if (!accessory) {52 accessory = new this.api.platformAccessory(hub_label, uuid, this.hap.Categories.TV_SET_TOP_BOX);53 this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);54 this.log.info('Added new accessory: ' + accessory.displayName);55 }56 new AnekolHarmonyHubHelper(this, accessory, this.harmony_api, hub)57 this.add_configured(accessory)58 // configure hub devices accessory59 uuid = this.hap.uuid.generate(PLUGIN_NAME + "_" + hub.slug + "_devices")60 accessory = this.find_restored(uuid)61 if (!accessory) {62 accessory = new this.api.platformAccessory(hub_label + " Devices", uuid, this.hap.Categories.SWITCH);63 this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);64 this.log.info('Added new accessory: ' + accessory.displayName);65 }66 new AnekolHarmonyHubDevicesHelper(this, accessory, this.harmony_api, hub, hub_config.devices)67 this.add_configured(accessory)68 // configure hub volume accessory69 uuid = this.hap.uuid.generate(PLUGIN_NAME + "_" + hub.slug + "_volume")70 accessory = this.find_restored(uuid)71 if (!accessory) {72 accessory = new this.api.platformAccessory(hub_label + " Volume", uuid, this.hap.Categories.LIGHTBULB);73 this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);74 this.log.info('Added new accessory: ' + accessory.displayName);75 }76 new AnekolHarmonyHubVolumeHelper(this, accessory, this.harmony_api, hub)77 this.add_configured(accessory)78 }79 }80 // deregister any restored accessories not configured81 for (var r of this.restored) {82 if (!this.configured.find(c => c.UUID === r.UUID)) {83 this.log.info("Deregister: not configured: " + r.displayName)84 this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [r])85 }86 }87 })88 })89 }90 // discover hub configurations91 private async discover_hubs() {92 let discovered_hubs: Hub[] = []93 // find hubs94 let hd = await this.harmony_api.get("")95 let hub_slugs = hd.hubs ? hd.hubs : []96 for (var hub_slug of hub_slugs) {97 // find hub activities98 let ad = await this.harmony_api.get(hub_slug + "/activities")99 const activities: Activity[] = ad.activities ? ad.activities : []100 // find hub devices101 let dd = await this.harmony_api.get(hub_slug + "/devices")102 const devices: Device[] = dd.devices ? dd.devices : []103 discovered_hubs.push({ slug: hub_slug, activities: activities, devices: devices })104 }105 return discovered_hubs106 }107 // add accessory to configured list108 public add_configured(accessory: PlatformAccessory) {109 this.configured.push(accessory)110 }111 // configureAccessory will be called once for every cached accessory restored112 public configureAccessory(accessory: PlatformAccessory) {113 this.restored.push(accessory)114 }115 // find restored accessory116 public find_restored(uuid: string) {117 return this.restored.find(a => a.UUID === uuid)118 }119 // find config for a hub120 private config_for(slug: string) {121 for (const hub of this.hubs_config) {122 if (hub.slug == slug) {123 return hub124 }125 }126 return null127 }...
config.ts
Source:config.ts
1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6 */7import { AgentConfig } from "@best/types";8const HUB_CONFIG = process.env.HUB_CONFIG ? JSON.parse(process.env.HUB_CONFIG): {};9const HUB_URI = process.env.HUB_URI;10const HUB_AUTH_TOKEN = process.env.HUB_AUTH_TOKEN;11function normalizeArgOptions(argv: string[]): any {12 let arg;13 const normalizedArgs: any = {};14 while((arg = argv.shift()) !== undefined) {15 if (arg.startsWith('--')) {16 if (arg.includes('=')) {17 const [key, value] = arg.split('=');18 normalizedArgs[key.slice(2)] = value;19 } else {20 normalizedArgs[arg.slice(2)] = argv.shift();21 }22 }23 }24 return normalizedArgs;25}26const argv = normalizeArgOptions(process.argv.slice(2));27export function getHubConfig(): AgentConfig {28 return {29 ...HUB_CONFIG,30 uri: argv.hubUri || HUB_URI || HUB_CONFIG.uri,31 authToken: argv.hubAuthToken || HUB_AUTH_TOKEN || HUB_CONFIG.authToken32 };...
Using AI Code Generation
1var hubConfig = require('./hubConfig');2var hubClient = require('azure-iothub').Client.fromConnectionString(hubConfig.hubConnectionString);3var message = new Message('{"name":"IoT Hub Test Message"}');4hubClient.open(function (err) {5 if (err) {6 console.error('Could not connect: ' + err.message);7 } else {8 console.log('Client connected');9 hubClient.send('MyFirstDevice', message, printResultFor('send'));10 }11});12function printResultFor(op) {13 return function printResult(err, res) {14 if (err) console.log(op + ' error: ' + err.toString());15 if (res) console.log(op + ' status: ' + res.constructor.name);16 };17}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!