Implement enable/disable production services#247
Conversation
|
""" WalkthroughThis 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
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
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
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 forenable_production
- Use Dutch spelling
MAC-adresinstead of EnglishMAC 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 fordisable_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
📒 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
Theplugwise-usbdependency is updated to0.41.0and the integration version to0.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_MACfrom the device_tracker component is the correct way to access MAC address attributes in Home Assistant.
|
dirixmjm
left a comment
There was a problem hiding this comment.
The new service calls look reasonable.



Summary by CodeRabbit