New States for an Existing Device

Posted on
Mon Mar 05, 2018 8:26 pm
dgarozzo offline
Posts: 116
Joined: Jan 08, 2009

New States for an Existing Device

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?

Posted on
Mon Mar 05, 2018 9:13 pm
Colorado4Wheeler offline
User avatar
Posts: 2680
Joined: Jul 20, 2009
Location: Colorado

Re: New States for an Existing Device

Try this and it will update it

Code: Select all
dev.stateListOrDisplayStateIdChanged()

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Tue Mar 06, 2018 6:51 pm
dgarozzo offline
Posts: 116
Joined: Jan 08, 2009

Re: New States for an Existing Device

Thanks! That did the trick!

Posted on
Sun Apr 08, 2018 10:04 am
howartp offline
Posts: 3291
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: New States for an Existing Device

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?

Posted on
Sun Apr 08, 2018 10:38 am
Colorado4Wheeler offline
User avatar
Posts: 2680
Joined: Jul 20, 2009
Location: Colorado

Re: New States for an Existing Device

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.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Sun Apr 08, 2018 10:42 am
Colorado4Wheeler offline
User avatar
Posts: 2680
Joined: Jul 20, 2009
Location: Colorado

Re: New States for an Existing Device

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.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Sun Apr 08, 2018 3:45 pm
matt (support) offline
Site Admin
User avatar
Posts: 18459
Joined: Jan 27, 2003
Location: Texas

Re: New States for an Existing Device

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.

Image

Posted on
Sun Apr 08, 2018 3:48 pm
howartp offline
Posts: 3291
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: New States for an Existing Device

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

Posted on
Sun Apr 08, 2018 4:07 pm
howartp offline
Posts: 3291
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: New States for an Existing Device

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

Posted on
Sun Apr 08, 2018 5:38 pm
matt (support) offline
Site Admin
User avatar
Posts: 18459
Joined: Jan 27, 2003
Location: Texas

Re: New States for an Existing Device

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.

Image

Posted on
Mon Apr 09, 2018 3:03 am
howartp offline
Posts: 3291
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: New States for an Existing Device

Ah right, makes sense!

Peter


Sent from my iPhone using Tapatalk Pro

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests