Dynamic loading of settings


#1

Hello all, I haven’t posted here in a while, but I have an issue that I am hoping someone can help with.

I am developing a skill located at moviemaster (use the dev branch), and I need to check for an API key entered at mycroft home. Getting the setting, and having an error check for it is relatively simple. BUT, I need it to check if one has been entered before one of the intents is used. As of now, after one is entered, the mycroft instance has to be restarted before my skill knows it has been entered.

I am looking for a way to check automatically without calling code to do so with each intent.

If this is not explained well, please ask and I will try to explain better.


TMdB skill - testing please
#2

You can use self.settings.set_changed_callback to register a callback function, e.g. on_websettings_changed, that is called when the settings at mycroft home have changed:

def initialize(self):
    # ...
    self.settings.set_changed_callback(self.on_settings_changed)

def on_settings_changed(self):
    if self.settings.get("apiv3"):
        self.api = self.settings.get("apiv3")

As far as I understand the tmdbv3api will react to a missing API key by rasing an TMDbException exception. You can either handle that by adding an corresponding except for each intent or by adding to the beginning of each intent:

if not self.api:
    self.speak_dialog("no.api", {})

#3

Thanks. The set_changed_callback is what I was searching for.

I guess maybe I will have to add a check with every intent. I was hoping there might be a work around for that.


#4

Would be interested in other suggestions of how it could work. I see one benefit of the existing approach being that you can tailor the response depending on which intent was called, but that might not be so useful in your case.

Just had a quick look at your repo, could abstract it out along with the no info dialogue to self.checkMovie or similar? However I do like being able to see the different paths right there in the intent handler, sometimes repeating yourself just makes things easier to read.


#5

Thank you @gez-mycroft. I think I have it working with the set_changed_callback, but would love to hear other suggestions also.

I think I agree with just error checking each intent. It does make it easier to read.