I have a device definition (Devices.xml) that has a menu to select from a number of items (other Indigo devices, actually) a list of items already selected, and a couple buttons (add, delete).
- Code: Select all
<Device type="sensor" id="area">
<Name>Occupancy Area</Name>
<ConfigUI>
<Field id="sensorDevice" type="menu">
<Label>Sensor Device to Add:</Label>
<List class="indigo.devices" filter="indigo.sensor"/>
</Field>
<Field id="addDevice" type="button">
<Label/>
<Title>Add Device</Title>
<CallbackMethod>addDevice</CallbackMethod>
</Field>
<Field id="sensorListLabel" type="label" fontColor="darkgray">
<Label>This is the list of sensor devices included in this area.</Label>
</Field>
<Field id="sensorDeviceList" type="list" rows="15">
<Label>Included devices:</Label>
<List class="self" method="sensorDeviceList" dynamicReload="true"/>
</Field>
<Field id="deleteDevices" type="button">
<Label/>
<Title>Delete Devices</Title>
<CallbackMethod>deleteDevices</CallbackMethod>
</Field>
</ConfigUI>
</Device>
The items selected must be persistent, so they get saved in the pluginProps. Which should happen in pluginProps['sensorDeviceList']. right?
The menu popup works fine. And I'm ignoring the deleteDevices callback for now. I just can't seem to get addDevice to work. I should just be able to add the device selected in the sensorDevice popup to the sensorDeviceList, shouldn't I?
- Code: Select all
def addDevice(self, valuesDict, typeId=None, devId=None):
self.logger.debug(u"addDevice called, devId={}, typeId={}, valuesDict = {}".format(devId, typeId, valuesDict))
valuesDict['sensorDeviceList'].append(devId)
self.logger.debug(u"addDevice returning, valuesDict = {}".format(valuesDict))
return valuesDict
- Code: Select all
def sensorDeviceList(self, filter="", valuesDict=None, typeId="", targetId=0):
self.logger.debug(u"sensorDeviceList called with filter: {} typeId: {} targetId: {} valuesDict: {}".format(filter, typeId, targetId, valuesDict))
if not targetId: # no device specified
self.logger.debug(u"sensorDeviceList returning, no targetId")
return []
# get the saved list of sensor IDs
sensorList = valuesDict['sensorDeviceList']
if not sensorList:
self.logger.debug(u"sensorDeviceList returning, no sensorDeviceList")
return []
self.logger.debug(u"sensorDeviceList sensorList = {}".format(sensorList))
sensors = [
(sensorID, indigo.devices[sensorID].name)
for sensorID in sensorList
]
return sensors
Like I said, I'm probably forgetting something incredibly basic, and just not seeing it. These UI callbacks always give me grief. Sigh.