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

feat: parse all the response items from MeijuCloud for get_device_inf #231

Merged
merged 12 commits into from
Aug 2, 2024

Conversation

wuwentao
Copy link
Member

@wuwentao wuwentao commented Jul 18, 2024

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.

Copy link
Contributor

coderabbitai bot commented Jul 18, 2024

Walkthrough

The get_device_info function in cloud.py has been significantly enhanced, featuring an expanded docstring that clarifies API interactions and a richer set of device attributes. This improvement not only streamlines data retrieval but also elevates the overall user experience with comprehensive information such as des, active_status, and wifi_version.

Changes

Files Change Summary
midealocal/cloud.py Enhanced get_device_info function with a detailed docstring and additional attributes in the response.
tests/cloud_test.py Expanded assertions in test_meijucloud_get_device_info to validate new device attributes.
tests/responses/meijucloud_get_device_info_alt.json Added new fields to the JSON response for a more detailed representation of device information.

Poem

In the cloud where data streams,
New details join the info gleams.
With get_device_info so bright,
More insights come to light.
🎉 Let's celebrate with a cheer,
As our code grows more clear!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8178e76 and f224cd2.

Files selected for processing (1)
  • midealocal/cloud.py (2 hunks)
Additional comments not posted (2)
midealocal/cloud.py (2)

376-393: Docstring Update: Ensure accuracy and completeness.

The updated docstring provides detailed information about the API URL, headers, input, and response structure. Ensure that the docstring accurately reflects the actual API behavior and the response structure.


414-433: New Attributes: Verify correctness and completeness.

The additional attributes in the response processing logic should be verified for correctness. Ensure that all attributes are correctly mapped from the response and that their default values are handled appropriately.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f224cd2 and 18774d7.

Files selected for processing (1)
  • midealocal/cloud.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • midealocal/cloud.py

@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.59%. Comparing base (08aea5c) to head (2c256f1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #231   +/-   ##
=======================================
  Coverage   37.59%   37.59%           
=======================================
  Files          84       84           
  Lines        7451     7451           
=======================================
  Hits         2801     2801           
  Misses       4650     4650           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@rokam rokam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please improve tests to check the parse process

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 18774d7 and d425646.

Files selected for processing (1)
  • midealocal/cloud.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • midealocal/cloud.py

midealocal/cloud.py Outdated Show resolved Hide resolved
midealocal/cloud.py Outdated Show resolved Hide resolved
midealocal/cloud.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
tests/responses/meijucloud_get_device_info_alt.json (1)

12-32: Ensure consistency in field naming conventions.

The fields added to the JSON object are generally consistent, but consider the following:

  • Use snake_case for consistency with other fields.
  • Ensure that the field names are descriptive and relevant.

For example, activeStatus should be active_status, and wifiVersion should be wifi_version.

-    "activeStatus": 1,
-    "wifiVersion": "059009012205",
+    "active_status": 1,
+    "wifi_version": "059009012205",
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d425646 and 7f4fbf9.

Files selected for processing (3)
  • midealocal/cloud.py (2 hunks)
  • tests/cloud_test.py (1 hunks)
  • tests/responses/meijucloud_get_device_info_alt.json (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • midealocal/cloud.py
Additional comments not posted (1)
tests/cloud_test.py (1)

307-327: LGTM! Ensure all new fields are covered in tests.

The added assertions are correct and relevant. They ensure that the device object has the expected attributes and values.

However, verify that all new fields added to the JSON object are covered in the tests.

Verification successful

All new fields are covered in the tests.

The added assertions in the test file thoroughly cover the new fields in the device object.

  • des
  • active_status
  • active_time
  • master_id
  • wifi_version
  • enterprise
  • is_other_equipment
  • attrs
  • room_name
  • bt_mac
  • bt_token
  • hotspot_name
  • is_bluetooth
  • bind_type
  • ability
  • name_changed
  • template_of_tsl
  • shadow_level
  • smart_product_id
  • brand
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all new fields in the JSON object are covered in the tests.

# Test: Search for all assertions in the test file. Expect: All new fields are covered.
rg --type python -A 5 $'assert device.get('

Length of output: 131


Script:

#!/bin/bash
# Description: Verify all new fields in the JSON object are covered in the tests.

# Test: Search for all assertions in the test file. Expect: All new fields are covered.
rg --type python -A 5 'assert device.get('

Length of output: 131


Script:

#!/bin/bash
# Description: Verify all new fields in the JSON object are covered in the tests.

# Test: Search for all assertions in the test file. Expect: All new fields are covered.
rg --type python 'assert device.get'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify all new fields in the JSON object are covered in the tests.

# Test: Search for all assertions in the test file. Expect: All new fields are covered.
rg --glob '*.py' 'assert device.get'

Length of output: 3588

@wuwentao
Copy link
Member Author

Please improve tests to check the parse process

thanks for your review comments, add test done, please help to review and check the testcase info.

midealocal/cloud.py Outdated Show resolved Hide resolved
midealocal/cloud.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7f4fbf9 and 57b0214.

Files selected for processing (1)
  • midealocal/cloud.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • midealocal/cloud.py

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 57b0214 and 830b41d.

Files selected for processing (3)
  • midealocal/cloud.py (2 hunks)
  • tests/cloud_test.py (1 hunks)
  • tests/responses/meijucloud_get_device_info_alt.json (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • midealocal/cloud.py
  • tests/cloud_test.py
  • tests/responses/meijucloud_get_device_info_alt.json

@rokam rokam self-requested a review July 22, 2024 14:47
@rokam rokam added the bug Something isn't working label Jul 25, 2024
@rokam rokam added misc Miscellaneous and removed bug Something isn't working labels Jul 25, 2024
@rokam rokam changed the title chore: parse all the response items from MeijuCloud for get_device_info feat: parse all the response items from MeijuCloud for get_device_inf Jul 25, 2024
@rokam rokam removed the misc Miscellaneous label Jul 25, 2024
@rokam rokam added the enhancement New feature or request label Jul 25, 2024
@rokam rokam requested review from rokam and chemelli74 July 29, 2024 16:37
Copy link
Contributor

@rokam rokam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
midealocal/cloud.py (1)

438-456: Improve docstring formatting and clarity.

The docstring provides detailed information about the API interaction, but it can be formatted for better readability and clarity.

-        """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}}'
-        """
+        """
+        Get device information.
+
+        API URL: https://mp-prod.smartmidea.net/mas/v5/app/proxy?alias=/v1/appliance/info/get
+
+        Header:
+        - content-type: application/json; charset=utf-8
+        - secretVersion: 1
+        - sign: <generated_signature>
+        - random: <timestamp>
+        - uid: <user_id> (if available)
+        - accessToken: <access_token> (if available)
+
+        Input:
+        {
+            'applianceCode': 21000***830**18,
+            'reqId': 'b11bb9083be6d77906fe1c9f019cdea0',
+            'stamp': '20240710092728'
+        }
+
+        Response:
+        {
+            "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
+            }
+        }
+        """
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 830b41d and 7f66ca5.

Files selected for processing (1)
  • midealocal/cloud.py (2 hunks)
Additional comments not posted (1)
midealocal/cloud.py (1)

476-496: Ensure proper handling of new fields in the response dictionary.

The new fields added to the response dictionary enhance the functionality. Ensure that these fields are correctly handled and validated in the downstream code.

Verification successful

The new fields in the response dictionary are correctly handled and validated in the downstream code.

  • The fields are used in the midealocal/cloud.py file.
  • The fields are also validated in the tests/cloud_test.py file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new fields in the response dictionary are correctly handled in the downstream code.

# Test: Search for the usage of the new fields. Expect: Proper handling and validation of these fields.
rg --type python -A 5 $'des|active_status|active_time|master_id|wifi_version|enterprise|is_other_equipment|attrs|room_name|bt_mac|bt_token|hotspot_name|is_bluetooth|bind_type|ability|name_changed|support_wot|template_of_tsl|shadow_level|smart_product_id|brand'

Length of output: 292


Script:

#!/bin/bash
# Description: Verify that the new fields in the response dictionary are correctly handled in the downstream code.

# Test: Search for the usage of the new fields. Expect: Proper handling and validation of these fields.
rg -t py -A 5 'des|active_status|active_time|master_id|wifi_version|enterprise|is_other_equipment|attrs|room_name|bt_mac|bt_token|hotspot_name|is_bluetooth|bind_type|ability|name_changed|support_wot|template_of_tsl|shadow_level|smart_product_id|brand'

Length of output: 44128

@wuwentao
Copy link
Member Author

wuwentao commented Aug 1, 2024

@chemelli74 @rokam
I'm sorry for the delay these days, any comments with it? especially for @chemelli74 , we should have a agreement with it, for this PR and also for fututure PRs.

in addition, these response info is json format from cloud server, so all the types should be json types, and NOT python types. for example, json null vs python none.

thanks.

@rokam
Copy link
Contributor

rokam commented Aug 1, 2024

@chemelli74 @rokam
I'm sorry for the delay these days, any comments with it? especially for @chemelli74 , we should have a agreement with it, for this PR and also for fututure PRs.

in addition, these response info is json format from cloud server, so all the types should be json types, and NOT python types. for example, json null vs python none.

thanks.

It's ok for me.

@rokam rokam removed the enhancement New feature or request label Aug 1, 2024
@github-actions github-actions bot added the enhancement New feature or request label Aug 1, 2024
@chemelli74
Copy link
Member

If you guys both think that's fine, go ahead

@rokam rokam merged commit 1976eb6 into main Aug 2, 2024
10 checks passed
@rokam rokam deleted the parse_response branch August 2, 2024 00:17
@rokam rokam mentioned this pull request Aug 1, 2024
@wuwentao
Copy link
Member Author

wuwentao commented Aug 2, 2024

thanks.

rokam added a commit that referenced this pull request Aug 5, 2024
🤖 I have created a release *beep* *boop*
---


## [2.6.0](v2.5.0...v2.6.0)
(2024-08-02)


### Features

* parse all the response items from MeijuCloud for get_device_inf
([#231](#231))
([1976eb6](1976eb6))


### Bug Fixes

* **cli:** authenticate to get keys
([#256](#256))
([a017e7a](a017e7a))
* tank is always seen as full
([#255](#255))
([3524405](3524405))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants