-
Notifications
You must be signed in to change notification settings - Fork 2
Implement setting of energy logging intervals #247
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
Conversation
WalkthroughThe changes add a new asynchronous method Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Stick
participant StickNetwork
participant CircleMeasureIntervalRequest
participant Device
User->>Stick: set_energy_intervals(mac, cons_interval, prod_interval)
Stick->>StickNetwork: set_energy_intervals(mac, cons_interval, prod_interval)
StickNetwork->>CircleMeasureIntervalRequest: create and send request
CircleMeasureIntervalRequest->>Device: send request
Device-->>CircleMeasureIntervalRequest: NodeResponse (POWER_LOG_INTERVAL_ACCEPTED)
CircleMeasureIntervalRequest-->>StickNetwork: return response
StickNetwork-->>Stick: return success
Stick-->>User: return True
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Pylint (3.3.7)plugwise_usb/__init__.pyplugwise_usb/messages/requests.pyplugwise_usb/messages/responses.py
✨ Finishing Touches
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 (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #247 +/- ##
==========================================
- Coverage 81.21% 80.97% -0.24%
==========================================
Files 36 36
Lines 7369 7418 +49
==========================================
+ Hits 5985 6007 +22
- Misses 1384 1411 +27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (1)
plugwise_usb/messages/requests.py (1)
1267-1267: Fix trailing whitespace in docstring.The docstring clarification about the expected response message is helpful, but there's trailing whitespace that should be removed.
Apply this diff to fix the whitespace issue:
- Response message: NodeResponse with ack-type POWER_LOG_INTERVAL_ACCEPTED + Response message: NodeResponse with ack-type POWER_LOG_INTERVAL_ACCEPTED🧰 Tools
🪛 Ruff (0.11.9)
1267-1267: Trailing whitespace
Remove trailing whitespace
(W291)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
plugwise_usb/__init__.py(1 hunks)plugwise_usb/messages/requests.py(2 hunks)plugwise_usb/messages/responses.py(1 hunks)plugwise_usb/network/__init__.py(2 hunks)plugwise_usb/nodes/helpers/pulses.py(3 hunks)pyproject.toml(1 hunks)tests/test_usb.py(3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
plugwise_usb/nodes/helpers/pulses.py (1)
plugwise_usb/nodes/helpers/counter.py (3)
timestamp(170-178)direction(209-211)is_consumption(229-231)
tests/test_usb.py (2)
plugwise_usb/nodes/helpers/pulses.py (7)
add_log(416-451)log_addresses_missing(795-797)production_logging(138-140)log_interval_consumption(143-145)log_interval_production(148-150)update_pulse_counter(272-314)collected_pulses(167-215)plugwise_usb/nodes/helpers/counter.py (2)
log_addresses_missing(119-121)is_consumption(229-231)
plugwise_usb/network/__init__.py (5)
plugwise_usb/messages/requests.py (18)
CirclePlusAllowJoiningRequest(454-485)CircleMeasureIntervalRequest(1262-1293)send(365-374)send(387-396)send(438-440)send(476-485)send(512-521)send(542-553)send(566-575)send(588-597)send(621-630)send(667-676)send(719-728)send(775-784)send(808-817)send(848-857)send(880-889)response(125-129)plugwise_usb/__init__.py (2)
set_measure_interval(213-221)name(141-143)plugwise_usb/connection/__init__.py (1)
send(231-242)plugwise_usb/exceptions.py (2)
NodeError(24-25)MessageError(20-21)plugwise_usb/messages/responses.py (1)
NodeResponseType(56-72)
plugwise_usb/messages/requests.py (3)
plugwise_usb/connection/__init__.py (1)
send(231-242)plugwise_usb/messages/responses.py (1)
NodeResponse(243-270)plugwise_usb/exceptions.py (1)
MessageError(20-21)
🪛 Ruff (0.11.9)
plugwise_usb/__init__.py
220-220: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
plugwise_usb/nodes/helpers/pulses.py
540-540: Trailing whitespace
Remove trailing whitespace
(W291)
plugwise_usb/network/__init__.py
548-548: Blank line contains whitespace
Remove whitespace from blank line
(W293)
plugwise_usb/messages/requests.py
1267-1267: Trailing whitespace
Remove trailing whitespace
(W291)
🔇 Additional comments (15)
plugwise_usb/nodes/helpers/pulses.py (3)
94-95: LGTM!The new boolean flags for tracking previous and next log existence are properly initialized.
444-450: Good improvement to debug logging!Including the direction in the log message will help with debugging pulse log issues.
570-575: Clever heuristic for production detection!The logic that sets
_log_productiontoTruewhen 2 out of 3 consecutive slots have the same timestamp is a smart way to detect production logging patterns.pyproject.toml (1)
7-7: LGTM!The alpha version bump to v0.41.0a4 is appropriate for a pre-release feature.
plugwise_usb/network/__init__.py (1)
17-21: LGTM: Import addition is appropriate.The addition of
CircleMeasureIntervalRequestto the imports is necessary for the new functionality and follows the existing import pattern.plugwise_usb/messages/requests.py (1)
1284-1294: LGTM: Send method implementation follows established patterns.The
sendmethod is well-implemented and consistent with other request classes in the file. It properly validates the response type and handles both success and error cases appropriately.tests/test_usb.py (6)
1221-1221: LGTM: Production pulse value correctly updated to negative.The change from positive to negative production pulse value (-2000) aligns with the refined pulse direction logic where negative pulses indicate production when production logging is enabled.
1229-1229: LGTM: Consumption pulse value correctly set to zero.The consumption pulse value is appropriately set to 0, which is consistent with the test scenario for production/consumption energy log validation.
1238-1238: LGTM: Production pulse value correctly updated to negative.The change to negative production pulse value (-2200) is consistent with the updated pulse direction logic in the PulseCollection class.
1248-1248: LGTM: Consumption pulse value correctly set to zero.The consumption pulse value is correctly set to 0, maintaining consistency with the production/consumption test scenario.
1255-1255: LGTM: Pulse counter values correctly updated.The pulse counter update with consumption=0 and production=-500 (negative) is consistent with the refined pulse direction logic where negative values represent production.
1258-1273: LGTM: Test assertions correctly updated to match new pulse logic.The assertions have been properly updated to reflect the new behavior:
- Consumption assertions now expect 0 values (lines 1258, 1264, 1267)
- Production assertions expect positive values (500, 2000, 2500) which are correctly converted from negative input values (-500, -2000, -2200) by the
collected_pulsesmethod that returns absolute valuesThis aligns with the relevant code snippet showing that
collected_pulsesalways returns positive values for energy statistics:return (abs(pulses + log_pulses), timestamp).plugwise_usb/messages/responses.py (3)
59-59: Clarified comment for CIRCLE_PLUS enum member
The updated comment makes it explicit that this value is an acknowledgment forCirclePlusAllowJoiningRequestwith statefalse, improving readability.
61-61: Clarified comment for JOIN_ACCEPTED enum member
The refined comment now clearly denotes this as an acknowledgment forCirclePlusAllowJoiningRequestwith statetrue, enhancing clarity.
62-62: Added POWER_LOG_INTERVAL_ACCEPTED to NodeResponseType
Introducing thePOWER_LOG_INTERVAL_ACCEPTEDmember aligns with the new measurement interval request/response flow and ensures proper acknowledgment handling.
There was a problem hiding this 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
🧹 Nitpick comments (1)
plugwise_usb/network/__init__.py (1)
544-570: Method implementation is solid but fix whitespace issues.The
set_energy_intervalsmethod implementation follows good patterns with proper input validation, logging, and error handling. However, there are whitespace formatting issues that need to be addressed.Apply this diff to fix the whitespace issues:
"""Set the logging intervals for both energy consumption and production. - + Default: consumption = 60, production = 0. For logging energy in both directions set both to 60. """ # Validate input parameters if consumption <= 0: raise ValueError("Consumption interval must be positive") if production < 0: raise ValueError("Production interval must be non-negative") if production > 0 and production % consumption != 0: raise ValueError("Production interval must be a multiple of consumption interval") - _LOGGER.debug("set_energy_intervals | cons=%s, prod=%s", consumption, production) + _LOGGER.debug("set_energy_intervals | cons=%s, prod=%s", consumption, production) request = CircleMeasureIntervalRequest(🧰 Tools
🪛 Ruff (0.11.9)
548-548: Blank line contains whitespace
Remove whitespace from blank line
(W293)
560-560: Trailing whitespace
Remove trailing whitespace
(W291)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
plugwise_usb/__init__.py(1 hunks)plugwise_usb/network/__init__.py(2 hunks)plugwise_usb/nodes/helpers/pulses.py(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- plugwise_usb/init.py
- plugwise_usb/nodes/helpers/pulses.py
🧰 Additional context used
🪛 Ruff (0.11.9)
plugwise_usb/network/__init__.py
548-548: Blank line contains whitespace
Remove whitespace from blank line
(W293)
560-560: Trailing whitespace
Remove trailing whitespace
(W291)
🔇 Additional comments (1)
plugwise_usb/network/__init__.py (1)
17-21: Import addition looks good.The addition of
CircleMeasureIntervalRequestto the imports is appropriate and necessary for the newset_energy_intervalsmethod.
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugwise_usb/nodes/helpers/pulses.py(3 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
plugwise_usb/nodes/helpers/pulses.py
547-547: SyntaxError: Expected an indented block after function definition
548-548: SyntaxError: Unexpected indentation
🔇 Additional comments (3)
plugwise_usb/nodes/helpers/pulses.py (3)
94-95: LGTM! State tracking variables properly initialized.The new boolean flags
_next_log_existsand_prev_log_existsare appropriately initialized toFalseand will help track the existence of adjacent logs for improved direction detection logic.
444-449: Good enhancement to debug logging.Adding the
directionparameter to the debug log message provides valuable context for troubleshooting pulse direction detection issues.
519-543: LGTM! Well-structured helper method for previous log checking.The
_check_prev_productionmethod properly handles the logic for checking previous logs and updating consumption/production flags based on timestamp comparisons. The state tracking with_prev_log_existsimproves efficiency by ensuring checks are performed only once.
There was a problem hiding this 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 (1)
plugwise_usb/nodes/helpers/pulses.py (1)
380-381: Fix trailing whitespace and approve the explicit return.The explicit
return Falsestatement is good practice. However, there's trailing whitespace on line 380 that should be removed.Apply this diff to fix the whitespace:
- +🧰 Tools
🪛 Ruff (0.11.9)
380-380: Blank line contains whitespace
Remove whitespace from blank line
(W293)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugwise_usb/nodes/helpers/pulses.py(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
plugwise_usb/nodes/helpers/pulses.py (1)
plugwise_usb/nodes/helpers/counter.py (2)
direction(209-211)is_consumption(229-231)
🪛 Ruff (0.11.9)
plugwise_usb/nodes/helpers/pulses.py
380-380: Blank line contains whitespace
Remove whitespace from blank line
(W293)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Check commit
- GitHub Check: Check commit
🔇 Additional comments (3)
plugwise_usb/nodes/helpers/pulses.py (3)
94-95: LGTM! Good state tracking implementation.The new boolean flags
_next_log_processedand_prev_log_processedprovide proper state tracking for the refactored direction detection logic, ensuring each log is processed only once per invocation.
445-450: LGTM! Improved debug logging.Adding the
directionparameter to the debug logging provides valuable information for troubleshooting pulse direction detection issues.
511-518: Good refactoring approach with improved code organization.The extraction of complex direction detection logic into helper methods improves code readability and maintainability. The use of processed flags and timestamp comparisons follows a logical approach.
There was a problem hiding this 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
🧹 Nitpick comments (1)
plugwise_usb/nodes/helpers/pulses.py (1)
380-380: Fix trailing whitespace on blank line.The static analysis tool correctly identifies trailing whitespace on this blank line.
- +🧰 Tools
🪛 Ruff (0.11.9)
380-380: Blank line contains whitespace
Remove whitespace from blank line
(W293)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugwise_usb/nodes/helpers/pulses.py(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
plugwise_usb/nodes/helpers/pulses.py (1)
plugwise_usb/nodes/helpers/counter.py (3)
timestamp(170-178)direction(209-211)is_consumption(229-231)
🪛 Ruff (0.11.9)
plugwise_usb/nodes/helpers/pulses.py
380-380: Blank line contains whitespace
Remove whitespace from blank line
(W293)
🔇 Additional comments (5)
plugwise_usb/nodes/helpers/pulses.py (5)
91-92: LGTM! Good state management improvement.The new boolean flags
_first_next_log_processedand_first_prev_log_processedprovide clear state tracking for the refactored log direction detection logic. This ensures each log is processed only once per invocation, improving the robustness of the algorithm.
445-450: LGTM! Enhanced debugging information.Adding the
directionparameter to the debug logging provides valuable context for troubleshooting energy flow direction issues. This will help with debugging consumption vs production pulse logging.
511-518: LGTM! Well-structured refactoring.The refactored logic properly delegates to helper methods and uses the returned timestamps for accurate direction detection. The condition correctly identifies production logging when 2 out of 3 consecutive slots have the same timestamp, and handles None values appropriately when logs don't exist.
520-545: LGTM! Robust helper method implementation.The
_check_prev_productionmethod correctly handles all edge cases:
- Returns
Nonewhen logs don't exist (avoiding undefined variable issues)- Uses state tracking to ensure logs are processed only once
- Properly manages consumption/production direction based on timestamp equality
- Resets state flags when logs are no longer available
The logic for energy direction detection is sound and well-implemented.
547-572: LGTM! Consistent and well-implemented helper method.The
_check_next_productionmethod maintains excellent consistency with its counterpart_check_prev_production. It properly:
- Handles missing logs by returning
None- Uses state tracking with
_first_next_log_processedflag- Implements correct energy direction logic for next log timestamps
- Maintains code symmetry for better maintainability
The implementation addresses all the issues identified in previous reviews and provides a robust solution for production pulse detection.
Allows to enable/disable production measurements
|
There was a problem hiding this 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
♻️ Duplicate comments (1)
plugwise_usb/network/__init__.py (1)
544-570: Excellent implementation with comprehensive input validation.The method addresses the previous review feedback by implementing proper input validation:
- Ensures consumption interval is positive
- Ensures production interval is non-negative
- Validates production is a multiple of consumption when non-zero
- Proper error handling and response validation
The implementation follows established patterns and integrates well with the existing codebase.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 553-558: plugwise_usb/network/init.py#L553-L558
Added lines #L553 - L558 were not covered by tests
[warning] 560-561: plugwise_usb/network/init.py#L560-L561
Added lines #L560 - L561 were not covered by tests
[warning] 564-565: plugwise_usb/network/init.py#L564-L565
Added lines #L564 - L565 were not covered by tests
[warning] 567-568: plugwise_usb/network/init.py#L567-L568
Added lines #L567 - L568 were not covered by tests
🧹 Nitpick comments (1)
plugwise_usb/messages/requests.py (1)
1267-1267: Fix trailing whitespace.Remove the trailing whitespace on line 1267 as flagged by static analysis.
- Response message: NodeResponse with ack-type POWER_LOG_INTERVAL_ACCEPTED + Response message: NodeResponse with ack-type POWER_LOG_INTERVAL_ACCEPTED🧰 Tools
🪛 Ruff (0.11.9)
1267-1267: Trailing whitespace
Remove trailing whitespace
(W291)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
CHANGELOG.md(1 hunks)plugwise_usb/__init__.py(1 hunks)plugwise_usb/messages/requests.py(2 hunks)plugwise_usb/messages/responses.py(1 hunks)plugwise_usb/network/__init__.py(2 hunks)plugwise_usb/nodes/helpers/pulses.py(4 hunks)pyproject.toml(1 hunks)scripts/tests_and_coverage.sh(1 hunks)tests/test_usb.py(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- CHANGELOG.md
- pyproject.toml
- tests/test_usb.py
- plugwise_usb/messages/responses.py
🧰 Additional context used
🧬 Code Graph Analysis (4)
plugwise_usb/__init__.py (2)
plugwise_usb/network/__init__.py (1)
set_energy_intervals(544-570)plugwise_usb/exceptions.py (2)
MessageError(20-21)NodeError(24-25)
plugwise_usb/messages/requests.py (4)
tests/test_usb.py (1)
send(252-258)plugwise_usb/connection/__init__.py (1)
send(231-242)plugwise_usb/messages/responses.py (1)
NodeResponse(243-270)plugwise_usb/exceptions.py (1)
MessageError(20-21)
plugwise_usb/network/__init__.py (5)
plugwise_usb/messages/requests.py (18)
CirclePlusAllowJoiningRequest(454-485)CircleMeasureIntervalRequest(1262-1293)send(365-374)send(387-396)send(438-440)send(476-485)send(512-521)send(542-553)send(566-575)send(588-597)send(621-630)send(667-676)send(719-728)send(775-784)send(808-817)send(848-857)send(880-889)response(125-129)plugwise_usb/__init__.py (2)
set_energy_intervals(213-221)name(141-143)plugwise_usb/connection/__init__.py (1)
send(231-242)plugwise_usb/exceptions.py (2)
NodeError(24-25)MessageError(20-21)plugwise_usb/messages/responses.py (3)
response_type(236-240)response_type(266-270)NodeResponseType(56-72)
plugwise_usb/nodes/helpers/pulses.py (1)
plugwise_usb/nodes/helpers/counter.py (3)
timestamp(170-178)direction(209-211)is_consumption(229-231)
🪛 GitHub Check: codecov/patch
plugwise_usb/__init__.py
[warning] 217-221: plugwise_usb/init.py#L217-L221
Added lines #L217 - L221 were not covered by tests
plugwise_usb/messages/requests.py
[warning] 1286-1291: plugwise_usb/messages/requests.py#L1286-L1291
Added lines #L1286 - L1291 were not covered by tests
plugwise_usb/network/__init__.py
[warning] 553-558: plugwise_usb/network/init.py#L553-L558
Added lines #L553 - L558 were not covered by tests
[warning] 560-561: plugwise_usb/network/init.py#L560-L561
Added lines #L560 - L561 were not covered by tests
[warning] 564-565: plugwise_usb/network/init.py#L564-L565
Added lines #L564 - L565 were not covered by tests
[warning] 567-568: plugwise_usb/network/init.py#L567-L568
Added lines #L567 - L568 were not covered by tests
plugwise_usb/nodes/helpers/pulses.py
[warning] 537-540: plugwise_usb/nodes/helpers/pulses.py#L537-L540
Added lines #L537 - L540 were not covered by tests
[warning] 542-542: plugwise_usb/nodes/helpers/pulses.py#L542
Added line #L542 was not covered by tests
[warning] 567-568: plugwise_usb/nodes/helpers/pulses.py#L567-L568
Added lines #L567 - L568 were not covered by tests
🪛 Ruff (0.11.9)
plugwise_usb/messages/requests.py
1267-1267: Trailing whitespace
Remove trailing whitespace
(W291)
🔇 Additional comments (10)
scripts/tests_and_coverage.sh (1)
26-27: Clarify the intent behind removing coverage collection.The change removes coverage collection from the test execution. Is this intentional for debugging purposes, or should coverage collection be retained?
Consider whether this change aligns with your testing and CI/CD requirements.
plugwise_usb/__init__.py (1)
213-221: LGTM! Clean implementation of the energy intervals configuration.The method properly delegates to the network layer with appropriate exception handling and chaining. The implementation follows the established patterns in the codebase.
Note: Static analysis indicates this code lacks test coverage, but the functionality appears correct.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 217-221: plugwise_usb/init.py#L217-L221
Added lines #L217 - L221 were not covered by testsplugwise_usb/messages/requests.py (1)
1284-1293: LGTM! The send method follows established patterns.The implementation correctly validates the response type and handles error cases appropriately, consistent with other request classes in the module.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 1286-1291: plugwise_usb/messages/requests.py#L1286-L1291
Added lines #L1286 - L1291 were not covered by testsplugwise_usb/network/__init__.py (1)
17-21: LGTM! Import statement correctly updated.The addition of
CircleMeasureIntervalRequestto the imports is necessary for the new functionality.plugwise_usb/nodes/helpers/pulses.py (6)
91-92: LGTM! Good state tracking enhancement.The addition of
_first_next_log_processedand_first_prev_log_processedflags improves the robustness of the direction detection logic by ensuring adjacent logs are processed only once per invocation.
382-383: LGTM! Explicit return improves code clarity.Adding the explicit
return Falsestatement makes the function's behavior more predictable and follows good defensive programming practices.
446-446: LGTM! Enhanced debug logging.Adding the
directionparameter to the debug logging provides valuable context for troubleshooting pulse direction detection issues.
512-520: LGTM! Well-structured refactoring.The delegation to helper methods
_check_prev_productionand_check_next_productionimproves code organization and maintainability. The logic correctly implements the business rule where production is detected when 2 out of 3 consecutive slots have the same timestamp.
549-575:❓ Verification inconclusive
LGTM with test coverage improvement needed.
The
_check_next_productionmethod mirrors the structure of_check_prev_productionand is correctly implemented with proper state tracking and error handling for the next slot processing.Static analysis indicates test coverage gaps for lines 567-568. Please ensure comprehensive unit tests cover all code paths in this method, particularly the conditional branches for different
_log_productionstates.
🏁 Script executed:
#!/bin/bash # Check if there are existing tests for the next production logic rg -A 10 -B 5 "_check_next_production|next.*production" tests/Length of output: 64
Ensure test coverage for
_check_next_productionI wasn’t able to find any existing tests that exercise this new helper, and static analysis shows lines 567–568 remain untested. Please add unit tests covering all branches in this method, including:
- Next log exists vs. missing
_first_next_log_processedtransitions- All combinations of
timestampequality and_log_productionbeingTrue,False, orNoneFile to cover:
• plugwise_usb/nodes/helpers/pulses.py (lines 549–575)🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 567-568: plugwise_usb/nodes/helpers/pulses.py#L567-L568
Added lines #L567 - L568 were not covered by tests
521-547:❓ Verification inconclusive
LGTM with test coverage improvement needed.
The
_check_prev_productionmethod is well-implemented with proper state tracking and error handling. The logic correctly processes the previous slot only once per invocation and handles missing logs appropriately.However, static analysis indicates test coverage gaps for lines 537-540 and 542. Please add unit tests to cover the edge cases in this method, particularly:
- When
_log_productionis True but not None- When
_log_productionis None
🏁 Script executed:
#!/bin/bash # Check current test coverage for this method rg -A 10 -B 5 "_check_prev_production" tests/Length of output: 45
Add unit tests for
_check_prev_productionedge casesI wasn’t able to find any existing tests that directly exercise this helper. Please ensure that all code paths in
_check_prev_productionare covered, in particular:
- When there is no previous log (
_first_prev_log_processedreset path)- When
_log_productionis initiallyNoneand set toFalse- When
_log_productionisTrueand the previous log’sis_consumptionflag is toggled- When a duplicate timestamp is detected on the second log (both logs’
is_consumptionflags switched)Once you’ve added those tests, verify via your coverage report that lines 537–540 and 542 in
plugwise_usb/nodes/helpers/pulses.pyare exercised.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 537-540: plugwise_usb/nodes/helpers/pulses.py#L537-L540
Added lines #L537 - L540 were not covered by tests
[warning] 542-542: plugwise_usb/nodes/helpers/pulses.py#L542
Added line #L542 was not covered by tests



Summary by CodeRabbit