mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-19 00:30:10 -07:00
Cache a ModelInfo wrapper
This commit is contained in:
parent
947ea8a647
commit
445ea623fc
23
wideq.py
23
wideq.py
@ -353,6 +353,10 @@ class Client(object):
|
||||
# raw JSON list data describing the devices.
|
||||
self._devices = None
|
||||
|
||||
# Cached model info data. This is a mapping from URLs to JSON
|
||||
# responses.
|
||||
self._model_info = {}
|
||||
|
||||
@property
|
||||
def gateway(self):
|
||||
if not self._gateway:
|
||||
@ -445,6 +449,15 @@ class Client(object):
|
||||
client.refresh()
|
||||
return client
|
||||
|
||||
def model_info(self, device):
|
||||
"""For a DeviceInfo object, get a ModelInfo object describing
|
||||
the model's capabilities.
|
||||
"""
|
||||
url = device.model_info_url
|
||||
if url not in self._model_info:
|
||||
self._model_info[url] = ModelInfo(device.load_model_info())
|
||||
return self._model_info[url]
|
||||
|
||||
|
||||
class DeviceInfo(object):
|
||||
"""Details about a user's device.
|
||||
@ -471,7 +484,15 @@ class DeviceInfo(object):
|
||||
def name(self):
|
||||
return self.data['alias']
|
||||
|
||||
def model_info(self):
|
||||
def load_model_info(self):
|
||||
"""Load JSON data describing the model's capabilities.
|
||||
"""
|
||||
return requests.get(self.model_info_url).json()
|
||||
|
||||
|
||||
class ModelInfo(object):
|
||||
"""A description of a device model's capabilities.
|
||||
"""
|
||||
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
|
Loading…
x
Reference in New Issue
Block a user