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

Remove warning about using incorrect schema for entity service registration #311

Closed
wants to merge 3 commits into from

Conversation

RogerSelwyn
Copy link
Contributor

@RogerSelwyn RogerSelwyn commented Oct 12, 2024

2024-10-12 12:00:30.700 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'nodered' registers an entity service with a non entity service schema which will stop working in HA Core 2025.9 at custom_components/nodered/switch.py, line 62: platform.async_register_entity_service(, please create a bug report at https:/zachowj/hass-node-red/issues

Summary by CodeRabbit

  • New Features

    • Improved state management in the binary sensor with clearer definitions for lock states.
  • Bug Fixes

    • Simplified the service trigger schema in the switch component, maintaining functionality while enhancing clarity.

Copy link

coderabbitai bot commented Oct 12, 2024

Walkthrough

The pull request introduces updates to two files within the custom components of Node-RED. In binary_sensor.py, a new import for LockState is added, and the on_states tuple is modified to use LockState.UNLOCKED instead of the deprecated STATE_UNLOCKED. In switch.py, the SERVICE_TRIGGER_SCHEMA is simplified from a vol.Schema object to a plain dictionary while maintaining its required and optional fields.

Changes

File Path Change Summary
custom_components/nodered/binary_sensor.py Added import for LockState, updated on_states to use LockState.UNLOCKED instead of STATE_UNLOCKED
custom_components/nodered/switch.py Changed SERVICE_TRIGGER_SCHEMA from vol.Schema to a plain dictionary without altering its structure

Possibly related PRs

  • Replace deprecated constant #306: This PR directly relates to the changes in the binary_sensor.py file, specifically addressing the replacement of the deprecated constant STATE_UNLOCKED with LockState.UNLOCKED, which is the same modification made in the main PR.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1ea8fad and 0339651.

📒 Files selected for processing (1)
  • custom_components/nodered/binary_sensor.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • custom_components/nodered/binary_sensor.py

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@RogerSelwyn RogerSelwyn reopened this Oct 12, 2024
Copy link

@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 and nitpick comments (1)
custom_components/nodered/binary_sensor.py (1)

48-48: LGTM: Updated to use LockState.UNLOCKED

The change from STATE_UNLOCKED to LockState.UNLOCKED is a good improvement. It uses a more type-safe enum value instead of a string constant, which aligns with best practices and addresses the warning about incorrect schemas.

Consider updating other string constants in the on_states tuple to use similar enum values if they exist in Home Assistant. For example, STATE_ON, STATE_OPEN, and STATE_HOME might have corresponding enum values that could be used for consistency.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2413954 and 1ea8fad.

📒 Files selected for processing (2)
  • custom_components/nodered/binary_sensor.py (2 hunks)
  • custom_components/nodered/switch.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
custom_components/nodered/binary_sensor.py (2)

6-6: LGTM: Import statement added correctly

The new import statement for LockState from homeassistant.components.lock is correctly placed and necessary for the subsequent use of LockState.UNLOCKED. This change aligns with the PR objective of updating the integration to use the correct schemas and constants.


Line range hint 1-80: Overall impact: Positive change with no negative side effects

The changes made to this file are focused and beneficial:

  1. They address the warning about using incorrect schemas as mentioned in the PR objectives.
  2. They improve type safety by using an enum value (LockState.UNLOCKED) instead of a string constant.
  3. The changes maintain backwards compatibility and don't affect the existing logic of the binary sensor.

These updates enhance the integration's compliance with Home Assistant's expected schemas without introducing any apparent negative side effects or breaking changes.

custom_components/nodered/switch.py (2)

Line range hint 62-64: Verify compatibility with async_register_entity_service

The simplified SERVICE_TRIGGER_SCHEMA is correctly used in the async_register_entity_service method. However, let's ensure that this method accepts a plain dictionary as the schema argument in the current Home Assistant version.

To confirm this, please run the following command to check the async_register_entity_service method signature in the Home Assistant core:

#!/bin/bash
# Description: Check async_register_entity_service method signature

# Test: Search for async_register_entity_service method definition
rg --type python 'def async_register_entity_service' homeassistant/helpers/entity_platform.py

If the method accepts a plain dictionary, no further changes are needed. If it requires a vol.Schema object, we may need to update the registration code.


34-38: Approved: Schema simplification resolves the warning.

The change from vol.Schema to a plain dictionary for SERVICE_TRIGGER_SCHEMA is correct and addresses the warning about using an incorrect schema for entity service registration. This modification ensures compatibility with Home Assistant Core 2025.9 and beyond.

The simplified schema maintains the same validation rules for the fields, which is good for maintaining consistency in the service's behavior.

Let's verify if there are any other occurrences of vol.Schema in the file that might need similar updates:

✅ Verification successful

Verified: No remaining vol.Schema usages found.

The change from vol.Schema to a plain dictionary for SERVICE_TRIGGER_SCHEMA has been successfully applied. No other instances of vol.Schema were detected in custom_components/nodered/switch.py, ensuring that the warning about incorrect schema usage is resolved.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other vol.Schema usages in the file

# Test: Search for vol.Schema usages
rg --type python 'vol\.Schema' custom_components/nodered/switch.py

Length of output: 126


Script:

#!/bin/bash
# Description: Re-check for other vol.Schema usages in the file without specifying file type

# Test: Search for vol.Schema usages
rg 'vol\.Schema' custom_components/nodered/switch.py

Length of output: 54

@RogerSelwyn
Copy link
Contributor Author

Probably done this wrong somehow, since it seems to have included a minor change from my previous pull. I don't think it is an issue.

@RogerSelwyn RogerSelwyn deleted the patch-2 branch October 12, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant