def _editDevice(self): ''' Runs the 'Edit device' dialog for currently selected device. ''' items = self._deviceList.selectedItems() if not items: return dev = devices.get(items[0].text(0)) log.debug("Editing device: %s" % dev) dialog = DeviceConfigDialog(dev) if not dialog.run(): return connect = dialog.params.pop("connect", False) if dev.name != dialog.params["name"]: self._updateConnectionState(False, dev) devices.remove(dev.name) index = self._deviceList.indexOfTopLevelItem(items[0]) self._deviceList.takeTopLevelItem(index) dev = devices.add(type=Device, **dialog.params) self._addDeviceItem(dev) else: address = dialog.params["address"] port = dialog.params["port"] if dev.address != (address, port): self._updateConnectionState(False, dev) devices.update(**dialog.params) self._deviceItems[dev].updateDevice() log.info("Device edited: %s" % dev) if connect: self._updateConnectionState(True, dev)
def _addDevice(self): ''' Runs the 'Add device' dialog. ''' log.debug("Adding new device") dialog = DeviceConfigDialog() if not dialog.run(): return connect = dialog.params.pop("connect", False) dev = devices.add(type=Device, **dialog.params) self._addDeviceItem(dev) log.info("New device added: %s" % dev) if connect: self._updateConnectionState(True, dev)
def testAdd(self): device = devices.add(_DEVICE_NAME, **_DEVICE_PARAS) self.failUnless(device) self.failUnlessEqual(device, devices.get(_DEVICE_NAME))