The problem is that you're assuming that there are valid plugin prefs in the __init__ method:
- Code: Select all
self.authorization_token = self.pluginPrefs['authorizationtoken']
self.username = self.pluginPrefs['life360_username']
self.password = self.pluginPrefs['life360_password']
self.refresh_frequency = self.pluginPrefs['refresh_frequency']
But on first launch, those don't exist yet. The config dialog can't even run because it's failing plugin initialization (the __init__ method is the absolute first thing in your plugin to get called, well before config dialog etc). You have to rework your logic knowing that when the plugin first initializes, you won't have valid values. To fix the obvious issue:
- Code: Select all
self.authorization_token = self.pluginPrefs.get('authorizationtoken', None)
self.username = self.pluginPrefs.get('life360_username', None)
self.password = self.pluginPrefs.get('life360_password', None)
self.refresh_frequency = self.pluginPrefs.get('refresh_frequency', 30)
I took a stab at a reasonable default for refresh_frequency mostly to show how you could do that. I doubt that will fully solve your problem though, you'll likely need further refactoring to make sure that on first run everything does (or doesn't) do what's expected.
You will also need to handle a config dialog close without valid values (the user clicks the Cancel button), which will continue to result in missing stuff. You need to programmatically make sure that before you use any of those values that they are present, OR handle the failures that will happen if they are missing or invalid.