forked from mac-zhou/midea-msmart
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for additional cloud credentials based on region (#181)
* Add additional cloud credentials and default to US * Update unit tests and use a constant for default region
- Loading branch information
Showing
5 changed files
with
88 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,12 @@ | |
0xb7, 0xe4, 0x2d, 0x53, 0x49, 0x47, 0x62, 0xbe | ||
]) | ||
|
||
|
||
OPEN_MIDEA_APP_ACCOUNT = "[email protected]" | ||
OPEN_MIDEA_APP_PASSWORD = "this_is_a_password1" | ||
DEFAULT_CLOUD_REGION = "US" | ||
CLOUD_CREDENTIALS = { | ||
"DE": ("[email protected]", "das_ist_passwort1"), | ||
"KR": ("[email protected]", "password_for_sea1"), | ||
"US": ("[email protected]", "this_is_a_password1") | ||
} | ||
|
||
|
||
class DeviceType(IntEnum): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import unittest | ||
from typing import Any, Optional | ||
|
||
from msmart.cloud import ApiError, Cloud, CloudError | ||
from msmart.const import OPEN_MIDEA_APP_ACCOUNT, OPEN_MIDEA_APP_PASSWORD | ||
from msmart.const import DEFAULT_CLOUD_REGION | ||
|
||
|
||
class TestCloud(unittest.IsolatedAsyncioTestCase): | ||
# pylint: disable=protected-access | ||
|
||
async def _login(self, account: str = OPEN_MIDEA_APP_ACCOUNT, | ||
password: str = OPEN_MIDEA_APP_PASSWORD) -> Cloud: | ||
client = Cloud(account, password) | ||
async def _login(self, | ||
region: str = DEFAULT_CLOUD_REGION, | ||
*, | ||
account: Optional[str] = None, | ||
password: Optional[str] = None | ||
) -> Cloud: | ||
client = Cloud(region, account=account, password=password) | ||
await client.login() | ||
|
||
return client | ||
|
@@ -23,11 +28,27 @@ async def test_login(self) -> None: | |
self.assertIsNotNone(client._access_token) | ||
|
||
async def test_login_exception(self) -> None: | ||
"""Test that we can login to the cloud.""" | ||
"""Test that bad credentials raise an exception.""" | ||
|
||
with self.assertRaises(ApiError): | ||
await self._login(account="[email protected]", password="not_a_password") | ||
|
||
async def test_invalid_region(self) -> None: | ||
"""Test that an invalid region raise an exception.""" | ||
|
||
with self.assertRaises(ValueError): | ||
await self._login("NOT_A_REGION") | ||
|
||
async def test_invalid_credentials(self) -> None: | ||
"""Test that invalid credentials raise an exception.""" | ||
|
||
# Check that specifying only an account or password raises an error | ||
with self.assertRaises(ValueError): | ||
await self._login(account=None, password="some_password") | ||
|
||
with self.assertRaises(ValueError): | ||
await self._login(account="some_account", password=None) | ||
|
||
async def test_get_token(self) -> None: | ||
"""Test that a token and key can be obtained from the cloud.""" | ||
|
||
|
@@ -53,7 +74,7 @@ async def test_get_token_exception(self) -> None: | |
async def test_connect_exception(self) -> None: | ||
"""Test that an exception is thrown when the cloud connection fails.""" | ||
|
||
client = Cloud(OPEN_MIDEA_APP_ACCOUNT, OPEN_MIDEA_APP_PASSWORD) | ||
client = Cloud(DEFAULT_CLOUD_REGION) | ||
|
||
# Override URL to an invalid domain | ||
client._base_url = "https://fake_server.invalid." | ||
|