Strange behaviour of updateStateOnServer

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Mon Dec 17, 2012 9:42 am
Juju offline
User avatar
Posts: 108
Joined: Aug 31, 2011
Location: Toulouse - FRANCE

Strange behaviour of updateStateOnServer

Hello,

In a custom plugin, I have a method reading a state value for targeted device, doing some things modifying this value, and at the end updating the device state with the new value. It looks like this :
Code: Select all
def selectZone(self, action, dev):
      activeZone = dev.states[u'activeZone']
      ... some very interesting things ...
      dev.updateStateOnServer("activeZone", value=targetZone)


It works perfectly if I launch once the selectZone action, or if I launch twice manually, but if I do an action group calling twice this action, it seems the state is updated only when the second call is finished ...

Is it normal ?

Posted on
Mon Dec 17, 2012 9:50 am
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: Strange behaviour of updateStateOnServer

It should update every time. I think the problem might be that the dev argument passed into selectZone might be the same device for both actions in the group. That is, when it is called a second time the copy of dev sent to function has not yet been updated by the server so it has the exact same attributes as the first time selectZone is called.

Try adding this call to the top of method definition:

Code: Select all
dev.refreshFromServer()


Does that fix the problem?

Image

Posted on
Mon Dec 17, 2012 2:45 pm
Juju offline
User avatar
Posts: 108
Joined: Aug 31, 2011
Location: Toulouse - FRANCE

Re: Strange behaviour of updateStateOnServer

Hello Matt,

You are right, the device is the same for the two calls to selectZone.
And dev.refreshFromServer() solve my problem !

Thanks.

Julien

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests