Acces to thingsboard shared attribute - javascript

i'am trying to call a shared attribute for a device (thingbsoard) with the rule chain so i can apply an if statement on it , but i dont know how to do it , is there anyway that allow me to call attributes in rule chain please ?
this is the example i used , but i'am sure that the get function is wrong .
var shared_att = global.getSharedAttributeValue("threshold");
if (shared_att > 50) {
// Trigger an alarm
var alarm = {
type: "Temperature",
severity: "Critical",
description: "Temperature has exceeded the threshold of 50 degrees.",
status: "Active"
};

Use Originator attributes rule node to fetch any type of attributes.

Related

Can placeholders be used only for Database Events in Firebase and not queries?

Take a look at the following JSON structure:
"Fund_Project_Request" : {
"-LEEy7uxXEeI4AJuePoB" : {
"4ZpTt0rHvjYfKAnCukIlhGpH6kz2" : {
"afds1234" : 2,
"asdf12" : 2
},
"iRfNzDSjFiOADqn3KsG8nNuZEfp2" : {
"afds1234" : 1
}
}
},
Here, if I want to get the values 'afds1234' or 'asdf12' which I'm going to call as 'reward_ids' in an onWrite function, all I have to do is:
exports.manipulateRewards = functions.database.ref('/Fund_Project_Request/{ArtcallID}/{UserID}/{rewardID}').onWrite((change, context) => {
const reward_id = context.params.rewardID;
});
Let's say I want to obtain these reward_ids strings without using the onWrite function. Would I be able to do so with a singleValueEventListener or any other method of querying?
When writing code to query Realtime Database, there are no wildcards. You must know the exact path of the data you're interested in.
Cloud Functions triggers aren't really anything like normal listeners. They are essentially filtering all writes that flow through the system, and triggering only on the writes that match the given path.

refactor capybara javascript dropzone test

I'm trying to call a dropzone capybara test multiple times. However, when I call it a second time, the ID has already been used. I'm trying to randomize the ID so it can run multiple times.
def drop_in_dropzone(file_path)
page.execute_script <<-JS
fakeFileInput = window.$('<input/>').attr(
{id: 'fakeFileInput', type:'file'}
).appendTo('body');
JS
attach_file("fakeFileInput", file_path)
page.execute_script("var fileList = [fakeFileInput.get(0).files[0]]")
page.execute_script <<-JS
var e = jQuery.Event('drop', { dataTransfer : { files : [fakeFileInput.get(0).files[0]] } });
$('.dropzone')[0].dropzone.listeners[0].events.drop(e);
JS
end
Error when calling it 2nd time.
Failure/Error: attach_file("fakeFileInput", file_path)
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching file field "fakeFileInput"
You can definitely just generate a random id number for the input but it might be easier to just only create the fakeFileInput it if doesn't already exist. This would only work if you don't use the input for any other purposes than in this method, but it seems like that's what you're doing.
page.execute_script <<-JS
fakeFileInput = fakeFileInput || window.$('<input/>').attr(
{id: '#{fake_input_id}', type:'file'}
).appendTo('body');
JS
If it did already exist it wouldn't get created again and it would just get reused.

Getting an error with Twitter lib

In Google Apps Script I have this snippet of code in my project to send a tweet (also in jsBin):
function sendTweet(status) {
var twitterKeys= {
TWITTER_CONSUMER_KEY: "x",
TWITTER_CONSUMER_SECRET: "x",
TWITTER_ACCESS_TOKEN: "x",
TWITTER_ACCESS_SECRET: "x"
};
var props = PropertiesService.getScriptProperties();
props.setProperties(twitterKeys);
twit = new Twitter.OAuth(props);
var service = new Twitter.OAuth(props);
if ( service.hasAccess() ) {
var response = twit.sendTweet(status);
if (response) {
Logger.log("Tweet ID " + response.id_str);
} else {
// Tweet could not be sent
// Go to View -> Logs to see the error message
}
}
}
sendTweet("test");
But the problem I'm having is that I get this error:
TypeError: Cannot read property "text" from undefined. (line 293, file "twitter", project "Twitter lib")
Line 293 is from version 21 of the "Twitter lib" library (MKvHYYdYA4G5JJHj7hxIcoh8V4oX7X1M_).
The message "test" actually gets tweeted, despite that error. Does anyone know how to fix it?
Hi, author of Twitter Lib here. #Mogsdad pointed me here over Twitter. I think I know what's going on with your script, and it's a peculiarity of how Google Script works.
You have most of your code in a function that takes an argument, and then you have a call to the function at the top level of your script. What happens, when you go to the "Run" menu and select your sendTweet function, is that the script at the top level gets run before the selected function is executed, and the tweet would be sent at that time with the "test" text.
Then after that, sendTweet gets run with no arguments, meaning the status variable is undefined. You're sending an undefined value into twit.sendTweet(), causing the error you see.
What I'd recommend here is simply wrapping your last line of code into a function so you can call it from the Run menu, like this:
function sendTestTweet() {
sendTweet("test");
}
Just to recap, the error you've seen is:
TypeError: Cannot read property "text" from undefined. (line 293, file "twitter", project "Twitter lib")
That is in the sendTweet() method of the library, see below.
/**
* Upload a tweet to Twitter with optional media.
*
* #param {string | Tweet} tweet the status text to send as a Twitter update
* #param {optional object} params any additional parameters to send as part of the update post
* #return {object} the Twitter response as an object if successful, null otherwise
*/
OAuth.prototype.sendTweet = function(tweet, params) {
var i;
var payload = { //<=== 293
"status" : (tweet.text || tweet)
};
Your code invokes this method with a single string parameter, status, which is set to "test".
The author of the library allowed for the tweet parameter to be one of two things:
It can be an object with a text property containing the message to Tweet, or
It can be a string.
However, the way that's being handled checks for tweet.text first, then if that does not exist it checks for a string tweet. When tweet.text does not exist (i.e. when using just a string), that TypeError is thrown.
I've reached out to the library author so they can publish the fix. However, in the meantime you can send a Tweet object with a text property, or take a copy of the library and update it yourself.
Send Tweet object. The Tweet object is documented in the Twitter API v1.1 documentation, but since the only property involved in this operation is text, a simple change in your status function will do the trick. Just ensure that status is an object with a text property.
function sendTweet(status) {
if (typeof status === string)
status = {text:status};
...
Update the library yourself.
To avoid the error, and handle the parameter options properly, line 294 in the library should be:
"status" : (tweet.hasOwnProperty("text") ? tweet.text : tweet)
Or:
"status" : (typeof tweet === 'object' ? tweet.text : tweet)
You'll need to publish it, and update the library ID in your code, but that should take care of this problem. Once a library update is available, you can switch back.

How to show the number of user stories/test cases by total, pending, complete, in progress, accepted?

So I saw this app for rally on Github:
https://github.com/RallyApps/DefectSummaryMatrix
And I am trying to make the same thing, except for test cases and user stories, instead of defects. How would I go about doing this? I am pretty new into the rally SDK and kind of lost to be honest, so anything you guys can say would help.
I've been looking at the App.html for this, and I think this part is the part I need to pay attention to cause this is where it gets the information about the defects:
var defectQuery = function() {
var selected = releaseDropdown.getSelectedName();
var releaseQuery = '(Release.Name = "' + selected + '")';
var queryObject = [];
queryObject[0] = { key: 'defectStates', type: 'Defect', attribute: 'State' };
queryObject[1] = { key: 'defectPriorities', type: 'Defect', attribute: 'Priority' };
queryObject[2] = {
key: 'defects',
type: 'Defect',
query: releaseQuery,
fetch: 'FormattedID,Name,State,Priority,ScheduleState,ObjectID,Description,owner,DisplayName,LoginName'
};
rallyDataSource.findAll(queryObject, populateTable);
};
How do I modify this to get information about user stories? I think the type field would be called userStory or something like that, but then what would the key and attributes be? I can't find any documentation on this.
See Rally object model in Web Services API documentation.
User stories are called "HierarchicalRequirement" in the WS API. Click on HierarchicalRequirement object in the object model to go over the attributes.
I suggest that you do not use the DefectSummaryMatrix as a starting point. It is a legacy app that is using legacy AppSDK1. Use AppSDK2 instead. There is an example of multi-type object grid here.

How to pass id from one store to be used in another in Sencha touch 2

I have 2 stores, one for events and one for data captured for that event. I am trying to get the id from the events store and use it in the data store. I have the following field in my data model:
{ name: 'eventId', type: 'int' },
My controller fetches the form data, validates it and after this, my code fails. I am trying the following to get the id from the first store and then set it in the second store
var idStore = Ext.getStore('Details');
var id = idStore.findRecord('id');
currentData.set('eventId', newValues.id);
My console returns null for var id, which leads me to believe that my code is wrong, can someone help explain to me how I fetch the id and use it?
Thanks
I figured it out, the docs Docs say to specify the value after the field. All I had to do was to add '1' after the 'id' field.
This does raise some questions though, I have to ensure that my id's always start with '1', does anyone know of a better way?

Categories

Resources