Help Sorting Dictionary

Fast dirty way to adjust your current code to sort:
Add import operator to the top of your code
After your for loop that adds the items to alarms put:

alarms.sort(key=operator.itemgetter('device'))

That will run through your alarms list and sort by the item key 'device'. That will get you working 'for now'™

Some side notes:

  • You are making multiple single tag calls to system.tag.readBlocking, It's more efficient to do a single call with multiple tag paths.

  • You first define alarms as the result from a call to system.alarm.queryStatus, but then later define it as a list that you are putting data into. Avoid reusing the same variable name in the same function, instead choose different variable names that can still clearly articulate what data it holds. In this case the second alarms could be something like repeaterAlarmList or similar (I suck with variable names too)

2 Likes