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

Add buttons support in WB-MWAC v.1 template #858

Merged
merged 8 commits into from
Feb 4, 2025

Conversation

ad7718
Copy link
Contributor

@ad7718 ad7718 commented Jan 28, 2025

Добавил поддержку нажатий в шаблон WB-MWAC v.1, в прошивке поддержка уже есть.

Summary by CodeRabbit

  • New Features

    • Added support for buttons in the WB-MWAC template.
    • Introduced new input parameters for button press actions.
    • Enhanced input handling with debounce and hold time configurations.
  • Documentation

    • Updated translations for new button-related parameters.
    • Improved localization for English and Russian languages.
  • Version Update

    • Package version upgraded from 2.154.2 to 2.155.0.

@ad7718 ad7718 requested review from a team, KraPete and sikmir as code owners January 28, 2025 09:26
Copy link

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request introduces version 2.155.0 of the wb-mqtt-serial package, focusing on adding button support to the WB-MWAC template. The changes enhance the configuration file by introducing new input parameters, press action definitions, and localization entries. The modification allows for more sophisticated input handling, specifically for button interactions, with detailed configurations for different types of button presses.

Changes

File Change Summary
debian/changelog Version updated from 2.154.2 to 2.155.0; added support for buttons in WB-MWAC template.
templates/config-wb-mwac.json.jinja - Added IN_MODE_BUTTON and MMATRIX_OUTPUTS_NUMBER variables
- Introduced "Press Parameters" for input actions
- Added debounce and hold time configurations
- Expanded translations for new button-related parameters

Possibly related PRs

  • Add WB-MIR v3 template, update WB-MIR v2 template #825: The changes in the main PR, which enhance button support in the WB-MWAC template, are related to the retrieved PR that also introduces a new template for WB-MIR with button support, indicating a shared focus on improving button input handling across different templates.
  • Feature/fw 274 mcm debounce #855: The changes in the main PR, which enhance button input handling in the WB-MWAC template, are related to the modifications in the retrieved PR that adjust debounce settings, as both involve improvements to input handling configurations within different templates of the wb-mqtt-serial package.

Suggested reviewers

  • KraPete
  • sikmir
  • pgasheev

Poem

🐰 Buttons dance, a digital delight,
In WB-MWAC's template, shining bright
Short press, long press, actions unfurl
Configuration magic begins to swirl
A rabbit's code, with buttons so neat! 🎉


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 17c82e6 and 0999995.

📒 Files selected for processing (2)
  • debian/changelog (1 hunks)
  • templates/config-wb-mwac.json.jinja (9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (6)
templates/config-wb-mwac.json.jinja (5)

10-11: LGTM! Constants are well-defined and consistently used.

The new constants IN_MODE_BUTTON and MMATRIX_OUTPUTS_NUMBER follow the existing naming convention and are used consistently throughout the template.


487-526: Button press counters are properly implemented with real-time updates.

The implementation includes:

  • Separate counters for each press type
  • Proper sporadic flag for real-time updates
  • Disabled by default to avoid unnecessary traffic

Line range hint 624-734: Translations are complete and well-documented.

The implementation includes:

  • Comprehensive translations for all new features
  • Clear descriptions with recommended values
  • Both English and Russian translations

144-205: Button mode parameters are well-structured with clear constraints.

The implementation includes:

  • Proper debounce handling with mode-specific descriptions
  • Reasonable defaults and ranges for timing parameters
  • Clear conditions for parameter visibility

However, consider adding validation to ensure in{n}_debounce_ms is 5-10 times less than in{n}_secp_waiting_time as mentioned in the description.

Run this script to verify the relationship between debounce and waiting time:

✅ Verification successful

Default timing parameters are correctly configured, but runtime validation is needed

The default values (debounce: 50ms, waiting time: 300ms) maintain the recommended 5-10x relationship. However, since these are configurable parameters, consider implementing runtime validation to ensure this relationship is maintained when users modify the values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that debounce time is 5-10 times less than waiting time
# Expected: No instances where debounce >= waiting_time/5

for i in {1..6}; do
  echo "Checking input $i..."
  # Get debounce value
  rg -A 2 "in${i}_debounce_ms.*default.*" | grep "default"
  # Get waiting time value
  rg -A 2 "in${i}_secp_waiting_time.*default.*" | grep "default"
done

Length of output: 1085


206-271: Button press actions are comprehensive and well-organized.

The implementation includes:

  • Four types of button presses with appropriate actions
  • Different actions for alarm vs regular outputs
  • Proper address calculations using offsets

Consider adding validation to ensure the address ranges don't overlap with existing registers.

Run this script to check for address overlaps:

✅ Verification successful

Button press action addresses are properly separated and non-overlapping

The address calculations use well-defined ranges with sufficient gaps:

  • Base addresses (544, 608, 672, 736) are separated by 64 addresses
  • Each input's block of 8 addresses fits within these gaps
  • No other template addresses overlap with these ranges
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential address overlaps in register mappings
# Expected: No overlapping addresses

# Extract all address definitions
rg '"address":\s*\d+' -o | sort -n | uniq -d

Length of output: 18618


Script:

#!/bin/bash
# Description: Check for address overlaps specifically in button press action ranges
# Expected: No overlapping addresses in these ranges

# Extract addresses from config-wb-mwac.json.jinja and check if they fall in our ranges
rg '"address":\s*(\d+)' -o templates/config-wb-mwac.json.jinja | 
  grep -o '[0-9]\+' | 
  sort -n | 
  awk '
    ($1 >= 544 && $1 <= 799) {
      range = "unknown"
      if ($1 >= 544 && $1 <= 607) range = "short press"
      else if ($1 >= 608 && $1 <= 671) range = "long press"
      else if ($1 >= 672 && $1 <= 735) range = "double press"
      else if ($1 >= 736 && $1 <= 799) range = "short then long press"
      print $1, range
    }
  ' | uniq -d

Length of output: 448


Script:

#!/bin/bash
# Description: Check if file exists and show all addresses in button press ranges
# Expected: See all addresses in the ranges 544-799

# First check if file exists
echo "Checking file existence:"
ls -l templates/config-wb-mwac.json.jinja

echo -e "\nAll addresses in button press ranges:"
rg '"address":\s*(\d+)' -o templates/config-wb-mwac.json.jinja | 
  grep -o '[0-9]\+' | 
  sort -n | 
  awk '
    ($1 >= 544 && $1 <= 799) {
      range = "unknown"
      if ($1 >= 544 && $1 <= 607) range = "short press"
      else if ($1 >= 608 && $1 <= 671) range = "long press"
      else if ($1 >= 672 && $1 <= 735) range = "double press"
      else if ($1 >= 736 && $1 <= 799) range = "short then long press"
      print $1, range
    }
  '

Length of output: 718


Script:

#!/bin/bash
# Description: Check address calculations in Jinja template
# Expected: Find address calculation patterns for button actions

echo "Searching for address calculations:"
rg --multiline '"address":\s*\{\{.*?\}\}' templates/config-wb-mwac.json.jinja

echo -e "\nChecking for MMATRIX_OUTPUTS_NUMBER definition:"
rg "MMATRIX_OUTPUTS_NUMBER\s*=" templates/config-wb-mwac.json.jinja

Length of output: 1839

debian/changelog (1)

1-5: LGTM! The changelog entry follows the Debian format.

The changelog entry is well-formatted and includes all required fields:

  • Package name and version
  • Distribution and urgency
  • Change description
  • Author's name and email
  • Timestamp

Comment on lines 52 to 59
{% for out_num in range(1, OUTPUTS_NUMBER + 1) -%}
{
"title":
{% if out_num == OUT_NUM_K1 %} "Output K1 actions",
{% elif out_num == OUT_NUM_K2 %} "Output K2 actions",
{% elif out_num == OUT_NUM_ALARM %} "Actions for \"Leakage\" mode",
{% else %} "Actions for \"Wet cleaning\" mode",
{% endif %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{% for out_num in range(1, OUTPUTS_NUMBER + 1) -%}
{
"title":
{% if out_num == OUT_NUM_K1 %} "Output K1 actions",
{% elif out_num == OUT_NUM_K2 %} "Output K2 actions",
{% elif out_num == OUT_NUM_ALARM %} "Actions for \"Leakage\" mode",
{% else %} "Actions for \"Wet cleaning\" mode",
{% endif %}
{% set titles = {
OUT_NUM_K1: "Output K1 actions",
OUT_NUM_K2: "Output K2 actions",
OUT_NUM_ALARM: 'Actions for \\"Leakage\\" mode'
} -%}
{% for out_num in range(1, OUTPUTS_NUMBER + 1) -%}
{
"title": "{{ titles.get(out_num, 'Actions for \\"Wet cleaning\\" mode') }}",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

сделал

@ad7718 ad7718 requested a review from sikmir February 3, 2025 05:47
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

🧹 Nitpick comments (1)
templates/config-wb-mwac.json.jinja (1)

143-182: Consider restricting debounce range for button mode.

While the conditional display of debounce parameters based on mode is well implemented, the debounce range (0-2000ms) for button mode might be too wide. According to the description, it should be 5-10 times less than the second press waiting time (which defaults to 300ms).

Consider applying this change:

             "in{{ in_num }}_debounce_ms": {
                 "min": 0,
-                "max": 2000,
+                "max": 100,
                 "default": 50,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7b00cc8 and 5578b7e.

⛔ Files ignored due to path filters (1)
  • test/TDeviceTemplatesTest.Validate.dat is excluded by !**/*.dat
📒 Files selected for processing (2)
  • debian/changelog (1 hunks)
  • templates/config-wb-mwac.json.jinja (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • debian/changelog
🔇 Additional comments (7)
templates/config-wb-mwac.json.jinja (7)

10-11: LGTM! Constants are well-defined and used consistently.

The new constants IN_MODE_BUTTON and MMATRIX_OUTPUTS_NUMBER are appropriately defined and used throughout the configuration for button mode and address calculations.


41-45: LGTM! Press parameters group is well-structured.

The press parameters are logically grouped under each input, providing good organization and clarity.


52-63: Implementation matches previous review suggestions.

The titles dictionary and group generation for button actions aligns with the previously suggested implementation.


183-206: LGTM! Press timing parameters are well-configured.

The timing parameters have appropriate ranges and defaults that align with the descriptions and recommended values.


207-271: LGTM! Button press actions are comprehensive and well-implemented.

The implementation:

  • Supports all press types (short, long, double, short-then-long)
  • Correctly handles special case for alarm output
  • Uses proper address calculations

488-527: LGTM! Press counters provide useful debugging capabilities.

The press counters are well-implemented with:

  • Coverage for all press types
  • Disabled by default to avoid cluttering the interface
  • Proper mode conditions

625-741: LGTM! Translations are comprehensive and helpful.

The translations:

  • Cover all new parameters and actions
  • Provide clear descriptions with recommended values
  • Support both English and Russian languages

@ad7718 ad7718 merged commit 04563ec into master Feb 4, 2025
13 checks passed
@ad7718 ad7718 deleted the feature/mwac_v1-buttons-support branch February 4, 2025 12:29
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.

3 participants