Strange behaviour of updateStateOnServer

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
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
User avatar
Juju
Posts: 108
Joined: Wed Aug 31, 2011 10:16 am
Location: Toulouse - FRANCE

Strange behaviour of updateStateOnServer

Post by Juju »

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 ?
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Strange behaviour of updateStateOnServer

Post by matt (support) »

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
User avatar
Juju
Posts: 108
Joined: Wed Aug 31, 2011 10:16 am
Location: Toulouse - FRANCE

Re: Strange behaviour of updateStateOnServer

Post by Juju »

Hello Matt,

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

Thanks.

Julien
Locked

Return to “Extending Indigo with Plugins and Python”