Пример #1
0
def get_or_renew_creds(email, password, stored_creds):
    try:
        if stored_creds is None:
            http_client = MerossHttpClient.from_user_password(email=email, password=password)
        else:
            http_client = MerossHttpClient(cloud_credentials=stored_creds)

        # Test device listing. If goes ok, return it immediately
        http_devices = http_client.list_devices()
        return http_client.get_cloud_credentials(), http_devices

    except TokenException:
        # In case the current token is expired or invalid, let's try to re-login.
        _LOGGER.warning("Current token has been refused by the Meross Cloud. Trying to generate a new one with "
                        "stored user credentials...")

        # Build a new client with username/password rather than using stored credentials
        http_client = MerossHttpClient.from_user_password(email=email, password=password)
        http_devices = http_client.list_devices()
        return http_client.get_cloud_credentials(), http_devices
Пример #2
0
 def _test_authorization(username, password):
     client = MerossHttpClient.from_user_password(email=username,
                                                  password=password)
     return client.get_cloud_credentials()
Пример #3
0
 def setUp(self):
     self.client = MerossHttpClient.from_user_password(email=EMAIL,
                                                       password=PASSWORD)