Page 1 of 1

New States for an Existing Device

PostPosted: Mon Mar 05, 2018 8:26 pm
by dgarozzo
If I have a Device that I have already created, and I update my plugin to add additional States to it, do I have to delete the Device and re-create it? Or can I add the new States dynamically?

Re: New States for an Existing Device

PostPosted: Mon Mar 05, 2018 9:13 pm
by Colorado4Wheeler
Try this and it will update it

Code: Select all
dev.stateListOrDisplayStateIdChanged()

Re: New States for an Existing Device

PostPosted: Tue Mar 06, 2018 6:51 pm
by dgarozzo
Thanks! That did the trick!

Re: New States for an Existing Device

PostPosted: Sun Apr 08, 2018 10:04 am
by howartp
I was about to ask exactly the same question as I couldn't find the code (I knew it existed) but I then found this thread only a month old.

However I'm still getting:

Code: Select all
2018-04-08 17:01:13.498   Z-Wave Scene Controller Error   exception in deviceStartComm(Dummy STudy Remote): 'key repeatDelay not found in dict'
2018-04-08 17:01:13.507   Z-Wave Scene Controller Error   exception in deviceStartComm(Dummy ZRC90 Bed): 'key repeatDelay not found in dict'


My code is thus:

def deviceStartComm(self, dev):
if (dev.deviceTypeId == "sceneController"):
dev.stateListOrDisplayStateIdChanged()
devID = dev.id
zedID = dev.ownerProps['deviceId']
nodeID = indigo.devices[int(zedID)].ownerProps['address']

repeatDelay = dev.ownerProps['repeatDelay']

self.delayFromNode[int(nodeID)] = int(repeatDelay)

I've just added repeatDelay to my devices.xml and it works when I edit and re-save a device, but this error occurs for any I haven't edited?

Re: New States for an Existing Device

PostPosted: Sun Apr 08, 2018 10:38 am
by Colorado4Wheeler
You shouldn't need anything more than the 'dev.stateListOrDisplayStateIdChanged()', that should update the device to have all the new states - then you would still need to give those new states a value, otherwise if your plugin calls the state looking for a value it's going to get the default instead of what it wants.

Re: New States for an Existing Device

PostPosted: Sun Apr 08, 2018 10:42 am
by Colorado4Wheeler
And there's no harm in just running that on deviceStartCom for every device, I do it on all of my plugins so I never have to worry about it.

Re: New States for an Existing Device

PostPosted: Sun Apr 08, 2018 3:45 pm
by matt (support)
howartp wrote:
I've just added repeatDelay to my devices.xml and it works when I edit and re-save a device, but this error occurs for any I haven't edited?

Are you sure the device type ID is "sceneController?" Add some indigo.server.log() calls before/after the call to stateListOrDisplayStateIdChanged() just to see if it is really getting to that call.

Re: New States for an Existing Device

PostPosted: Sun Apr 08, 2018 3:48 pm
by howartp
It’s definitely being called.

I’ve added ownerProps.get(repeatDelay,0) and it’s cleared up, so must be what C4W said about not-set values?


Sent from my iPhone using Tapatalk Pro

Re: New States for an Existing Device

PostPosted: Sun Apr 08, 2018 4:07 pm
by howartp
Having said that, all I’ve done there is circumvented the issue as I’ve still not ‘got’ a repeatDelay in those existing device dicts which I should have.

The deviceStartComm() hasn’t changed since I launched the plugin, except for today, and the whole plugin references a bunch of other lines which I actually snipped out of the post above, but still inside the if: statement.


Sent from my iPhone using Tapatalk Pro

Re: New States for an Existing Device

PostPosted: Sun Apr 08, 2018 5:38 pm
by matt (support)
Ah yes, sorry I thought you were adding a device state (not a property). The stateListOrDisplayStateIdChanged() call only gets the states added to the device and doesn't help with properties. For properties as you've noted the default values only get set when the settings dialog is shown/accepted, so you do need to use the get(key, default) method. I agree that ideally Indigo would get the props from the XML file but currently those are strictly used (read) only by the UI code when it is about to show the settings dialog.

Re: New States for an Existing Device

PostPosted: Mon Apr 09, 2018 3:03 am
by howartp
Ah right, makes sense!

Peter


Sent from my iPhone using Tapatalk Pro