Clearing delayed actions for multiple devices in one command

Posted on
Mon Dec 25, 2023 8:24 pm
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Clearing delayed actions for multiple devices in one command

I've been trying to rationalise and improve a lot of my sprawling python scripts, and I'm not sure if this is possible.

At present I have some action groups that run that have multiple lines for clearing device specific delayed actions, like so:

indigo.device.removeDelayedActions(monitor)
indigo.device.removeDelayedActions(lights)
indigo.device.removeDelayedActions(fan)
etc

I've been trying to find a way to get it into one single line. Most of what I've tried has failed on a syntax error. Closest I can find is:

indigo.device.removeDelayedActions(monitor),(lights),(fan)

but this doesn't seem to remove the delayed actions at all. Is this possible and if so what's the best way to do it?

Computer says no.

Posted on
Tue Dec 26, 2023 7:22 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Clearing delayed actions for multiple devices in one com

I'll answer by saying that you can't, and then show you how you can. :wink:

The command indigo.device.removeDelayedActions only accepts one argument at a time, and then clears all delayed actions from the target device. The command doesn't accept collections of devices (although I believe this feature may be on the list). You can iterate over a collection of devices, which takes a couple of lines--and it's the way I'd recommend doing it because it's more Pythonic.

Code: Select all
device_list = (123456789, 987654321, 234567890)
for item in device_list:
    indigo.device.removeDelayedActions(item)
It's only three lines, and it's easy to see what's going on.

That said, you can use a little Python "trickery" using a List Comprehension, which compacts these operations down to a single line:

Code: Select all
_ = [indigo.device.removeDelayedActions(item) for item in (123456789, 987654321, 234567890)]
Still relatively easy to understand, but the above code is way more obvious. The underscore is a common way to indicate a "toss away" value which is really only necessary to make Python syntax inspectors happy (not required).

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Dec 26, 2023 9:22 am
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Clearing delayed actions for multiple devices in one com

Ooooh perfect! That makes sense. I shall have a play with this later on. Much appreciated!

Computer says no.

Posted on
Wed Dec 27, 2023 10:52 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Clearing delayed actions for multiple devices in one com

Dave, this forum totally need an up vote feature.

Posted on
Wed Dec 27, 2023 11:03 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Clearing delayed actions for multiple devices in one com

ryanbuckner wrote:
Dave, this forum totally need an up vote feature.

Appreciated, but not necessary. I've received a metric ton of help on these fantastic forums and I'm happy to help out when I can.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Dec 30, 2023 7:25 pm
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Clearing delayed actions for multiple devices in one com

Oh and this worked perfectly. And I’ve adapted it for use with a few other lines that were similarly setup! Many thanks!


Sent from my iPhone using Tapatalk Pro

Computer says no.

Posted on
Sat Dec 30, 2023 7:48 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Clearing delayed actions for multiple devices in one com

Glad to help.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests

cron