Skip to content

Commit

Permalink
Merge branch 'main' into chemelli74-ruff-first-run
Browse files Browse the repository at this point in the history
  • Loading branch information
rokam authored May 28, 2024
2 parents 00782ac + ac7f78e commit 17bb44c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 80 deletions.
6 changes: 3 additions & 3 deletions midealocal/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ async def list_appliances(
) -> dict[int, dict[str, Any]] | None:
raise NotImplementedError

async def get_device_info(self, device_id: str) -> dict[str, Any] | None:
async def get_device_info(self, device_id: int) -> dict[str, Any] | None:
if response := await self.list_appliances(home_id=None):
if int(device_id) in response.keys():
return cast(dict, response[int(device_id)])
return cast(dict, response[device_id])
return None

async def download_lua(
Expand Down Expand Up @@ -331,7 +331,7 @@ async def list_appliances(
return appliances
return None

async def get_device_info(self, device_id: str) -> dict[str, Any] | None:
async def get_device_info(self, device_id: int) -> dict[str, Any] | None:
data = {"applianceCode": device_id}
if response := await self._api_request(
endpoint="/v1/appliance/info/get",
Expand Down
157 changes: 86 additions & 71 deletions tests/cloud_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def test_meijucloud_login_success(self) -> None:
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["meijucloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["meijucloud_login.json"],
],
)
Expand All @@ -54,7 +54,9 @@ async def test_meijucloud_login_invalid_user(self) -> None:
"""Test MeijuCloud login invalid user"""
session = Mock()
response = Mock()
response.read = AsyncMock(return_value=self.responses["invalid_response.json"])
response.read = AsyncMock(
return_value=self.responses["cloud_invalid_response.json"]
)
session.request = AsyncMock(return_value=response)
cloud = get_midea_cloud(
"美的美居",
Expand Down Expand Up @@ -111,7 +113,7 @@ async def test_meijucloud_list_appliances(self) -> None:
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["meijucloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["meijucloud_login.json"],
self.responses["meijucloud_list_appliances.json"],
],
Expand All @@ -125,34 +127,38 @@ async def test_meijucloud_list_appliances(self) -> None:
)
assert cloud is not None
assert await cloud.login()
appliances = await cloud.list_appliances(1)
appliances = await cloud.list_appliances("1")
assert appliances is not None
assert len(appliances.keys()) == 2
assert appliances[1]["name"] == "Appliance Name"
assert appliances[1]["type"] == 0xAC
assert appliances[1]["sn"] == "mySecretKey"
assert appliances[1]["sn8"] == "9d52c159"
assert appliances[1]["model_number"] == 10
assert appliances[1]["manufacturer_code"] == "1234"
assert appliances[1]["model"] == "Product Model"
assert appliances[1]["online"]
appliance = appliances.get(1)
assert appliance is not None
assert appliance.get("name") == "Appliance Name"
assert appliance.get("type") == 0xAC
assert appliance.get("sn") == "mySecretKey"
assert appliance.get("sn8") == "9d52c159"
assert appliance.get("model_number") == 10
assert appliance.get("manufacturer_code") == "1234"
assert appliance.get("model") == "Product Model"
assert appliance.get("online")

assert appliances[2]["name"] == "Appliance Name 2"
assert appliances[2]["type"] == 0xAC
assert appliances[2]["sn"] == ""
assert appliances[2]["sn8"] == "00000000"
assert appliances[2]["model_number"] == 10
assert appliances[2]["manufacturer_code"] == "1234"
assert appliances[2]["model"] == "00000000"
assert not appliances[2]["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") == "00000000"
assert appliance.get("model_number") == 10
assert appliance.get("manufacturer_code") == "1234"
assert appliance.get("model") == "00000000"
assert not appliance.get("online")

async def test_meijucloud_get_device_info(self) -> None:
"""Test MeijuCloud get_device_info"""
session = Mock()
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["meijucloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["meijucloud_login.json"],
self.responses["meijucloud_get_device_info.json"],
self.responses["meijucloud_get_device_info_alt.json"],
Expand All @@ -169,32 +175,34 @@ async def test_meijucloud_get_device_info(self) -> None:
assert await cloud.login()

device = await cloud.get_device_info(1)
assert device["name"] == "Appliance Name"
assert device["type"] == 0xAC
assert device["sn"] == "mySecretKey"
assert device["sn8"] == "9d52c159"
assert device["model_number"] == 10
assert device["manufacturer_code"] == "1234"
assert device["model"] == "Product Model"
assert device["online"]
assert device is not None
assert device.get("name") == "Appliance Name"
assert device.get("type") == 0xAC
assert device.get("sn") == "mySecretKey"
assert device.get("sn8") == "9d52c159"
assert device.get("model_number") == 10
assert device.get("manufacturer_code") == "1234"
assert device.get("model") == "Product Model"
assert device.get("online")

device = await cloud.get_device_info(2)
assert device["name"] == "Appliance Name 2"
assert device["type"] == 0xAC
assert device["sn"] == ""
assert device["sn8"] == "00000000"
assert device["model_number"] == 10
assert device["manufacturer_code"] == "1234"
assert device["model"] == "00000000"
assert not device["online"]
assert device is not None
assert device.get("name") == "Appliance Name 2"
assert device.get("type") == 0xAC
assert device.get("sn") == ""
assert device.get("sn8") == "00000000"
assert device.get("model_number") == 10
assert device.get("manufacturer_code") == "1234"
assert device.get("model") == "00000000"
assert not device.get("online")

async def test_meijucloud_download_lua(self) -> None:
"""Test MeijuCloud download_lua"""
session = Mock()
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["meijucloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["meijucloud_login.json"],
self.responses["meijucloud_download_lua.json"],
self.responses["meijucloud_download_lua.json"],
Expand Down Expand Up @@ -235,7 +243,7 @@ async def test_msmartcloud_login_success(self) -> None:
response.read = AsyncMock(
side_effect=[
self.responses["msmartcloud_reroute.json"],
self.responses["msmartcloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["msmartcloud_login.json"],
],
)
Expand All @@ -253,7 +261,9 @@ async def test_msmartcloud_login_invalid_user(self) -> None:
"""Test MSmartCloud login invalid user"""
session = Mock()
response = Mock()
response.read = AsyncMock(return_value=self.responses["invalid_response.json"])
response.read = AsyncMock(
return_value=self.responses["cloud_invalid_response.json"]
)
session.request = AsyncMock(return_value=response)
cloud = get_midea_cloud(
"MSmartHome",
Expand Down Expand Up @@ -285,10 +295,10 @@ async def test_msmartcloud_list_appliances(self) -> None:
response.read = AsyncMock(
side_effect=[
self.responses["msmartcloud_reroute.json"],
self.responses["msmartcloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["msmartcloud_login.json"],
self.responses["msmartcloud_list_appliances.json"],
self.responses["invalid_response.json"],
self.responses["cloud_invalid_response.json"],
],
)
session.request = AsyncMock(return_value=response)
Expand All @@ -300,28 +310,32 @@ async def test_msmartcloud_list_appliances(self) -> None:
)
assert cloud is not None
assert await cloud.login()
appliances = await cloud.list_appliances(1)
appliances = await cloud.list_appliances(None)
assert appliances is not None
assert len(appliances.keys()) == 2
assert appliances[1]["name"] == "Appliance Name"
assert appliances[1]["type"] == 0xAC
assert appliances[1]["sn"] == "1234567890abcdef1234567890abcdef"
assert appliances[1]["sn8"] == "0abcdef1"
assert appliances[1]["model_number"] == 10
assert appliances[1]["manufacturer_code"] == "1234"
assert appliances[1]["model"] == "0abcdef1"
assert appliances[1]["online"]
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")

assert appliances[2]["name"] == "Appliance Name 2"
assert appliances[2]["type"] == 0xAC
assert appliances[2]["sn"] == ""
assert appliances[2]["sn8"] == ""
assert appliances[2]["model_number"] == 0
assert appliances[2]["manufacturer_code"] == "1234"
assert appliances[2]["model"] == ""
assert not appliances[2]["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(1)
appliances = await cloud.list_appliances(None)
assert appliances is None

async def test_msmartcloud_get_device_info(self) -> None:
Expand All @@ -331,7 +345,7 @@ async def test_msmartcloud_get_device_info(self) -> None:
response.read = AsyncMock(
side_effect=[
self.responses["msmartcloud_reroute.json"],
self.responses["msmartcloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["msmartcloud_login.json"],
self.responses["msmartcloud_list_appliances.json"],
],
Expand All @@ -347,23 +361,24 @@ async def test_msmartcloud_get_device_info(self) -> None:
assert await cloud.login()

device = await cloud.get_device_info(1)
assert device["name"] == "Appliance Name"
assert device["type"] == 0xAC
assert device["sn"] == "1234567890abcdef1234567890abcdef"
assert device["sn8"] == "0abcdef1"
assert device["model_number"] == 10
assert device["manufacturer_code"] == "1234"
assert device["model"] == "0abcdef1"
assert device["online"]
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_msmartloud_download_lua(self) -> None:
async def test_msmartcloud_download_lua(self) -> None:
"""Test MSmartCloud download_lua"""
session = Mock()
response = Mock()
response.read = AsyncMock(
side_effect=[
self.responses["msmartcloud_reroute.json"],
self.responses["msmartcloud_login_id.json"],
self.responses["cloud_login_id.json"],
self.responses["msmartcloud_login.json"],
self.responses["meijucloud_download_lua.json"],
],
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions tests/responses/msmartcloud_login_id.json

This file was deleted.

0 comments on commit 17bb44c

Please sign in to comment.