How to use publishDevice method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

hassioMQTT.js

Source:hassioMQTT.js Github

copy

Full Screen

1const mqtt = require('mqtt');23class HomeAssistantMQTT {4 constructor(server, options, bridgeTopic) {5 this.mqttPublishPersistentOptions = { qos: 2, retain: true };6 this.mqttPublishVolatileOptions = { qos: 2, retain: false };7 this.mqttClient = mqtt.connect(server, options);8 this.devices = [];9 this.bridgeTopic = bridgeTopic;1011 console.info(`start mqtt connection: "${server}"`);12 this.mqttClient.on('connect', () => {13 console.info(`Succesfully connected to MQTT Server: "${server}"`);14 this.processMQTTBridge();15 });16 }1718 processMQTTBridge() {19 this.mqttClient.subscribe(`${this.bridgeTopic}/bridge/#`, (subscribeError) => {20 if (!subscribeError) {21 console.info('Succesfully subscribed to bridge:');2223 this.mqttClient.on('message', (topic, message) => {24 console.info(`bridge received message topic: "${topic}" - message: "${message}"`);25 if (topic === `${this.bridgeTopic}/devices`) {26 //listen to this topic only if the devices is empty and fill with retained devices27 if (this.devices === undefined || this.devices.length == 0) {28 var bridgeDevices = JSON.parse(message);29 console.info(`Bridge devices found : "${message}"`);30 for (var d in bridgeDevices) {31 this.devices.push(bridgeDevices[d]);32 }33 }34 }35 //Device announcement36 if (topic === `${this.bridgeTopic}/bridge/announce`) {37 var device = JSON.parse(message);38 var existingDevice = this.devices.find(d => d._id === device._id)39 if (existingDevice) {40 // console.info(`Publish device state for message : "${device}"`);41 this.publishDeviceState(device); //device exists so only publish the state42 }43 else {44 //device don't exists publish configuration, state and add to bridge devices45 this.devices.push(device);46 // console.info(`Publish device configuration for message : "${device}"`);47 this.publishDeviceConfiguration(device);48 // console.info(`Publish device state for message : "${device}"`);49 this.publishDeviceState(device);50 // console.info(`Publish devices : "${devices}"`)51 this.publishMQTTmessage(`${this.bridgeTopic}/bridge/devices`, this.devices, this.mqttPublishPersistentOptions);52 }5354 }55 })56 } else console.error(`Subscribe to bridge error: ${subscribeError}`)57 }58 )59 }6061 publishMQTTmessage(topic, payload, options) {62 this.mqttClient.subscribe(topic, (subscribeError) => {63 if (!subscribeError) {64 // console.info(`Succesfully subscribed to topic: "${topic}"`);65 this.mqttClient.publish(topic, JSON.stringify(payload), options, (publishError) => {66 if (!publishError) {67 // console.info(`Succesfully published to topic: "${topic}" payload: "${JSON.stringify(payload)} with options: "${JSON.stringify(options)}"`);68 this.mqttClient.unsubscribe(topic, (unsubscribeError) => {69 if (!unsubscribeError) {70 // console.info(`Succesfully unsubscribed from topic: "${topic}"`);71 }72 else console.error(`Unsubscribe error: ${unsubscribeError}`);73 });74 }75 else console.error(`Publish error: ${publishError}`);76 })77 }78 else console.error(`Subscribe error: ${subscribeError}`);79 })80 }8182 publishDeviceConfiguration(device) {83 var deviceId = device._id;84 var publishDevice = {85 identifiers: [deviceId],86 manufacturer: "SpeedTest by Ookla",87 name: device.name,88 }8990 if (device.data.speeds) {91 //Download92 var topic = `homeassistant/sensor/${deviceId}/download/config`;93 var payload = {94 device: publishDevice,95 name: `${device.name} Download`,96 // device_class: metric.label.toLowerCase(),97 icon: 'mdi:speedometer',98 state_topic: `${this.bridgeTopic}/${deviceId}`,99 unique_id: `${deviceId}_download`,100 unit_of_measurement: 'Mbps',101 value_template: `{{ value_json.download }}`102 };103 this.publishMQTTmessage(topic, payload, this.mqttPublishPersistentOptions);104 //Upload105 topic = `homeassistant/sensor/${deviceId}/upload/config`;106 payload = {107 device: publishDevice,108 name: `${device.name} Upload`,109 // device_class: metric.label.toLowerCase(),110 icon: 'mdi:speedometer',111 state_topic: `${this.bridgeTopic}/${deviceId}`,112 unique_id: `${deviceId}_upload`,113 unit_of_measurement: 'Mbps',114 value_template: `{{ value_json.upload }}`115 };116 this.publishMQTTmessage(topic, payload, this.mqttPublishPersistentOptions);117 }118 if (device.data.ping) {119 //Ping120 var topic = `homeassistant/sensor/${deviceId}/ping/config`;121 var payload = {122 device: publishDevice,123 name: `${device.name} Ping`,124 // device_class: metric.label.toLowerCase(),125 icon: 'mdi:speedometer',126 state_topic: `${this.bridgeTopic}/${deviceId}`,127 unique_id: `${deviceId}_ping`,128 unit_of_measurement: 'ms',129 value_template: `{{ value_json.ping }}`130 };131 this.publishMQTTmessage(topic, payload, this.mqttPublishPersistentOptions);132 }133 }134135 publishDeviceState(device) {136 var deviceId = device._id;137 var topic = `${this.bridgeTopic}/${deviceId}`;138139 var state = {};140 if (device.data.speeds) {141 state = { ...state, download: device.data.speeds.download.toFixed(1), upload: device.data.speeds.upload.toFixed(1) };142 }143 if (device.data.ping) {144 state = { ...state, ping: device.data.ping };145 }146147 this.publishMQTTmessage(topic, state, this.mqttPublishVolatileOptions);148 }149150 publishDeviceAnnouncement(device) {151 this.publishMQTTmessage(`${this.bridgeTopic}/bridge/announce`, device, this.mqttPublishVolatileOptions);152 }153}154 ...

Full Screen

Full Screen

devices-controller.js

Source:devices-controller.js Github

copy

Full Screen

...25 'marketName,' +26 'phone.imei,' +27 'provider.name,' +28 'group.originName'29 function publishDevice(device) {30 if (!device.model) {31 device.display = {}32 }33 else {34 device.displayStr = device.display.width + 'x' + device.display.height35 }36 for (var i in device) {37 if (device[i] === null) {38 device[i] = ''39 }40 }41 return device42 }43 function addDevice(device, timeStamp) {44 return CommonService.add(45 $scope.devices46 , devicesBySerial47 , device48 , 'serial'49 , timeStamp)50 }51 function updateDevice(device, timeStamp) {52 return CommonService.update(53 $scope.devices54 , devicesBySerial55 , device56 , 'serial'57 , timeStamp)58 }59 function deleteDevice(serial, timeStamp) {60 return CommonService.delete(61 $scope.devices62 , devicesBySerial63 , serial64 , timeStamp)65 }66 function initScope() {67 DevicesService.getOboeDevices('user', deviceFields, function(device) {68 addDevice(publishDevice(device), -1)69 })70 .done(function() {71 $scope.$digest()72 })73 }74 SettingsService.bind($scope, {75 target: 'removingFilters'76 , source: 'DevicesRemovingFilters'77 , defaultValue: {78 present: 'False'79 , booked: 'False'80 , annotated: 'False'81 , controlled: 'False'82 }83 })84 $scope.devices = []85 $scope.confirmRemove = {value: true}86 $scope.scopeDevicesCtrl = $scope87 $scope.itemsPerPageOptions = ItemsPerPageOptionsService88 SettingsService.bind($scope, {89 target: 'deviceItemsPerPage'90 , source: 'deviceItemsPerPage'91 , defaultValue: $scope.itemsPerPageOptions[2]92 })93 $scope.removingFilterOptions = ['True', 'False', 'Any']94 $scope.removeDevice = function(serial, askConfirmation) {95 if (askConfirmation) {96 GenericModalService.open({97 message: 'Really delete this device?'98 , type: 'Warning'99 , size: 'sm'100 , cancel: true101 })102 .then(function() {103 CommonService.errorWrapper(104 DevicesService.removeDevice105 , [serial, $scope.removingFilters]106 )107 })108 }109 else {110 CommonService.errorWrapper(111 DevicesService.removeDevice112 , [serial, $scope.removingFilters]113 )114 }115 }116 $scope.removeDevices = function(search, filteredDevices, askConfirmation) {117 function removeDevices() {118 CommonService.errorWrapper(119 DevicesService.removeDevices120 , search ?121 [$scope.removingFilters, filteredDevices.map(function(device) {122 return device.serial123 })124 .join()] :125 [$scope.removingFilters]126 )127 }128 if (askConfirmation) {129 GenericModalService.open({130 message: 'Really delete this selection of devices?'131 , type: 'Warning'132 , size: 'sm'133 , cancel: true134 })135 .then(function() {136 removeDevices()137 })138 }139 else {140 removeDevices()141 }142 }143 $scope.$on('user.settings.devices.created', function(event, message) {144 addDevice(publishDevice(message.device), message.timeStamp)145 })146 $scope.$on('user.settings.devices.deleted', function(event, message) {147 deleteDevice(message.device.serial, message.timeStamp)148 })149 $scope.$on('user.settings.devices.updated', function(event, message) {150 updateDevice(publishDevice(message.device), message.timeStamp)151 })152 initScope()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require("devicefarmer-stf-client");2var client = devicefarmer.createClient({3});4client.publishDevice("deviceID", function (err, res) {5 if (err) {6 console.log("Error while publishing device");7 return;8 }9 console.log("Device published successfully");10});11POST /api/v1/devices/{deviceId}/publish12{13}

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf-client');2var client = new devicefarmer.Client({3});4client.publishDevice('deviceID', function (err, device) {5 if (err) {6 return console.error(err);7 }8 console.log(device);9});10client.unpublishDevice('deviceID', function (err, device) {11 if (err) {12 return console.error(err);13 }14 console.log(device);15});16client.getDevices(function (err, devices) {17 if (err) {18 return console.error(err);19 }20 console.log(devices);21});22client.getPublishedDevices(function (err, devices) {23 if (err) {24 return console.error(err);25 }26 console.log(devices);27});28client.getUnpublishedDevices(function (err, devices) {29 if (err) {30 return console.error(err);31 }32 console.log(devices);33});34client.getDevicesInUse(function (err, devices) {35 if (err) {36 return console.error(err);37 }38 console.log(devices);39});

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarm = require('devicefarmer-stf');2var pubDevice = devicefarm.publishDevice('deviceid');3pubDevice.then(function(result){4 console.log(result);5});6var devicefarm = require('devicefarmer-stf');7var unPubDevice = devicefarm.unPublishDevice('deviceid');8unPubDevice.then(function(result){9 console.log(result);10});11var devicefarm = require('devicefarmer-stf');12var deviceStatus = devicefarm.getDeviceStatus('deviceid');13deviceStatus.then(function(result){14 console.log(result);15});16var devicefarm = require('devicefarmer-stf');17var deviceDetails = devicefarm.getDeviceDetails('deviceid');18deviceDetails.then(function(result){19 console.log(result);20});21var devicefarm = require('devicefarmer-stf');22var deviceList = devicefarm.getDeviceList();23deviceList.then(function(result){24 console.log(result);25});26var devicefarm = require('devicefarmer-stf');27var deviceList = devicefarm.getDeviceList('deviceid');28deviceList.then(function(result){29 console.log(result);30});31var devicefarm = require('devicefarmer-stf');32var deviceList = devicefarm.getDeviceList('deviceid','model');33deviceList.then(function(result){34 console.log(result);35});36var devicefarm = require('devicefarmer-stf');37var deviceList = devicefarm.getDeviceList('deviceid','model','os');38deviceList.then(function(result){39 console.log(result);40});41var devicefarm = require('devicefarmer-stf');

Full Screen

Using AI Code Generation

copy

Full Screen

1var deviceFarmer = require('devicefarmer-stf');2var deviceFarmer = new deviceFarmer();3var device = deviceFarmer.publishDevice("DEVICE_ID");4console.log(device);5var deviceFarmer = require('devicefarmer-stf');6var deviceFarmer = new deviceFarmer();7var device = deviceFarmer.publishDevice("DEVICE_ID");8console.log(device);9var deviceFarmer = require('devicefarmer-stf');10var deviceFarmer = new deviceFarmer();11var device = deviceFarmer.publishDevice("DEVICE_ID");12console.log(device);13var deviceFarmer = require('devicefarmer-stf');14var deviceFarmer = new deviceFarmer();15var device = deviceFarmer.publishDevice("DEVICE_ID");16console.log(device);17var deviceFarmer = require('devicefarmer-stf');18var deviceFarmer = new deviceFarmer();19var device = deviceFarmer.publishDevice("DEVICE_ID");20console.log(device);21var deviceFarmer = require('devicefarmer-stf');22var deviceFarmer = new deviceFarmer();23var device = deviceFarmer.publishDevice("DEVICE_ID");24console.log(device);25var deviceFarmer = require('devicefarmer-stf');26var deviceFarmer = new deviceFarmer();27var device = deviceFarmer.publishDevice("DEVICE_ID");28console.log(device);29var deviceFarmer = require('devicefarmer-stf');30var deviceFarmer = new deviceFarmer();31var device = deviceFarmer.publishDevice("DEVICE_ID");32console.log(device);33var deviceFarmer = require('devicefarmer-stf');34var deviceFarmer = new deviceFarmer();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful