Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can load the xml db from a cached file #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pylutron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,15 +508,16 @@ def send(self, op, cmd, integration_id, *args):
(cmd, str(integration_id)) + tuple((str(x) for x in args if x is not None)))
self._conn.send(op + out_cmd)

def load_xml_db(self, cache_path=None):
"""Load the Lutron database from the server.
def load_xml_db(self, cache_path=None, refresh_data=True):
"""Load the Lutron database from the server if refresh_data is True

If a locally cached copy is available, use that instead.
If not, if a locally cached copy is available, use that instead, or
create one and store it
"""

xml_db = None
loaded_from = None
if cache_path:
if cache_path and not refresh_data:
try:
with open(cache_path, 'rb') as f:
xml_db = f.read()
Expand All @@ -529,6 +530,10 @@ def load_xml_db(self, cache_path=None):
with urllib.request.urlopen(url) as xmlfile:
xml_db = xmlfile.read()
loaded_from = 'repeater'
if cache_path and not refresh_data:
with open(cache_path, 'wb') as f:
f.write(xml_db)
_LOGGER.info("Stored db as %s" % cache_path)

_LOGGER.info("Loaded xml db from %s" % loaded_from)

Expand Down