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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

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.153.2 to 2.153.3.

@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.153.3 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.153.2 to 2.153.3
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

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! 🎉


📜 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 0999995 and 7b00cc8.

⛔ Files ignored due to path filters (1)
  • test/TDeviceTemplatesTest.Validate.dat is excluded by !**/*.dat
📒 Files selected for processing (1)
  • 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 (6)

10-11: LGTM: Constants for button mode and matrix outputs.

The new constants IN_MODE_BUTTON and MMATRIX_OUTPUTS_NUMBER are well-defined and used consistently throughout the template.


183-206: Consider adding validation for time parameters.

The button press parameters have good default values and descriptions, but there might be timing-related issues:

  1. lp_hold_time (long press) is 1000ms by default
  2. secp_waiting_time (second press) is 300ms by default

These timings could conflict if a user sets secp_waiting_time > lp_hold_time, potentially causing ambiguous button press detection.

Consider adding a validation to ensure secp_waiting_time < lp_hold_time to prevent timing conflicts.


208-271: LGTM: Comprehensive button action configuration.

The implementation provides a complete set of button actions:

  • Short press (sp)
  • Long press (lp)
  • Double press (dp)
  • Short then long press (slp)

Each action type has appropriate options:

  • For regular outputs: do nothing, off, on, toggle
  • For alarm output: do nothing, off (restricted options for safety)

489-527: LGTM: Button press counters with proper conditions.

The implementation includes counters for all press types:

  • Single press counter
  • Long press counter
  • Double press counter
  • Short-then-long press counter

Each counter is:

  • Properly disabled by default (enabled: false)
  • Correctly conditioned on button mode
  • Set as sporadic for efficient updates

625-631: LGTM: Clear English translations for button parameters.

The translations provide clear descriptions and recommendations:

  • Debounce time: 50ms recommended
  • Long press time: 1000ms recommended
  • Second press waiting time: 300ms recommended

731-738: LGTM: Clear Russian translations for button parameters.

The Russian translations are accurate and maintain consistency with the English versions, including all recommendations and technical details.


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

debian/changelog Show resolved Hide resolved
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