1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-16 15:20:09 -07:00

Make load into a class method

This commit is contained in:
Adrian Sampson 2018-01-20 21:47:32 -05:00
parent 2ce09e9642
commit ebc9c5b679
2 changed files with 15 additions and 11 deletions

View File

@ -64,8 +64,7 @@ def example_command(client, args):
def example(args): def example(args):
state = load_state() state = load_state()
client = wideq.Client() client = wideq.Client.load(state)
client.load(state)
if not client._auth: if not client._auth:
client._auth = authenticate(client.gateway) client._auth = authenticate(client.gateway)

View File

@ -371,11 +371,11 @@ class Client(object):
and allows serialization of state. and allows serialization of state.
""" """
def __init__(self): def __init__(self, gateway=None, auth=None, session=None):
# The three steps required to get access to call the API. # The three steps required to get access to call the API.
self._gateway = None self._gateway = gateway
self._auth = None self._auth = auth
self._session = None self._session = session
# The last list of devices we got from the server. # The last list of devices we got from the server.
self._devices = None self._devices = None
@ -404,18 +404,23 @@ class Client(object):
self._devices = self.session.get_devices() self._devices = self.session.get_devices()
return self._devices return self._devices
def load(self, state): @classmethod
"""Load the client objects from the encoded state data. def load(cls, state):
"""Load a client from serialized state.
""" """
client = cls()
if 'gateway' in state: if 'gateway' in state:
self._gateway = Gateway.load(state['gateway']) client._gateway = Gateway.load(state['gateway'])
if 'auth' in state: if 'auth' in state:
self._auth = Auth.load(self._gateway, state['auth']) client._auth = Auth.load(client.gateway, state['auth'])
if 'session' in state: if 'session' in state:
self._session = Session.load(self._auth, state['session']) client._session = Session.load(client.auth, state['session'])
return client
def dump(self): def dump(self):
"""Serialize the client state.""" """Serialize the client state."""