We have moved at community.getvera.com

Author Topic: javascript api  (Read 1328 times)

Offline zoot1612

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 603
  • Karma: +21/-2
javascript api
« on: January 08, 2016, 08:10:51 pm »
I am confused about the way the following api's work , any one give me some clarity? I  also can't get setDeviceState to work at all is this a bug, I did look at bug tracker but couldn't find anything. why are they implemented differently?

Code: [Select]
setDeviceState(deviceId, service, variable, value, options)

setDeviceStatePersistent(deviceId, service, variable, value, options)

setDeviceStateVariable(deviceId, service, variable, value, onSuccess, onFailure, context)

setDeviceStateVariablePersistent(deviceId, service, variable, value, onSuccess, onFailure, context)

So many questions and no answers.

The following does however work: -
Code: [Select]
function setDeviceStateVariable(DEVICE, SID, VARIABLE, VALUE)
{
api.setDeviceStatePersistent(DEVICE, SID, VARIABLE, VALUE,
{
'onSuccess': function()
{
ShowStatus('Data updated', false);
},
'onFailure': function()
{
ShowStatus("Failed to update data. Reload LuuP and try again", true);
}
});
}

Thanks

Offline alex.str

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: javascript api
« Reply #1 on: January 11, 2016, 02:42:29 pm »
1. api.setDeviceState() and api.setDeviceStateVariable() are the same - they set a value for a given device id, service and variable

Ex. (from browser JavaScript console):
> api.setDeviceState(154, 'urn:upnp-org:serviceId:AllControls1', 'MyTestVariable', 'JustAValue');
undefined
> api.getDeviceState(154, 'urn:upnp-org:serviceId:AllControls1', 'MyTestVariable');
"JustAValue"

The value set in this manner will be lost if you refresh the browser.


2. api.setDeviceStatePersistent() and api.setDeviceStateVariablePersistent() are the same - they set a value for a given device id, service and variable; the value will be kept after 'reload'

Ex.:
> api.setDeviceStatePersistent(154, 'urn:upnp-org:serviceId:AllControls1', 'MyBigVariable', 'A persistent one');
undefined
(refresh the browser)
api.getDeviceState(154, 'urn:upnp-org:serviceId:AllControls1', 'MyBigVariable');
"A persistent one"

The value set in this manner will be written to the user_data.