diff --git a/mycroft/skills/settings.py b/mycroft/skills/settings.py index b2c4bd0114..1537881380 100644 --- a/mycroft/skills/settings.py +++ b/mycroft/skills/settings.py @@ -70,6 +70,10 @@ class SkillSettings(dict): self.load_skill_settings() + @property + def _is_stored(self): + return hash(str(self)) == self.loaded_hash + def __getitem__(self, key): return super(SkillSettings, self).__getitem__(key) @@ -111,7 +115,7 @@ class SkillSettings(dict): request settings and store it if it changes TODO: implement as websocket """ - if self._skill_exist_in_backend: + if self._skill_exist_in_backend(): try: # update settings self.settings = self._get_settings() @@ -124,8 +128,7 @@ class SkillSettings(dict): self.__setitem__(field["name"], field["value"]) # store value if settings has changed from backend - new_hash = hash(str(self)) - if new_hash != self.loaded_hash: + if not self._is_stored: self.store() self.loaded_hash = hash(str(self)) diff --git a/test/skills/settings.py b/test/skills/settings.py index e02c912b50..de9fe4f548 100644 --- a/test/skills/settings.py +++ b/test/skills/settings.py @@ -2,6 +2,7 @@ from mycroft.skills.settings import SkillSettings from os.path import join, dirname, abspath from os import remove +import json import unittest @@ -68,6 +69,13 @@ class SkillSettingsTest(unittest.TestCase): s2 = SkillSettings(join(dirname(__file__), 'settings')) self.assertTrue(len(s) == len(s2)) + def test_load_existing(self): + directory = join(dirname(__file__), 'settings', 'settings.json') + with open(directory, 'w') as f: + json.dump({"test": "1"}, f) + s = SkillSettings(join(dirname(__file__), 'settings')) + self.assertEqual(len(s), 1) + if __name__ == '__main__': unittest.main()