tutorials:addingbatterychanged
Differences
This shows you the differences between two versions of the page.
Last revisionBoth sides next revision | |||
tutorials:addingbatterychanged [2018/04/11 16:51] – created James Sentman | tutorials:addingbatterychanged [2018/04/11 17:27] – created James Sentman | ||
---|---|---|---|
Line 2: | Line 2: | ||
By combining the [[xtension_manual: | By combining the [[xtension_manual: | ||
+ | |||
+ | ====Use A Group==== | ||
+ | |||
+ | Adding the contextual handler to each unit would be a pain, luckily we can use a Group since all such events flow upwards from the Unit’s ON script and if not handled there then it will get sent to every group that the Unit is a member of. So we only need to write this code in one place. | ||
+ | |||
+ | Create a new Group and add all your battery operated devices into it. Make sure to check the “ignore clicks” checkbox so that an errant click on this in a list won’t turn every single motion sensor in your home on at once. | ||
+ | |||
+ | |||
+ | {{ : | ||
+ | |||
+ | ====The Script==== | ||
+ | {{ : | ||
+ | |||
+ | Whenever a contextual interface is going to be opened, either as a contextual menu or as a Detailed Unit Controls window being opened a handler in the Unit’s On script is run to see if the Unit wants to show any extra functions to the user. If the On script of the unit doesn’t return True from the handler, or if there is no handler, then the event will also be sent to every Group that the Unit is a member of. When the handler in the Group is run the value of [[dictionary: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | < | ||
+ | |||
+ | on getContextualHandlers() | ||
+ | return {“Set Battery Changed Date”} | ||
+ | end getContextualHandlers | ||
+ | |||
+ | on setBatteryChangedDate() | ||
+ | |||
+ | write log “A new battery has been installed for unit “ & (thisUnit) | ||
+ | | ||
+ | Set Unit Property “battery changed” to (current date) | ||
+ | | ||
+ | end setBatteryChangedDate | ||
+ | |||
+ | </ | ||
+ | |||
+ | Since the default of the [[dictionary: | ||
+ | |||
+ | |||
+ | ====Customizing Your List==== | ||
+ | |||
+ | In a list that contains the same Units, control click or right click on the headers of the list. Select “Insert Custom Column” and the [[xtension_manual: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | The Header Text field is the name you’d like to display in the Headers of the List. The Unit Property Name needs to be exactly the same as what you set in the Set Unit Property command of the script above. In the examples case thats “battery changed” | ||
+ | |||
+ | Make sure to check the “property is a date” checkbox as well. That will make the date properly display and be sortable both in the App and in the Web Interface. | ||
+ | |||
+ | Click OK and resize or re-arrange your new column so that it’s most useful to you. | ||
+ | |||
+ | ====Results==== | ||
+ | |||
+ | The resultant List window in the App in front and the same list being displayed in the Web Interface behind. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | ====History==== | ||
+ | * The ability to create custom columns was added to XTension in version 9.4 | ||
+ | * Contextual handlers on the web interface and in the Detailed Unit Controls window were added in version 9.4 | ||
+ | * Contextual menu handlers only in the App have been around forever. | ||
+ |
tutorials/addingbatterychanged.txt · Last modified: 2023/02/13 14:52 by 127.0.0.1