Skip to content

Commit

Permalink
feat: parse all the response items from MeijuCloud for get_device_inf (
Browse files Browse the repository at this point in the history
…#231)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **New Features**
- Enhanced device information with additional attributes like
description, active status, active time, master ID, WiFi version, and
more, improving data handling capabilities.

- **Documentation**
- Updated docstrings to provide clearer information on API interaction,
including details on expected input and response structure.

- **Tests**
- Added multiple assertions in tests to validate new device attributes,
enhancing test coverage and ensuring reliable device information
retrieval.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lucas Mindêllo de Andrade <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2024
1 parent 08aea5c commit 1976eb6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
41 changes: 40 additions & 1 deletion midealocal/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,25 @@ async def list_appliances(
return None

async def get_device_info(self, device_id: int) -> dict[str, Any] | None:
"""Get device information."""
"""Get device information.
API url: https://mp-prod.smartmidea.net/mas/v5/app/proxy?alias=/v1/appliance/info/get
header:
input: {'applianceCode': 21000***830**18,
'reqId': 'b11bb9083be6d77906fe1c9f019cdea0', 'stamp': '20240710092728'}
response: b'{"code":0,"msg":null,"data":{"id":null,
"applianceCode":21000***830**18,
"sn":"7105f17f36a6afcce272f8053e2be60fd74b1a4baca120afaad83011bb50e8d5f3678bf88e32ea11885394e1a32c9c0e",
"onlineStatus":1,"type":"0xDB","modelNumber":"12877",
"name":"device_name_bytearray",
"des":null,"activeStatus":1,"activeTime":"2024-06-12 10:45:45",
"masterId":null,"wifiVersion":"059009012205","enterprise":"0000",
"isOtherEquipment":null,"attrs":null,"roomName":null,
"btMac":"54B8740FA801","btToken":null,"hotspotName":null,
"isBluetooth":0,"bindType":null,"ability":null,"nameChanged":null,
"sn8":"38127874","supportWot":false,"templateOfTSL":null,
"shadowLevel":null,"smartProductId":10004256,"brand":null}}'
"""
data = {"applianceCode": device_id}
if response := await self._api_request(
endpoint="/v1/appliance/info/get",
Expand All @@ -455,6 +473,27 @@ async def get_device_info(self, device_id: int) -> dict[str, Any] | None:
"manufacturer_code": response.get("enterpriseCode", "0000"),
"model": response.get("productModel"),
"online": response.get("onlineStatus") == "1",
"des": response.get("des", None),
"active_status": response.get("activeStatus", None),
"active_time": response.get("activeTime", None),
"master_id": response.get("masterId", None),
"wifi_version": response.get("wifiVersion", None),
"enterprise": response.get("enterprise", None),
"is_other_equipment": response.get("isOtherEquipment", None),
"attrs": response.get("attrs", None),
"room_name": response.get("roomName", None),
"bt_mac": response.get("btMac", None),
"bt_token": response.get("btToken", None),
"hotspot_name": response.get("hotspotName", None),
"is_bluetooth": response.get("isBluetooth", None),
"bind_type": response.get("bindType", None),
"ability": response.get("ability", None),
"name_changed": response.get("nameChanged", None),
"support_wot": response.get("supportWot", None),
"template_of_tsl": response.get("templateOfTSL", None),
"shadow_level": response.get("shadowLevel", None),
"smart_product_id": response.get("smartProductId", None),
"brand": response.get("brand", None),
}
sn8 = device_info.get("sn8")
if sn8 is None or len(sn8) == 0:
Expand Down
21 changes: 21 additions & 0 deletions tests/cloud_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,27 @@ async def test_meijucloud_get_device_info(self) -> None:
assert device.get("manufacturer_code") == "1234"
assert device.get("model") == "00000000"
assert not device.get("online")
assert device.get("des") is None
assert device.get("active_status") == 1
assert device.get("active_time") == "2024-06-12 10:45:45"
assert device.get("master_id") is None
assert device.get("wifi_version") == "059009012205"
assert device.get("enterprise") == "0000"
assert device.get("is_other_equipment") is None
assert device.get("attrs") is None
assert device.get("room_name") is None
assert device.get("bt_mac") == "54B8740FA801"
assert device.get("bt_token") is None
assert device.get("hotspot_name") is None
assert device.get("is_bluetooth") == 0
assert device.get("bind_type") is None
assert device.get("ability") is None
assert device.get("name_changed") is None
assert not device.get("support_wot")
assert device.get("template_of_tsl") is None
assert device.get("shadow_level") is None
assert device.get("smart_product_id") == 10004256
assert device.get("brand") is None

device = await cloud.get_device_info(99)
assert device is None
Expand Down
23 changes: 22 additions & 1 deletion tests/responses/meijucloud_get_device_info_alt.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
"sn8": "",
"enterpriseCode": "1234",
"onlineStatus": "0",
"applianceCode": "2"
"applianceCode": "2",
"des": null,
"activeStatus": 1,
"activeTime": "2024-06-12 10:45:45",
"masterId": null,
"wifiVersion": "059009012205",
"enterprise": "0000",
"isOtherEquipment": null,
"attrs": null,
"roomName": null,
"btMac": "54B8740FA801",
"btToken": null,
"hotspotName": null,
"isBluetooth": 0,
"bindType": null,
"ability": null,
"nameChanged": null,
"supportWot": false,
"templateOfTSL": null,
"shadowLevel": null,
"smartProductId": 10004256,
"brand": null
}
}

0 comments on commit 1976eb6

Please sign in to comment.