public override IDevice createNewInstance(DeviceMetadata m, IDevice parent) { if (m.Type == NanoleafDevice.NANOLEAF_DEVICE_TYPE_NAME) { NanoleafDevice d = new NanoleafDevice(Guid.NewGuid().ToString()); d.Name = "new Nanoleaf Panel"; d.DeviceType = (EDeviceType)Enum.Parse(typeof(EDeviceType), m.Model); //Find the next ID if possible var lamps = org.dmxc.lumos.Kernel.Project.DeviceManager.getInstance() .Devices.OfType <NanoleafDevice>().Where(c => c.DeviceType.Equals(d.DeviceType)).Select(c => c.PanelID); var firstid = NanoleafPlugin.getAllPanels(d.DeviceType).Select(p => p.ID) .Except(lamps) .FirstOrDefault(); if (firstid != 0) { d.PanelID = firstid; return(d); } return(d); } throw new NotSupportedException("Unable to create a Device for Type: " + m.Type); }
private void setInstance() { this._instance = NanoleafPlugin.getAllPanels(this.deviceType).FirstOrDefault(p => p.ID.Equals(this.panelId)); NanoleafPlugin.getControllers().ForEach(c => c.PanelAdded -= PanelAdded); NanoleafPlugin.getControllers().ForEach(c => c.PanelRemoved -= PanelRemoved); if (this._instance == null) { NanoleafPlugin.getControllers().ForEach(c => c.PanelAdded += PanelAdded); } else { NanoleafPlugin.getControllers().ForEach(c => c.PanelRemoved += PanelRemoved); } }