New states not added in off devices

Posted on
Thu Nov 16, 2017 11:33 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

New states not added in off devices

I have some devices that are sensor types for each zone in the nx alarm system
They are set to on/off when the alarm system sends zone status.

I wanted to add a state( device.xml). When the device is off indigo does not add the new states to the devices when I reload the plugin. When the devices are on it does add the new states.
Some of the states I don’t want to set to on ( eg fire). Others I can just open the door and restart the plugin then it adds the new states.

Only other solution is to delete and recreate the devices.

Is this correct and is it on purpose or an accident?

Karl.


Sent from my iPhone using Tapatalk

Posted on
Fri Nov 17, 2017 11:32 am
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: New states not added in off devices

You'll want to have your plugin call:

dev.stateListOrDisplayStateIdChanged()

That forces Indigo Server to pull in the new Devices.xml state information. The way I use it is to have a version counter in the device's pluginProps, then when that device has its start communication method called I check to see if it is an older version that needs to be updated, in which case I call the method above (and then update the version counter so it doesn't get called again on next start comm).

Image

Posted on
Sat Nov 18, 2017 9:00 am
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: New states not added in off devices

ok thanks, that helps.. anything against running at start of plugin like this:
Code: Select all
    def startup(self):
        self.initDevs = True
...
    def deviceStartComm(self, dev):
        if self.initDevs:
            dev.stateListOrDisplayStateIdChanged()
...

    def runConcurrentThread(self):
        self.initDevs = False
...


A related question: is there a way to check if
def deviceStopComm(self, dev):
is called in the normal plugin state (open device/save etc) or if it is called when the plugin stops. I would like to do different things when the plugin stops.


Thanks

Karl

Posted on
Sun Nov 19, 2017 5:49 pm
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: New states not added in off devices

It would be slightly preferred to only call it once on the device after the states have been added. Doing so requires the overhead of tracking a device structure version (via a pluginProps), but there is some overhead in what the IndigoServer has to do when it is rebuilding the state table (as the result of the stateListOrDisplayStateIdChanged() call). It is not essential that you change the approach though.

Regarding deviceStopComm, I think you could add another plugin attribute (self.shuttingDown = True) as the last line of runConcurrentThread(), then check that inside of deviceStopComm to differentiate between the different cases?

Image

Posted on
Sun Nov 19, 2017 10:45 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: New states not added in off devices

ok thanks, I did not know when deviceStopComm was called, when indigo shuts down.

As the "deviceDeleted" is depreciated here my next Q: in order to distinguish between delete and stop one has to check if device still exists.
In deviceStopComm after delete does the device still exist when deviceStopComm is called?

Karl

Posted on
Tue Nov 21, 2017 12:12 pm
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: New states not added in off devices

I'm not sure if it exists or not (without digging into the code), but if you really need to know when the device is deleted then I would use deviceDeleted(). It is deprecated in the sense that we strongly encourage just using the start/stopComm hooks if at all possible, but isn't deprecated in the sense that we are planning on removing it anytime soon. Just make sure you call the parent class method inside your implementation.

Image

Posted on
Tue Nov 21, 2017 12:29 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: New states not added in off devices

Why do you want to delete deviceDeleted()? It is very useful.


Sent from my iPhone using Tapatalk

Posted on
Tue Nov 21, 2017 12:39 pm
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: New states not added in off devices

Because from a functional perspective why/when/how a device is "halted" shouldn't matter in most cases. There are several reasons a device should have it communication stopped: user choses to disable it, plugin stops, server stops, device is deleted, etc. In most cases it shouldn't matter what caused the halt from the plugin's perspective, all that should matter is the plugin needs to know that the device should be taken offline. So we want to encourage plugin developers to use those 2 hooks (stop/startComm) as the primary way to handle all those use cases if at all possible. If your plugin really needs to know when a device is created/deleted (and I can think of some reasons why this would be useful), then you can use deviceDeleted().

Image

Posted on
Tue Nov 21, 2017 4:18 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: New states not added in off devices

Here scenario / cases

There is a difference if a device gets started stopped or paused or modified:
Code: Select all
start stop source          action                  possible actions to device
at plugin start:           start device        ==> init, reset, load params
at plugin stop:            stop device         ==> stop devices, shutdown

while running:
device can be paused:      disable/enable      ==>  keep it running, just don't do anything
device can be modified:    edit device         ==>  new parameters for e.g. channels, offsets etc, no need to restart ..
device can be deleted:     by user, or plugin, ==>  stop device action, shutdown


In some of my plugins they are managing many devices. They send updates on a frequent basis from different sources (e.g. each RPI can send updates for each beacon: 10RPI *20beacons every 30 secs =~ 10 loops/sec through all plugin devices ) Each time a messages gets received the plugin needs to determine which indigo device it is
In order to do that it keeps a matching table ( e.g. MAC# to indigo ID) , instead of for each message looping through ALL plugin devices and trying to find a match
To keep this in sync the plugin needs to know if a device is active/paused/ deleted.
currently the only way I found to be reliable is to do a sync once every 1-2 minutes and to refresh the machting table physical device - indigo ID and catch exceptions if a device was deleted


So it would be nice if there is a ongoing supported way to know if a devices is active/deleted/ stopped/ active/ paused..
==> really missing is deleted.
-- paused: dev.enabled OK
-- plugin init: check variable set at startup and reset when entering runConcurrentThread OK
-- plugin stop: just learned you can set variable at the end of runConcurrentThread OK
-- device deleted was device deleted(), but set to be removed in the future. ??

Karl

Posted on
Tue Nov 21, 2017 10:04 pm
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: New states not added in off devices

kw123 wrote:
-- device deleted was device deleted(), but set to be removed in the future.

I think you are misunderstanding me. Above I said we don't have intention of removing it, and that it is safe to be used we just discourage it unless you absolutely need it.

Image

Posted on
Tue Nov 21, 2017 10:12 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: New states not added in off devices

ok thanks, all settled

Karl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest