[WIP] need to add PATCH for settingsmeta.json
parent
d3621b7fca
commit
01d8a0caf7
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
from threading import Timer
|
||||||
from os.path import isfile, join, exists, expanduser
|
from os.path import isfile, join, exists, expanduser
|
||||||
from mycroft.util.log import getLogger
|
from mycroft.util.log import getLogger
|
||||||
from mycroft.api import DeviceApi
|
from mycroft.api import DeviceApi
|
||||||
|
@ -38,6 +39,7 @@ logger = getLogger(__name__)
|
||||||
SKILLS_DIR = "/opt/mycroft/skills"
|
SKILLS_DIR = "/opt/mycroft/skills"
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: account for settings changes through skill ie. change default playlist
|
||||||
class SkillSettings(dict):
|
class SkillSettings(dict):
|
||||||
"""
|
"""
|
||||||
SkillSettings creates a dictionary that can easily be stored
|
SkillSettings creates a dictionary that can easily be stored
|
||||||
|
@ -60,8 +62,8 @@ class SkillSettings(dict):
|
||||||
self.loaded_hash = hash(str(self))
|
self.loaded_hash = hash(str(self))
|
||||||
|
|
||||||
self._send_settings_meta()
|
self._send_settings_meta()
|
||||||
self._request_settings()
|
self._poll_web_settings()
|
||||||
self._load_settings()
|
self._load_web_settings()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _is_stored(self):
|
def _is_stored(self):
|
||||||
|
@ -78,9 +80,9 @@ class SkillSettings(dict):
|
||||||
|
|
||||||
def _send_settings_meta(self):
|
def _send_settings_meta(self):
|
||||||
"""
|
"""
|
||||||
If settings meta data exists and the skill is loaded for the
|
TODO: do a poll, if settingsmeta.json changes, PATCH it to backend
|
||||||
first time, send settingsmeta.json to the backend and store uuid
|
If settings meta data exists and skill does not have a uuid,
|
||||||
for skill
|
send settingsmeta.json to the backend and store uuid for skill
|
||||||
"""
|
"""
|
||||||
if isfile(self._meta_path):
|
if isfile(self._meta_path):
|
||||||
with open(self._meta_path) as f:
|
with open(self._meta_path) as f:
|
||||||
|
@ -92,13 +94,12 @@ class SkillSettings(dict):
|
||||||
response = self._post_metadata(self.settings_meta)
|
response = self._post_metadata(self.settings_meta)
|
||||||
self._store_uuid(response)
|
self._store_uuid(response)
|
||||||
|
|
||||||
def _request_settings(self):
|
def _poll_web_settings(self):
|
||||||
"""
|
"""
|
||||||
Poll to backend to request settings and store it if it changes
|
If uuid exists for this skill poll to backend to
|
||||||
|
request settings and store it if it changes
|
||||||
TODO: implement as websocket
|
TODO: implement as websocket
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# TODO: A get request for specific skill uuid instead of getting all
|
|
||||||
if isfile(self._uuid_path):
|
if isfile(self._uuid_path):
|
||||||
with open(self._uuid_path, 'r') as f:
|
with open(self._uuid_path, 'r') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
@ -110,9 +111,13 @@ class SkillSettings(dict):
|
||||||
settings_list = skill_setting['skillMetadata']['sections']
|
settings_list = skill_setting['skillMetadata']['sections']
|
||||||
for section in settings_list:
|
for section in settings_list:
|
||||||
for field in section["fields"]:
|
for field in section["fields"]:
|
||||||
pass
|
self.__setitem__(field["name"], field["value"])
|
||||||
|
|
||||||
def _load_settings(self):
|
self.store()
|
||||||
|
# poll backend every 60 seconds for new settings
|
||||||
|
Timer(60, self._poll_web_settings).start()
|
||||||
|
|
||||||
|
def _load_web_settings(self):
|
||||||
"""
|
"""
|
||||||
If settings.json exist, open and read stored values into self
|
If settings.json exist, open and read stored values into self
|
||||||
"""
|
"""
|
||||||
|
@ -161,12 +166,3 @@ class SkillSettings(dict):
|
||||||
with open(self._settings_path, 'w') as f:
|
with open(self._settings_path, 'w') as f:
|
||||||
json.dump(self, f)
|
json.dump(self, f)
|
||||||
self.loaded_hash = hash(str(self))
|
self.loaded_hash = hash(str(self))
|
||||||
|
|
||||||
def test(self):
|
|
||||||
with open(self._uuid_path, 'r') as f:
|
|
||||||
data = json.load(f)
|
|
||||||
return data
|
|
||||||
|
|
||||||
# account for settings changes through skill ie. change default playlist
|
|
||||||
|
|
||||||
# account for finding a place to store uuid
|
|
||||||
|
|
Loading…
Reference in New Issue