Creating device groups without using DeviceFactory UI

Posted on
Tue Apr 04, 2017 8:03 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Creating device groups without using DeviceFactory UI

This should be possible now, right? I'm going by this section of the Indigo 7 release notes:

Group management additions

In Indigo 6, we introduce the DeviceFactory pattern which allows your plugin to have a factory like method that creates any number of devices as part of the config process. If your plugin creates multiple devices, those devices are automatically linked together into a device group. However, the only way to manage groups was through the DeviceFactory config UI. You couldn't add/remove devices from the group outside of that dialog. We've now added some arguments to allow you to manage these groups outside of the DeviceFactory UI.

The create() method on the indigo.Device class can now have another argument passed: groupWithDevice. The default value is None (so it won't be grouped with anything), but you may pass an ID of any other device that your plugin manages to have it added to that device's group (or one will be created if the target device isn't already in a group).

Also, we've added another argument to the delete() method on the indigo.Device class: autoDeleteSiblingDevices. The default value is True, but if you pass False then just the device itself will be deleted, but other devices in the device group will be left alone.


I'm trying to add a "subdevice" when the user creates a device. I'm trying to do this here:

Code: Select all
    def closedDeviceConfigUi(self, valuesDict, userCancelled, typeId, devId):
        if not userCancelled:
            if typeId == "masterSensor":
                newdev = indigo.device.create(indigo.kProtocol.Plugin, deviceTypeId="subSensor", groupWithDevice=devId)
                newdev.model = "Custom Sensor"
                newdev.subModel = "Sub Sensor"
                newdev.replaceOnServer()
        return


Both devices get created, but they're not grouped in any way. Not the Edit Device UI, and not in the deletion dialog.

Related question - it appears that the "sub" device type must be defined in Devices.xml. What if I don't want the user to be able to ever create devices of that type directly? Is it possible to have the definition there, but have it be hidden from the Device Type list in the New Device dialog for the plugin?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 05, 2017 8:30 am
matt (support) offline
Site Admin
User avatar
Posts: 20568
Joined: Jan 27, 2003
Location: Texas

Re: Creating device groups without using DeviceFactory UI

Hi Joe,

I think the problem is that the devId argument to closeDeviceConfigUi isn't assigned until after the dialog is closed. It is used (not None or 0) if you are editing a device. You can add a log statement there to check that theory. If that is the case then you can override deviceStartComm and add your logic there. It is called after a new device is created as well. You'll want to make sure your sub device doesn't already exist so it doesn't get duplicated on plugin reload, etc., so I would add an "fullyInitialized" property and use dev.replacePluginPropsOnSesrver() to update it after the secondary devices are created.

If you add a device factory node to Devices.xml, then the device dialog will not show the device type popup. It will, however, show a Define and Sync button which brings up the UI specified by the ConfigUI node (below) – I'm not sure if that will be useful for your case or not. Note it will never show the device types though, so if you are doing a hybrid approach where you want some types to show but not others then we'll need to think about how we can extend it.

Code: Select all
   <DeviceFactory>
      <Name>Define Device Group...</Name>
      <ButtonTitle>Close</ButtonTitle>
      <ConfigUI>
      </ConfigUI>
   </DeviceFactory>

Image

Posted on
Wed Apr 05, 2017 8:58 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Creating device groups without using DeviceFactory UI

matt (support) wrote:
Hi Joe,

I think the problem is that the devId argument to closeDeviceConfigUi isn't assigned until after the dialog is closed. It is used (not None or 0) if you are editing a device. You can add a log statement there to check that theory.


I don't think that's it. Here's some debug output. 523695469 is the "master" device. 142570583 is the "sub" device. The devId is set before closedDeviceConfigUi is called. It does seem odd that the sub device is started, stopped, then started again before the master. Which is also started, stopped, then started.

joe

Code: Select all
   RFPlayer Debug                  Called validateDeviceConfigUi(self, valuesDict, typeId, devId):
   RFPlayer Debug                       (UiValuesDict : (dict)   address : 180 (string), tempHygroSensor, 523695469)
   RFPlayer Debug                  closedDeviceConfigUi(self, valuesDict, userCancelled, typeId, devId):
   RFPlayer Debug                       (UiValuesDict : (dict)   address : 180 (string), False, tempHygroSensor, 523695469)
   RFPlayer Debug                  Called deviceStartComm(self, device): new device 1 (142570583)
   RFPlayer Debug                  new device 1: Device Current Version = 0
   RFPlayer Debug                  Updated new device 1 to version 0
   RFPlayer Debug                  Starting Humidity Sensor device new device 1
   RFPlayer Debug                  Called deviceStopComm(self, device): new device 1 (142570583)
   RFPlayer Debug                  Stopping Humidity Sensor device new device 1
   RFPlayer Debug                  Called deviceStartComm(self, device): new device 1 (142570583)
   RFPlayer Debug                  new device 1: Device Current Version = 0
   RFPlayer Debug                  Updated new device 1 to version 0
   RFPlayer Debug                  Starting Humidity Sensor device new device 1
   RFPlayer Debug                  Called deviceStartComm(self, device): new device (523695469)
   RFPlayer Debug                  new device: Device Current Version = 0
   RFPlayer Debug                  Updated new device to version 0
   RFPlayer Debug                  Starting Temperature/Humidity Sensor device new device
   RFPlayer Debug                  Called deviceStopComm(self, device): new device (523695469)
   RFPlayer Debug                  Stopping Temperature/Humidity Sensor device new device
   RFPlayer Debug                  Called deviceStartComm(self, device): new device (523695469)
   RFPlayer Debug                  new device: Device Current Version = 0
   RFPlayer Debug                  Updated new device to version 0
   RFPlayer Debug                  Starting Temperature/Humidity Sensor device new device

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 05, 2017 9:23 am
matt (support) offline
Site Admin
User avatar
Posts: 20568
Joined: Jan 27, 2003
Location: Texas

Re: Creating device groups without using DeviceFactory UI

Okay, two other possibilities then I believe. Try adding the stub XML (for <DeviceFactory>) from my previous post to your devices.xml. Does that get it to work?

If not, then try moving the device add logic to deviceStartComm (just hack in something for a test). The issue might be that the Indigo GUI is clearing out the device grouping information on the device being created/edited (master in this case).

I do remember testing the new groupWithDevice argument on the create method, but I don't recall under what context I created it. Obviously, I should have spent a bit more time QAing this one...

Image

Posted on
Wed Apr 05, 2017 9:31 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Creating device groups without using DeviceFactory UI

matt (support) wrote:
Okay, two other possibilities then I believe. Try adding the stub XML (for <DeviceFactory>) from my previous post to your devices.xml. Does that get it to work?


Not really. First, I got an error because the <ConfigUI> element must contain at least one <Field> element. I added the menu popup for my available devices list and got past that error. So then I don't get a menu for device type. I do get a popup dialog with the menu on it, but selecting that does nothing because I don't have any of the <DeviceFactory> methods defined.

matt (support) wrote:
If not, then try moving the device add logic to deviceStartComm (just hack in something for a test). The issue might be that the Indigo GUI is clearing out the device grouping information on the device being created/edited (master in this case).


Yeah, that's next.

This is pretty complicated because I have some device types that must have normal config dialogs (like the master interface which has a USB/serial interface), and others like multi-sensors which I might be able to skip the normal config dialog.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 05, 2017 10:58 am
jay (support) offline
Site Admin
User avatar
Posts: 16815
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Creating device groups without using DeviceFactory UI

Your use-case sounds something like the Airfoil Pro plugin and Airfoil Instance and speaker devices. The approach I took was to use a DeviceFactory for the main instance (the DF dialog allows you to select an instance found via bonjour) and a config UI for that same device to allow instance-specific options. When I sync with that instance device, it creates all the necessary speaker objects for that instance (in the same folder as the instance).

Later, if a new speaker device is detected, I just automatically create it again in the same folder as the instance as soon as I see it's there (it's basically called from inside runConcurrentThread). I was never totally satisfied with this because I don't like auto-generated devices, but at the time it seemed the best approach. I think if I redid it now, I'd probably auto create them on the initial DeviceFactory sync and any subsequent define and sync, and perhaps even allow the user to specify which ones to create inside the instance config dialog (have a list of new speakers they can select from or something). In which case I might likely have run into the problem you're seeing.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 05, 2017 12:58 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Creating device groups without using DeviceFactory UI

Creating the sub device in deviceStartComm works.

Now to figure out how to hide the subtypes from the Device Type menu. I think I might have to just define some very basic devices (sensor, relay, etc), and determine the custom UI and behaviors at run time, rather than define all the possible subtypes.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Aug 06, 2020 9:34 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Creating device groups without using DeviceFactory UI

Hi Joe,

FlyingDiver wrote:
Creating the sub device in deviceStartComm works.

Now to figure out how to hide the subtypes from the Device Type menu. I think I might have to just define some very basic devices (sensor, relay, etc), and determine the custom UI and behaviors at run time, rather than define all the possible subtypes.


Did you ever figure out how to hide the subtypes from the Device Type menu?

Posted on
Thu Aug 06, 2020 9:36 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Creating device groups without using DeviceFactory UI

autolog wrote:
Hi Joe,

FlyingDiver wrote:
Creating the sub device in deviceStartComm works.

Now to figure out how to hide the subtypes from the Device Type menu. I think I might have to just define some very basic devices (sensor, relay, etc), and determine the custom UI and behaviors at run time, rather than define all the possible subtypes.


Did you ever figure out how to hide the subtypes from the Device Type menu?


No, I just changed the devices to the final types when I created them.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Aug 06, 2020 9:55 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Creating device groups without using DeviceFactory UI

OK - Thanks. :)

Maybe Matt has a view on if this is possible and if so how?

If it isn't possible (at the moment) I could prevent the submodel being created by the user - it doesn't seem to user friendly though. ;)

I have discovered another "feature" is that when you create a main device and it starts, and within the devStart you create a sub-model, the already open device dialogue that was there from creating a new device, isn't update with the sub-model. You have to close the dialogue and open it again to get the sub-model to display.

How does Indigo know which subModel device is associated with the main model device. When I print the device details for each there is no indication in the properties that I can see. In this instance I don't have a Device factory setup in the devices.xml

At the moment I am storing a cross reference to each in the main and submodel device properties.

Another "feature" is that if you right click on either the model device or subModel device and select dependencies, then you are informed there aren't any. However, if you try to delete either of the devices, you are warned that there is a dependant device. :?

Posted on
Thu Aug 06, 2020 10:16 am
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Creating device groups without using DeviceFactory UI

autolog wrote:
How does Indigo know which subModel device is associated with the main model device. When I print the device details for each there is no indication in the properties that I can see. In this instance I don't have a Device factory setup in the devices.xml


I'm not sure I understand your terminology here. A subModel is a characteristic of a device. It's got nothing to do with a relationship with other devices.

Devices in a device group are peers, they're not main/sub devices. You generally create them by picking a primary device and others are derived from it, but that's not a requirement. Look at how the factory example plugin works.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Aug 06, 2020 11:08 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Creating device groups without using DeviceFactory UI

It's my terminology - apologies. :(

I understand how it works as I have leveraged Factory Devices in my Smappee plugin to good effect.

In this case, we are creating a primary device and when that is started, if the associated other device isn't present then it is created. I appreciate they are both sub-models and viewed side-by-side when you edit either device.

I think my points (excusing terminology) still stand:
  1. It isn't clear to me how Indigo knows the devices are associated i.e. it must know to be able to display them side-by-side. The association is done in the create process but then seems not to be subsequently accessible by the plugin?
  2. On creation of the associated device in the primary device, the Edit Device dialogue doesn't show the associated device until the dialogue is closed and re-opened.
  3. Indigo's dependency logic is inconsistent

I appreciate these questions are more likely to be for Matt to answer. :)

Posted on
Thu Aug 06, 2020 1:35 pm
matt (support) offline
Site Admin
User avatar
Posts: 20568
Joined: Jan 27, 2003
Location: Texas

Re: Creating device groups without using DeviceFactory UI

autolog wrote:
• It isn't clear to me how Indigo knows the devices are associated i.e. it must know to be able to display them side-by-side. The association is done in the create process but then seems not to be subsequently accessible by the plugin?

You can get a list of all the device IDs in a device group by calling this on any instance in the group:
Code: Select all
devIdList = indigo.device.getGroupList(devIdOrInstance)

There is a unique groupId stored in the device instances as well, but that isn't currently exposed via the python API. The above method uses that internal ID though to find all the devices in a group. If there ends up being a need to access the raw groupId then I can easily add it.

autolog wrote:
• On creation of the associated device in the primary device, the Edit Device dialogue doesn't show the associated device until the dialogue is closed and re-opened.

Sounds like a bug, and one that is probably not super easy to fix (the device panel UI is built up when the dialog is first shown and not as dynamic as it needs to be). :roll:

autolog wrote:
• Indigo's dependency logic is inconsistent[/list]

I fixed the Show Dependencies menu item a while back, but I think it was after the last release. Should be better in soon. 8)

Image

Posted on
Thu Aug 06, 2020 1:49 pm
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Creating device groups without using DeviceFactory UI

Thanks for the info Matt. :)

I think The getGroupList will allow us to do what we want.

We will cover the not so dynamic UI in our user docs. :)

Posted on
Fri Aug 07, 2020 8:04 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Creating device groups without using DeviceFactory UI

Hi Matt,
One further question from further up the thread: Is there a way to hide the subtypes from the Device Type menu?

At the moment I have changed deviceStartComm to prevent a particular device starting if it isn't part of a deviceGroup. I put out a message e.g. : "A Touch Portal Dynamic Icon device can only be automatically created by the Touch Portal plugin. Device '<DEVICE NAME>' disabled.".

From a user perspective that is a bit clunky but achieves the objective. :wink:

Who is online

Users browsing this forum: No registered users and 5 guests

cron