Scrounger / ioBroker.linkeddevices

Create linked objects (datapoints) of your devices with a self-defined structure. This makes it possible to create a structure in ioBroker, where all objects are centralized, e.g. to be used in the vis or scripts.
https://forum.iobroker.net/topic/22301/neuer-adapter-linkeddevices
MIT License
17 stars 11 forks source link

Custom object properties deleted on adapter restart #25

Closed algar42 closed 4 years ago

algar42 commented 5 years ago

Describe the bug
It looks like on restart adapter recreate all linked objects from scratch and removes all the custom properties that were added to objects by other adapters.

To Reproduce
For example, I have couple of objects for thermostat which are linked as: image

when I add this two temperature objects to IoT adapter to create GH thermostat, IoT adds some properties to the linked object: image

but when adapter is restarted the object properties are copied back from original states: image

Expected behavior
Is it possible to make adapter keep the changed object properties instead of copy them from original object each time adapter is started? i.e. copy on first creation and then keep untouched until update is manually requested (e.g. this could be a button in adapter settings to "re-link" particular state and drops all the settings made.

Versions:

Scrounger commented 5 years ago

The described behaviour is absolut correct. To solve this problem you must remove all custom settings from the original dp (...ch1.desiredTemp). Then create a linkedObject from this dp and set all custom only to the linkedObject. After restart it will not overwrite anymore because original objects has no custom attribute "smartName".

algar42 commented 5 years ago

Yes, I see. But some adapters, e.g. Mihome, have some pre-defined properties that I can't remove. e.g. when almost any adapter creates object the empty Native property is also created: image I can't affect this as this is under control of adapter of original state. But I want to add something like: native: {"alarmText": "Test Text"} into the linked object. Unfortunately in is not possible, as it will be deleted on next LinkedDevices adapter start. The same thing could happen with SmarName property - some of the adapters, e.g. IoT, Cloud, Lovelace etc. could add something like "smartname": false to the original object properties automatically, and it is Ok, as it states that we don't want to include this object into any Smart Devices (GH, Alexa etc.), but at the same time we want to add linked object as a smart device, and in this case we need to have the ability to override the original property and keep it unchanged. Do you agree?

thansk

Scrounger commented 5 years ago

Ah ok, now I understand the problem. Unfortunately, at the moment i do not have a good idea how to do that.

One solution I see in it, is to add a parameter 'dont overwrite on restart' to the linkedObject. if this is set, i can use the 'ObjectNotExists' method, so it will not be overwritten. But with this the disadvantage is, that linkedObject will never get any changes from the parentObject, for example if a new version of an adpater release and something changed on the attributes.

Better solution could be a list of custom / native atrributes that should be ignored, but the implementation is a bit tricky ;)

algar42 commented 5 years ago

I think at least for now it would be great to add at least 'don't overwrite on restart' checkbox to the adapter settings. As another solution, is it possible to merge original and linked object on restart and take only properties from original that are not exist in linked? I.e. take linked object as a priority. I understand that this could cause some other issues, which will need to be looked at, but it seems to me that such approach will be better anyway. Currently, say, I've lost about 15 virtual GH devices I did manually in IoT adapter after restart of Iobroker. :) Now afraid to create them again.....

Scrounger commented 5 years ago

You right, merging would be the best solution. There exist a merge function 'extendObject' - i will give it a try.

Scrounger commented 4 years ago

I added a new setting to the custom dialog, where you can set that on restart adapter the linkedObject will be merged instead of overwritten: grafik

This feature is implemented in the actual master branch (7471c3fe708713bcff1328886bdd3847dd4c2799)

Please test it and give a feedback.

algar42 commented 4 years ago

Sorry, I switched all my devices to new Alias feature of js-controller 2.0 and do not use linkedDevices anymore. :(

Scrounger commented 4 years ago

... now we have a new feature