Issues with getSettings

Im building my first App and trying to figure things out. I need the user to enter email, password and APIkey to use later when connecting to the Device.

Wanted to make things as easy as possible and thought Advanced Settings in Devices was the most easy way to get data from the user without having to build to much code.

So added the needed code for the user to enter the information in Advanced Settings after adding a device. So far everything works just fine.

But then my problems start…

In the Devices.js under async onSettings I do this:

let settings = this.getSettings();
this.log("email = ",;
this.log("password = ",settings.password);
this.log("APIkey = ",setting.APIkey);

What comes out in the log are a bit surprising, it shows the default values of email, passord and APIkey. If I then again goes in and changes some of the settings and press Save the log shows me the values I put in the first time…

Anyone with any good tip on what is the cause of this? Why are the this.getSettings giving me the old/previous values and not the current values?

onSettings() is called before the settings are changed. The purpose of this method is to allow an app to check if the settings are correct before allowing them to be changed.

The method gets passed an “event” object as argument with the following properties:

  • oldSettings: the previous (or rather, current) settings
  • newSettings: the new settings (the ones that will be set)
  • changedKeys: an array with the names of the settings that were changed (so if a user only changed their e-mail address, changedKeys will equal [ "email" ]).
1 Like

Ahhh so I can “pull out” the new settings from the changedKeys, validate and use them?

Then as discussed in many other threads it can surely be discussed that this isn’t a good and safe method to use as sensitive variables are stored in an insecure way in my method…

So long term for the App I will look at other options, this is just what will be used in the initial development phase of the App to get the basic function working.

There are no truly safe ways to store data on Homey. You can improve it slightly by encrypting the data before storing it, but you then need to either store the encryption key or ask the user to enter it each time the data is required, which then begs the question of why store the data :wink:
HP2023 local backups effectively allows anyone to view all the code and data of every app.

1 Like

@Adrian_Rockall true… will see what I eventually end up with doing once I have a working App.