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

Midea Air Cloud initial test coverage #40

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
127 changes: 127 additions & 0 deletions tests/cloud_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,130 @@ async def test_msmartcloud_download_lua(self) -> None:
assert os.path.exists(file)
os.remove(file)
os.removedirs("/tmp/download")

async def test_mideaaircloud_login_success(self) -> None:
"""Test MideaAirCloud login"""
session = Mock()
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["mideaaircloud_login_id.json"],
self.responses["mideaaircloud_login.json"],
]
)
session.request = AsyncMock(return_value=response)
cloud = get_midea_cloud(
"Midea Air", session=session, account="account", password="password"
)
assert cloud is not None
assert await cloud.login()

async def test_mideaaircloud_login_invalid_user(self) -> None:
"""Test MideaAirCloud login invalid user"""
session = Mock()
response = Mock()
response.read = AsyncMock(
return_value=self.responses["mideaaircloud_invalid_response.json"]
)
session.request = AsyncMock(return_value=response)
cloud = get_midea_cloud(
"Midea Air", session=session, account="account", password="password"
)
assert cloud is not None
assert not await cloud.login()

async def test_mideaaircloud_list_home(self) -> None:
"""Test MideaAirCloud list_home"""
session = Mock()
cloud = get_midea_cloud(
"Midea Air", session=session, account="account", password="password"
)
assert cloud is not None
homes = await cloud.list_home()
assert homes is not None
assert len(homes.keys()) == 1

async def test_mideaaircloud_list_appliances(self) -> None:
"""Test MideaAirCloud list_appliances"""
session = Mock()
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["mideaaircloud_login_id.json"],
self.responses["mideaaircloud_login.json"],
self.responses["mideaaircloud_list_appliances.json"],
self.responses["mideaaircloud_invalid_response.json"],
]
)
session.request = AsyncMock(return_value=response)
cloud = get_midea_cloud(
"Midea Air", session=session, account="account", password="password"
)
assert cloud is not None
assert await cloud.login()
appliances = await cloud.list_appliances(None)
assert appliances is not None
assert len(appliances.keys()) == 2
appliance = appliances.get(1)
assert appliance is not None
assert appliance.get("name") == "Appliance Name"
assert appliance.get("type") == 0xAC
assert appliance.get("sn") == "1234567890abcdef1234567890abcdef"
assert appliance.get("sn8") == "0abcdef1"
assert appliance.get("model_number") == 10
assert appliance.get("manufacturer_code") == "1234"
assert appliance.get("model") == "0abcdef1"
assert appliance.get("online")

appliance = appliances.get(2)
assert appliance is not None
assert appliance.get("name") == "Appliance Name 2"
assert appliance.get("type") == 0xAC
assert appliance.get("sn") == ""
assert appliance.get("sn8") == ""
assert appliance.get("model_number") == 0
assert appliance.get("manufacturer_code") == "1234"
assert appliance.get("model") == ""
assert not appliance.get("online")

appliances = await cloud.list_appliances(None)
assert appliances is None

async def test_mideaaircloud_get_device_info(self) -> None:
"""Test MideaAirCloud get_device_info"""
session = Mock()
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["mideaaircloud_login_id.json"],
self.responses["mideaaircloud_login.json"],
self.responses["mideaaircloud_list_appliances.json"],
]
)
session.request = AsyncMock(return_value=response)
cloud = get_midea_cloud(
"Midea Air", session=session, account="account", password="password"
)
assert cloud is not None
assert await cloud.login()

device = await cloud.get_device_info(1)
assert device is not None
assert device.get("name") == "Appliance Name"
assert device.get("type") == 0xAC
assert device.get("sn") == "1234567890abcdef1234567890abcdef"
assert device.get("sn8") == "0abcdef1"
assert device.get("model_number") == 10
assert device.get("manufacturer_code") == "1234"
assert device.get("model") == "0abcdef1"
assert device.get("online")

async def test_mideaaircloud_download_lua(self) -> None:
"""Test MideaAirCloud download_lua"""
session = Mock()
cloud = get_midea_cloud(
"Midea Air", session=session, account="account", password="password"
)
assert cloud is not None
with self.assertRaises(NotImplementedError):
await cloud.download_lua("/tmp/download", 10, "00000000", "0xAC", "0010")
3 changes: 3 additions & 0 deletions tests/responses/mideaaircloud_invalid_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorCode": 10
}
27 changes: 27 additions & 0 deletions tests/responses/mideaaircloud_list_appliances.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"errorCode": 0,
"result": {
"list": [
{
"modelNumber": 10,
"name": "Appliance Name",
"type": "0xAC",
"sn": "1234567890abcdef1234567890abcdef",
"enterpriseCode": "1234",
"productModel": "Product Model",
"onlineStatus": "1",
"id": "1"
},
{
"modelNumber": "ge",
"name": "Appliance Name 2",
"type": "0xAC",
"sn": "",
"sn8": "",
"enterpriseCode": "1234",
"onlineStatus": "0",
"id": "2"
}
]
}
}
11 changes: 11 additions & 0 deletions tests/responses/mideaaircloud_login.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"errorCode": 0,
"result": {
"sessionId": "ab527a62ed1caaa9f61b873475e5bfc336c18240d33a55d03721d8e3f14e10d8",
"userId": "1234567890abcdef1234567890abcdef",
"mdata": {
"accessToken": "1234567890abcdef1"
},
"accessToken": "ddfb3efba8121ee3a85a0d48ace6ba97c3f1d65a2c944f92fbe98985c3b759f2"
}
}
6 changes: 6 additions & 0 deletions tests/responses/mideaaircloud_login_id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"errorCode": 0,
"result": {
"loginId": "returnedLoginId"
}
}
Loading