hacs / integration

HACS gives you a powerful UI to handle downloads of all your custom needs.
https://hacs.xyz
MIT License
4.87k stars 1.22k forks source link

Add and update dashboard resources #3758

Closed ludeeus closed 1 month ago

ludeeus commented 1 month ago

Implement handling of dashboard resources in the backend.

Previously, the UI did this, but now that the updates are served by entities, this is no longer the case.

coderabbitai[bot] commented 1 month ago
Walkthrough ## Walkthrough The recent changes enhance the `custom_components/hacs/repositories/plugin.py` module by adding methods for managing dashboard resources, updating post-installation and post-uninstallation processes, and refining type hints. Corresponding updates in test files ensure these new functionalities are thoroughly tested, including URL mappings and resource handling. ## Changes | Files/Modules | Change Summary | |----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `custom_components/hacs/repositories/plugin.py` | Added imports (`re`, `ResourceStorageCollection`), new methods for dashboard resource management, and modified `async_post_installation` and `async_post_uninstall` methods to include resource updates and removals. | | `tests/conftest.py` | Modified `_dashboard_resources` processing in `assert_hacs_data` function to remove "id" key using `recursive_remove_key`. | | `tests/output/proxy_calls.json` | Added multiple URL mappings for test cases related to plugin repositories and dashboard resources handling. | | `tests/repositories/test_plugin_repository.py` | Added multiple test functions for verifying new methods in `plugin.py`, including generating dashboard resource URLs, handling resource updates, and verifying resource handlers. These tests ensure the new functionalities are correctly implemented and handle various scenarios, such as wrong versions, missing data, and resource removals and additions. | ## Sequence Diagram(s) (Beta) ```mermaid sequenceDiagram participant User participant HACSPluginRepository participant ResourceStorageCollection participant HomeAssistant User->>HACSPluginRepository: Install Plugin HACSPluginRepository->>HACSPluginRepository: async_post_installation() HACSPluginRepository->>HACSPluginRepository: update_dashboard_resources() HACSPluginRepository->>ResourceStorageCollection: Add Resource User->>HACSPluginRepository: Uninstall Plugin HACSPluginRepository->>HACSPluginRepository: async_post_uninstall() HACSPluginRepository->>HACSPluginRepository: remove_dashboard_resources() HACSPluginRepository->>ResourceStorageCollection: Remove Resource User->>HACSPluginRepository: Test Resource URL HACSPluginRepository->>HACSPluginRepository: generate_dashboard_resource_url() HACSPluginRepository->>User: Return URL ```

Recent review details **Configuration used: CodeRabbit UI** **Review profile: ASSERTIVE**
Commits Files that changed from the base of the PR and between 9e2f531d1a0abf545eac8a8af63104a3c0f2dd45 and eadd3e748f15c2a984eeb70bba27852c5d1be150.
Files selected for processing (2) * custom_components/hacs/repositories/plugin.py (4 hunks) * tests/repositories/test_plugin_repository.py (1 hunks)
Additional comments not posted (12)
custom_components/hacs/repositories/plugin.py (6)
`17-17`: Type hint import is correctly scoped under `TYPE_CHECKING` to avoid runtime overhead. --- `65-65`: The asynchronous methods `async_post_installation` and `async_post_uninstall` now handle dashboard resources, aligning with the PR's objectives. Also applies to: 67-69 --- `149-167`: The methods `generate_dashboard_resource_hacstag`, `generate_dashboard_resource_namespace`, and `generate_dashboard_resource_url` are well-implemented for generating resource identifiers. --- `171-191`: The method `_get_resource_handler` effectively handles various error scenarios related to resource access. The logging improvements suggested in previous comments have been correctly implemented. --- `195-221`: The methods `update_dashboard_resources` and `remove_dashboard_resources` are crucial for managing the lifecycle of dashboard resources. They correctly utilize the `_get_resource_handler` method to ensure resources are managed appropriately. --- `5-5`: Ensure the `re` module is used appropriately in the file.
Verification successful --- The `re` module is indeed used in the file `custom_components/hacs/repositories/plugin.py`, specifically for compiling a regular expression pattern. - Line: `HACSTAG_REPLACER = re.compile(r"\D+")` This confirms that the import of the `re` module is necessary.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify usage of the `re` module in the file. # Test: Search for the usage of the `re` module. Expect: At least one usage. rg --type python 're\.' custom_components/hacs/repositories/plugin.py ``` Length of output: 102 --- --- Script: ```shell #!/bin/bash # Description: Verify usage of the `re` module in the file. # Test: Search for the usage of the `re` module. Expect: At least one usage. rg --type py 're\.' custom_components/hacs/repositories/plugin.py ``` Length of output: 291
tests/repositories/test_plugin_repository.py (6)
`13-22`: The fixture `downloaded_plugin_repository` is correctly set up to provide a `HacsPluginRepository` instance for testing. --- `33-41`: The test `test_dashboard_namespace` correctly asserts the generation of namespaces for different repositories. --- `53-69`: The test `test_dashboard_hacstag` effectively checks the generation of HACS tags under various conditions. --- `72-77`: The test `test_dashboard_url` ensures that the URL generation for dashboard resources is correct. --- `80-88`: The series of tests from `test_get_resource_handler` to `test_get_resource_handler_no_hass_data` comprehensively cover various failure modes of the resource handler. These tests are crucial for ensuring robust error handling. Also applies to: 90-99, 102-111, 114-123, 126-135, 138-147, 150-159, 162-174 --- `176-197`: The tests `test_remove_dashboard_resource`, `test_add_dashboard_resource`, and `test_update_dashboard_resource` validate the functionality of adding, removing, and updating dashboard resources. These tests are well-structured and provide good coverage of the new functionalities. Also applies to: 199-217, 218-247
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.