a "device" in my plugin has empty states that are filled with either text, a variableID or statekey from another device. As an example, the device "Bill's Office" has a statekey, "mainLight" which reflects the state of the actual light in my office.
Currently, I can create an action that will populate Bill's Office:mainLight with On or Off. It will update the plugin whenever the action is called because the statekey only sees the string substitute of "%%d:937130354:onOffState%%".
I would like it to stay updated, but don't want to kill indigo with too much stuff in a run concurrent thread (Which I've never written before... baby steps. )
My thought is to add some metadata lines with the code that updates the states where "newValue" is the entered text (not substituted)
- Code: Select all
newProps = thisRoomDev.pluginProps
metaDataItem = "meta_"+requestedState
newProps[metaDataItem] = newValue
thisRoomDev.replacePluginPropsOnServer(newProps)
- Code: Select all
def runconcurrent bla bla bla(stuff):
xList =[]
for dev in indigo.devices.iter(filter="com.whmoorejr.my-rooms"):
accentLightMD = self.substitute(dev.pluginProps[meta_accentLight])
mainLightMD = self.substitute(dev.pluginProps[meta_mainLight])
otherDeviceMD = self.substitute(dev.pluginProps[meta_otherDevice])
key_value_list = [
{'key':'accentLight', 'value':accentLightMD},
{'key':'mainLight', 'value':mainLightMD},
{'key':'otherDevice', 'value':otherDeviceMD}
]
dev.updateStateOnServer(key_value_list)
My questions are...
Will this work?
Is there a better way?
Can you "self.substitute(dev.pluginProps...."?
Last thing... some states I would expect to change all the time... Lights, Motion Sensors, etc. Some will probably never change, roomName, floorLevel, buildingName. Either way, even though this could be updating stuff continually in the background, if that's too taxing on the server, the other option is to create an "Update all states" action that could be put on a control page so as you flip through rooms, you could click a button to get an updated status.... that wouldn't be ideal, but better than nothing if it shouldn't be a continual update thing.