Merge pull request #1379 from forslund/feature/settings-changed-callback

Add callback on settings change from backend
pull/1388/head
Michael Nguyen 2018-01-25 15:21:15 -06:00 committed by GitHub
commit 02eb1b8277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -99,11 +99,20 @@ class SkillSettings(dict):
self._device_identity = None
self._api_path = None
self._user_identity = None
self.changed_callback = None
# if settingsmeta exist
if isfile(self._meta_path):
self._poll_skill_settings()
def set_changed_callback(self, callback):
"""
Set callback to perform when server settings have changed.
callback: function/method to call when settings have changed
"""
self.changed_callback = callback
# TODO: break this up into two classes
def initialize_remote_settings(self):
""" initializes the remote settings to the server """
@ -380,7 +389,12 @@ class SkillSettings(dict):
if not self._complete_intialization:
return # unable to do remote sync
else:
original = hash(str(self))
self.update_remote()
# Call callback for updated settings
if self.changed_callback and hash(str(self)) != original:
self.changed_callback()
except Exception as e:
LOG.error(e)
LOG.exception("")