Skip to content

Implement enable/disable production services#247

Merged
bouwew merged 18 commits intomainfrom
enable_production
Jun 1, 2025
Merged

Implement enable/disable production services#247
bouwew merged 18 commits intomainfrom
enable_production

Conversation

@bouwew
Copy link
Copy Markdown
Contributor

@bouwew bouwew commented May 29, 2025

Summary by CodeRabbit

  • New Features
    • Added services to enable and disable production logging for Plugwise USB devices via MAC address.
  • Improvements
    • Enhanced user interface translations and service descriptions for the new production logging services in English and Dutch.
  • Chores
    • Updated dependency to plugwise-usb version 0.41.0.
    • Updated changelog and bumped integration version to 0.51.0.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2025

"""

Walkthrough

This update introduces two new services—enable and disable production measurements—for Plugwise USB devices, requiring a MAC address as input. The services are implemented, registered, and documented, with corresponding constants, schema, and translations added. The plugwise-usb library dependency is updated to version 0.41.0, and the integration version is incremented.

Changes

File(s) Change Summary
custom_components/plugwise_usb/init.py Added async service handlers and registration for enabling/disabling production measurements.
custom_components/plugwise_usb/const.py Added service name constants for enable/disable production; added type annotations; enhanced MAC regex validation.
custom_components/plugwise_usb/manifest.json Updated dependency to plugwise-usb 0.41.0 and version to 0.51.0.
custom_components/plugwise_usb/services.yaml Added enable_production and disable_production service definitions with required MAC field.
custom_components/plugwise_usb/strings.json
custom_components/plugwise_usb/translations/en.json
custom_components/plugwise_usb/translations/nl.json
Added service descriptions, names, and field prompts/translations for new services.
CHANGELOG.md Documented new services and library update under v0.51.0.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HomeAssistant
    participant PlugwiseUSB Integration
    participant Plugwise Node

    User->>HomeAssistant: Call enable_production/disable_production service (with MAC)
    HomeAssistant->>PlugwiseUSB Integration: Forward service call
    PlugwiseUSB Integration->>Plugwise Node: set_energy_intervals (enable: 60,60 / disable: 60,0)
    Plugwise Node-->>PlugwiseUSB Integration: Response/acknowledgment
    PlugwiseUSB Integration-->>HomeAssistant: Service completion
    HomeAssistant-->>User: Service result/confirmation
Loading

Suggested reviewers

  • brefra
  • ArnoutD

Poem

A rabbit hopped with code so neat,
Now Plugwise logs production heat!
Enable, disable, just say the word—
MAC address in, your wish is heard.
With new translations, the world can see,
This update brings more harmony!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e4193e and a628fed.

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@bouwew bouwew force-pushed the enable_production branch from d784aca to 9b82b8d Compare May 31, 2025 13:45
@bouwew bouwew marked this pull request as ready for review May 31, 2025 13:48
@bouwew bouwew requested a review from a team as a code owner May 31, 2025 13:48
Copy link
Copy Markdown
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: 2

🧹 Nitpick comments (7)
CHANGELOG.md (1)

5-8: Refine wording for clarity
The term "production logging" may be ambiguous. Consider rephrasing to "production measurement" to align with the service names and documentation.

custom_components/plugwise_usb/const.py (1)

35-36: Add explicit type annotation
Consider annotating service constants with their types for consistency and clarity, e.g.:

SERVICE_DISABLE_PRODUCTION: Final[str] = "disable_production"
SERVICE_ENABLE_PRODUCTION: Final[str] = "enable_production"
custom_components/plugwise_usb/translations/nl.json (2)

30-39: Refine Dutch translation for enable_production

  • Use Dutch spelling MAC-adres instead of English MAC address.
  • End the description with a period instead of a colon to match other entries.
    Example fix:
- "description": "Voer het mac-adres van de Node in:"
+ "description": "Voer het MAC-adres van de Node in."

40-49: Refine Dutch translation for disable_production

  • Use Dutch spelling MAC-adres.
  • Replace the trailing colon with a period.
    Example fix:
- "description": "Voer het mac-adres van the Node in:"
+ "description": "Voer het MAC-adres van de Node in."
custom_components/plugwise_usb/translations/en.json (1)

30-49: Clarify MAC address format requirements for better user experience.

The service descriptions specify "16 character MAC address" but don't clarify the expected format. Consider specifying whether the MAC should include separators (colons/hyphens) and case requirements to prevent user confusion.

Consider updating the MAC address descriptions to be more specific:

-          "description": "The full 16 character MAC address of the plugwise device."
+          "description": "The full 16 character MAC address of the plugwise device (format: AABBCCDDEEFF, without separators)."
custom_components/plugwise_usb/strings.json (1)

30-49: Clarify MAC address format requirements for consistency.

Same as the translations file, the MAC address descriptions should specify the expected format to improve user experience and reduce support issues.

Apply the same format clarification as suggested for the translations file:

-          "description": "The full 16 character MAC address of the plugwise device."
+          "description": "The full 16 character MAC address of the plugwise device (format: AABBCCDDEEFF, without separators)."
custom_components/plugwise_usb/__init__.py (1)

131-147: Document magic numbers and improve error specificity.

The implementation uses hardcoded values (60) without explanation. Consider using named constants for better maintainability and clarity.

+# Constants for production measurement intervals
+PRODUCTION_MEASUREMENT_INTERVAL = 60
+PRODUCTION_ENABLED_VALUE = 60
+PRODUCTION_DISABLED_VALUE = 0
+
 async def enable_production(call: ServiceCall) -> bool:
     """Enable production-measurement for a Node."""
     mac = call.data[ATTR_MAC]
     try:
-        result = await api_stick.set_measure_interval(mac, 60, 60)
+        result = await api_stick.set_measure_interval(mac, PRODUCTION_MEASUREMENT_INTERVAL, PRODUCTION_ENABLED_VALUE)
     except (NodeError, StickError) as exc:
-        raise HomeAssistantError(f"Failed to enable production: {exc}") from exc
+        raise HomeAssistantError(f"Failed to enable production measurements for device {mac}: {exc}") from exc
     return result

 async def disable_production(call: ServiceCall) -> bool:
     """Disable production-measurement for a Node."""
     mac = call.data[ATTR_MAC]
     try:
-        result = await api_stick.set_measure_interval(mac, 60, 0)
+        result = await api_stick.set_measure_interval(mac, PRODUCTION_MEASUREMENT_INTERVAL, PRODUCTION_DISABLED_VALUE)
     except (NodeError, StickError) as exc:
-        raise HomeAssistantError(f"Failed to disable production: {exc}") from exc
+        raise HomeAssistantError(f"Failed to disable production measurements for device {mac}: {exc}") from exc
     return result
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e413070 and 9b82b8d.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • custom_components/plugwise_usb/__init__.py (3 hunks)
  • custom_components/plugwise_usb/const.py (1 hunks)
  • custom_components/plugwise_usb/manifest.json (1 hunks)
  • custom_components/plugwise_usb/services.yaml (1 hunks)
  • custom_components/plugwise_usb/strings.json (1 hunks)
  • custom_components/plugwise_usb/translations/en.json (1 hunks)
  • custom_components/plugwise_usb/translations/nl.json (1 hunks)
🔇 Additional comments (2)
custom_components/plugwise_usb/manifest.json (1)

11-12: Integration version and requirement bump look correct
The plugwise-usb dependency is updated to 0.41.0 and the integration version to 0.51.0, matching the CHANGELOG entry.

custom_components/plugwise_usb/__init__.py (1)

7-7: LGTM: Appropriate import for MAC address handling.

The import of ATTR_MAC from the device_tracker component is the correct way to access MAC address attributes in Home Assistant.

Comment thread custom_components/plugwise_usb/services.yaml Outdated
Comment thread custom_components/plugwise_usb/__init__.py
@bouwew bouwew force-pushed the enable_production branch from d2709d4 to cfda7be Compare May 31, 2025 14:26
@sonarqubecloud
Copy link
Copy Markdown

@bouwew bouwew requested review from ArnoutD and dirixmjm May 31, 2025 15:38
Copy link
Copy Markdown
Contributor

@dirixmjm dirixmjm left a comment

Choose a reason for hiding this comment

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

The new service calls look reasonable.

@bouwew bouwew merged commit 999044e into main Jun 1, 2025
16 checks passed
@bouwew bouwew deleted the enable_production branch June 1, 2025 15:38
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.

2 participants