tiqi-group / pydase

A Python library for creating remote control interfaces of Python objects.
https://pydase.readthedocs.io
MIT License
2 stars 1 forks source link

Setter functions being called at startup when loading json file #46

Closed Iucimhub closed 1 year ago

Iucimhub commented 1 year ago

Is your feature request related to a problem? Please describe. It seems like pydase calls property setter functions when the app is restarted and previous values are loaded from the json file containing old values. This is problematic if for instance the variable controls the temperature of a fridge: The user may have used other means to change the temperature and would not like to revert the temperature to old values.

Describe the solution you'd like Use only getter functions at start up and not setter functions.

mosmuell commented 1 year ago

Would you rather like to have the getter function called when the service starts? Should this behaviour be the same for all properties or only "specified" ones?

Iucimhub commented 1 year ago

I think for most cases (i.e. a lab environment, where every device which has their own memory) it makes sense to call the getter instead of the setter. I can imagine that their are 'dumb' devices without own memory or which die when the service dies, but that seems to be the clear minority of use cases. I can't give you a good real world example of such a dumb device.

mosmuell commented 1 year ago

There might be several options to handle this:

  1. Implement a whitelist / blacklist of attributes that will be saved and restored This approach might make it complicated to define the attributes when its part of an instance within a list or a dict or so.
  2. Use a decorator to not store the value in the settings file / use the setter when reading from the settings file. This approach might make the property logic more difficult in pydase. I will have to look into this...
mosmuell commented 1 year ago

I think the following approach makes sense:

pydase will not set properties unless specified through a decorator like @load_from_json.