replacePluginPropsOnServer vs dev.replaceOnServer

Posted on
Tue Jun 09, 2020 9:35 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

replacePluginPropsOnServer vs dev.replaceOnServer

The difference and overlap of
dev.replacePluginPropsOnServer(props)
vs
dev.replaceOnServer()
is not clear to me

When changing
dev.descripton = "abc"
dev.replaceOnServer()
is required to update

props=dev.pluginProps
props[" xx"] = "abc"
dev.replacePluginPropsOnServer(props)
is required

Question:

1. does dev.replaceOnServer() include dev.replacePluginPropsOnServer(props)
2. are both required when changing both
3. does props ( dev = ... & props=dev.pluginProps) has to be refreshed after a dev.replaceOnServer()

Karl

Posted on
Tue Jun 09, 2020 5:58 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: replacePluginPropsOnServer vs dev.replaceOnServer

Hi Karl,

kw123 wrote:
1. does dev.replaceOnServer() include dev.replacePluginPropsOnServer(props)

replaceOnServer() replaces the entire device instance, which includes everything except states which are merged back in post-replace by the Indigo Server. However, practically speaking you need to use replacePluginPropsOnServer if you change any of the values inside the properties dict. That is because there is no way to modify the plugin properties on a plugin instance except by using that method. Whenever you use dev.pluginProps you are getting a copy (not a reference) of the pluginProps. So for example dev.pluginProps["foo"] = 123 doesn't do anything.

In summary, use replaceOnServer when you modify an attribute of the device instance (dev.name, dev.description, etc.) and use replacePluginPropsOnServer to update the plugin properties dict.

kw123 wrote:
2. are both required when changing both

See answer to Q1 above.

kw123 wrote:
3. does props ( dev = ... & props=dev.pluginProps) has to be refreshed after a dev.replaceOnServer()

No, I believe everything will still be in-sync immediately after the replaceOnServer() call (until something else modifies a property, state, etc.).

Image

Posted on
Wed Jun 10, 2020 10:07 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: replacePluginPropsOnServer vs dev.replaceOnServer

to play this back:
Code: Select all
dev = indigo.devices[123]
props = dev.pluginProps
props["abc"] = "123"
dev.replacePluginPropsOnServer(props)

dev = indigo.devices[123]
dev.description= "xyz"
dev.replaceOnServer()
works fine,
while:
Code: Select all
dev = indigo.devices[123]
props = dev.pluginProps
props["abc"] = "123"
dev.replacePluginPropsOnServer(props)

dev.description= "xyz"
dev.replaceOnServer()
does not?
so when changing dev.description and any other prop I need to get/update dev twice?

Karl

Posted on
Wed Jun 10, 2020 10:28 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: replacePluginPropsOnServer vs dev.replaceOnServer

kw123 wrote:
Code: Select all
dev = indigo.devices[123]
props = dev.pluginProps
props["abc"] = "123"
dev.replacePluginPropsOnServer(props)

dev.description= "xyz"
dev.replaceOnServer()
does not?



Worked fine for me. Note that if you've got the device edit dialog up, it won't dynamically update the notes field - you have to close the dialog then open it back up.

[MODERATOR NOTE]: moved topic to the correct forum.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jun 11, 2020 7:44 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: replacePluginPropsOnServer vs dev.replaceOnServer

Thanks that clarifies it.


Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests