I've added a button to the action.xml with the goal of making it execute the action when the dialog box is open.
(So a user has the option of running the action while the action dialog is open, like when you hit the "Run" button in a script action.) Is that possible?
This is what this code does...
Gives the user a dialog to select the device created with the plugin from a menu. The first button populates the 2nd menu with all the different states and state values for the selected device. Then there is a textfield where the user can enter a new state value for the state they selected. I'd like the option of running the action within the dialog so the user could update a state, select another state, update, select another state, etc... versus save, execute all, click, edit, select another state, save, execute all, etc.
This is what I have so far...Action.xml:
- Code: Select all
<!-- Experiment Actions -->
<Action id="setAnyState" uiPath="Combo Actions">
<Name>Set Any State</Name>
<CallbackMethod>setAnyState</CallbackMethod>
<ConfigUI>
<Field type="menu" id="setADeviceField" filter="self" devfaultValue="0" tooltip="">
<Label>Room to modify:</Label>
<List class="self" filter="self" method="filterDevices" dynamicReload="false"/>
</Field>
<Field id="buttonConfirmDevice" type="button" tooltip="">
<Label>To Select Device:</Label><Title>CLICK</Title> <CallbackMethod>buttonConfirmDevice</CallbackMethod>
</Field>
<Field type="menu" id="setAnyStateField" defaultValue="0" tooltip="">
<Label>Select State:</Label>
<List class="self" filter="new" method="filterDevStates" dynamicReload="true"/>
</Field>
<Field type="textfield" id="newStateValueField"><Label>Enter New Value:</Label></Field>
<Field id="label" type="label" fontSize="small" fontColor="darkgray">
<Label>You can insert text, a variable substitution %%v:VARIABLEID%% or device state %%d:DEVICEID:STATEKEY%%</Label>
</Field>
<Field id="buttonConfirmNewValue" type="button" tooltip="">
<Label>To Make Change Now:</Label><Title>CLICK</Title> <CallbackMethod>buttonConfirmNewValue</CallbackMethod>
</Field>
</ConfigUI>
</Action>
- Code: Select all
def setAnyState(self, pluginAction, dev):
requestedDev = str(pluginAction.props.get(u"setADeviceField"))
requestedState = str(pluginAction.props.get(u"setAnyStateField"))
substitutedValue = self.substitute(pluginAction.props.get("newStateValueField", ""))
thisRoomDev = indigo.devices[int(requestedDev)]
thisDevName = thisRoomDev.name
thisRoomDev.updateStateOnServer(key=requestedState, value=substitutedValue)
self.debugLog(thisDevName + " . " + requestedState + "has been changed to: " + substitutedValue)
def filterDevices(self, filter, valuesDict, typeId, targetId):
xList =[]
for dev in indigo.devices.iter(filter="com.whmoorejr.my-rooms"):
xList.append(( unicode(dev.id),dev.name))
xList.append(("0","==== off, do not use ===="))
return xList
def buttonConfirmDevice(self, valuesDict, typeID, devId):
return valuesDict
def filterDevStates(self, filter, valuesDict, typeId, targetId):
xList =[]
if len(valuesDict) < 2: return [("0","")]
if "setADeviceField" not in valuesDict: return [("0","")]
if valuesDict["setADeviceField"] in ["0",""]: return [("0","")]
dev = indigo.devices[int(valuesDict["setADeviceField"])]
for state in dev.states:
xList.append((state,state+" ; currentV: "+unicode(dev.states[state]) ))
xList.append(("0","==== off, do not use ===="))
return xList
self.debuglog("filterDevStates" + state + " and currentV: "+unicode(dev.states[state])+ " for " +setADeviceField)
def buttonConfirmNewValue(self, valuesDict, typeId, devId):
self.debugLog("I Pushed the Confirm Button")
#theRoomDev = indigo.devices[int(devId)]
#theRoomName = theRoomDev.name
self.debugLog("Check Variables: devId: " + str(devId) + " typeId: " + str(typeId))
return valuesDict
Any pointers would be greatly appreciated.