matt (support) wrote:Yes, I would keep a device property that is the version of the instance. If you then add or change the properties or states in an update, then you would update the version constant hard coded in the plugin. The startComm method would then check to see if the device instance is a legacy/older one compared to the hard coded constant, in which case it can call stateListOrDisplayStateIdChanged() and do any other needed updating (including bumping the version number to the newest one).
kw123 wrote:could you expand on versioning? how do you do it and how does it work ...
kCurDevVersCount = 4
inside deviceStartComm:
instanceVers = int(dev.pluginProps.get('devVersCount', 0))
if instanceVers >= kCurDevVersCount:
return # optimization: bail out since dev is already up-to-date
if instanceVers < 1:
# make changes to device to get it up to version 1, including calling stateListOrDisplayStateIdChanged if needed.
if instanceVers < 2:
# make changes to device to get it up to version 2, including calling stateListOrDisplayStateIdChanged if needed.
if instanceVers < 3:
# make changes to device to get it up to version 3, including calling stateListOrDisplayStateIdChanged if needed.
if instanceVers < 4:
# make changes to device to get it up to version 4, including calling stateListOrDisplayStateIdChanged if needed.
# now that it is up-to-date, change the version property to the latest
props = dev.pluginProps
props["devVersCount"] = kCurDevVersCount
dev.replacePluginPropsOnServer(props)
DaveL17 wrote:I guess I'm not understanding this fully. Is stateListOrDisplayStateIdChanged() completely rebuilding each device instance whether it needs to or not, or is it only making changes where there are differences between the instance and Devices.xml? I was thinking that the method would load the props from the xml file and compare that to what was presently in the device's props.
Regardless, I'm going to reduce the way I rely on this method since it seems to be using more horsepower than I realized.
matt (support) wrote:It doesn't destroy and re-instantiate the device. It just tells the Indigo Server that the state list might have changed, so Indigo re-queries the plugin for the state information (found in the devices.xml file). For that there is some interprocess communication that has to occur between the plugin -> server -> plugin and then back the other direction. It is generally fast, but still worth adding some logic to only call it in deviceStartComm if the state list (devices.xml) has really changed. Note it doesn't do anything with the device's pluginProps – only the states.
Users browsing this forum: No registered users and 1 guest