Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

0189-WebUI-Fix-ControlHmIP-MOD-RC8 #2892

Merged

Conversation

jp112sdl
Copy link
Contributor

@jp112sdl jp112sdl commented Nov 3, 2024

Description

Mit Version 3.79.6 wurde der Kanaltyp von KEY_TRANSCEIVER auf MULTI_MODE_TRANSMITTER geändert.
Somit wird zum Bauen der Controls in der WebUI in eine andere Sektion eingesprungen, die verlangt, dass es zum Kanal Metadaten gibt ("channelMode") mit dem Wert "3", siehe /www/rega/esp/datapointconfigurator.fn#L591

Das Kanalobjekt hat mit der Umstellung der Kanaltyps jedoch keine zusätzlichen Metadaten bekommen.
Somit ist es notwendig, die frühere Methode key_switch_sc.fn::CreateContent() zu verwenden.
Dabei wird letztendlich der CHANNEL_OPERATION_MODE direkt aus dem Master-Paramset ausgewertet (/www/webui/webui.js#L41867-L41879)

Related Issue

#2891

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Alternate Designs

Possible Drawbacks

Verification Process

Release Notes

Contributing checklist

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING and LICENSE document.
  • I fully agree to distribute my changes under Apache 2.0 license.

Summary by CodeRabbit

  • New Features

    • Enhanced web user interface for control devices with improved HTML table generation.
    • New functions added for dynamic control creation and error handling, enhancing user interaction.
  • Bug Fixes

    • Updated logic for handling different channel modes, ensuring appropriate function calls based on conditions.

Copy link

coderabbitai bot commented Nov 3, 2024

Walkthrough

The changes in this pull request involve modifications to the datapointconfigurator.fn file within the web user interface for control devices. The control flow has been updated to invoke different functions based on the channelMode value. Additionally, new functions have been introduced to create HTML tables and manage various control types dynamically, enhancing the interface's responsiveness and functionality.

Changes

File Path Change Summary
buildroot-external/patches/occu/0189-WebUI-Fix-ControlHmIP-MOD-RC8/occu/WebUI/www/rega/esp/datapointconfigurator.fn - Updated method call from CreateNoFunction() to CreateContent() based on channelMode value.
- Added functions: dcCreateTable(), dcCreate(), StringCut(), CreateEventInterface(), CreateChannelNotActive(), CreateNoFunction(), CreateUnknown(), CreateSysVar(), CreateSysVars(), HideCertainParameters().

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebUI
    participant ControlLogic

    User->>WebUI: Request control interface
    WebUI->>ControlLogic: Check channelMode
    alt channelMode == 3
        ControlLogic-->>WebUI: Call CreateDoorWindowContact()
    else channelMode != 3
        ControlLogic-->>WebUI: Call CreateContent()
    end
    WebUI-->>User: Display updated control interface
Loading

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 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.

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

🧹 Outside diff range and nitpick comments (3)
buildroot-external/patches/occu/0189-WebUI-Fix-ControlHmIP-MOD-RC8/occu/WebUI/www/rega/esp/datapointconfigurator.fn (3)

682-694: Simplify nested conditions for better readability

The nested if-else statements can be refactored for clarity and maintainability. Simplifying the logic makes it easier to understand and reduces the potential for errors.

Refactored code:

if ((ch.HssType() == "MULTI_MODE_INPUT_TRANSMITTER") && (ch.Label() != "ELV-SH-BM-S")) {
  if (ch.Label().Find("MOD-RC8") != -1) {
    WriteLine("<script>conInfo('HmIP-MOD-RC8 found');</script>");
    Call("/esp/controls/key_switch_sc.fn::CreateContent()");
  } else {
    Call("/esp/datapointconfigurator.fn::CreateNoFunction()");
  }
} else if (ch.Label() == "ELV-SH-BM-S") {
  WriteLine("<script>conInfo('ELV-SH-BM-S found');</script>");
  Call("/esp/controls/key_switch_sc.fn::CreateContentA()");
} else {
  Call("/esp/datapointconfigurator.fn::CreateNoFunction()");
}

91-169: Consider moving control name constants to a separate configuration file

The numerous control name constants defined within the function clutter the code and make maintenance harder. Moving these constants to a separate configuration file or module can enhance readability and centralize the constants for easier updates.


202-203: Remove unnecessary debugging statements

The WriteLine statements used for debugging purposes should be removed or commented out in the production code to avoid cluttering the console output and potentially exposing internal logic.

Apply this diff to remove the debugging statements:

-WriteLine( "<script>console.log('oE.ID(): "#oE.ID()#"');</script>" );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 16d83b2 and 8c2c8e2.

⛔ Files ignored due to path filters (1)
  • buildroot-external/patches/occu/0189-WebUI-Fix-ControlHmIP-MOD-RC8/occu/WebUI/www/rega/esp/datapointconfigurator.fn.orig is excluded by !**/*.orig
📒 Files selected for processing (2)
  • buildroot-external/patches/occu/0189-WebUI-Fix-ControlHmIP-MOD-RC8.patch (1 hunks)
  • buildroot-external/patches/occu/0189-WebUI-Fix-ControlHmIP-MOD-RC8/occu/WebUI/www/rega/esp/datapointconfigurator.fn (1 hunks)
🔇 Additional comments (3)
buildroot-external/patches/occu/0189-WebUI-Fix-ControlHmIP-MOD-RC8.patch (1)

4-9: LGTM! The change aligns with the PR objectives.

The modification correctly addresses the channel type change issue by:

  1. Preserving the special handling for channelMode == 3
  2. Using key_switch_sc.fn::CreateContent() to properly evaluate CHANNEL_OPERATION_MODE for other modes

Let's verify the key_switch_sc.fn implementation:

✅ Verification successful

The change is appropriate and the implementation is verified

The key_switch_sc.fn implementation shows that:

  1. CreateContent() function properly handles the UI state by creating appropriate controls and initializing the iseMOD_RC8 JavaScript object with the channel ID and address
  2. The function works in conjunction with CreateDoorWindowContact() which provides the necessary UI elements for displaying door/window states
  3. The change from CreateNoFunction() to CreateContent() in the patch is correct as it enables proper channel operation mode handling through the iseMOD_RC8 JavaScript object
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the key_switch_sc.fn implementation and its CreateContent function

# Test 1: Check if key_switch_sc.fn exists and contains CreateContent
rg -A 5 "function\s+::CreateContent" $(fd -t f "key_switch_sc.fn$")

# Test 2: Check for any references to CHANNEL_OPERATION_MODE in key_switch_sc.fn
rg "CHANNEL_OPERATION_MODE" $(fd -t f "key_switch_sc.fn$")

Length of output: 712


Script:

#!/bin/bash
# Let's examine the content of key_switch_sc.fn to understand its implementation
cat buildroot-external/patches/occu/0039-WebUI-Fix-Style-Glitches/occu/WebUI/www/rega/esp/controls/key_switch_sc.fn

# Also check for any other patches that might modify key_switch_sc.fn
fd -t f ".*\.patch$" | xargs rg -l "key_switch_sc.fn"

Length of output: 6412

buildroot-external/patches/occu/0189-WebUI-Fix-ControlHmIP-MOD-RC8/occu/WebUI/www/rega/esp/datapointconfigurator.fn (2)

683-693: 🛠️ Refactor suggestion

Improve string comparison logic for device labels

Using ch.Label().Substr(5,7) to check for "MOD-RC8" is brittle and may fail if the label format changes. Instead, consider using the Find() method to check if "MOD-RC8" is part of the label, which is more robust and maintainable.

Apply this diff to improve the string comparison logic:

-if (ch.Label().Substr(5,7) != "MOD-RC8") {
+if (ch.Label().Find("MOD-RC8") == -1) {

Likely invalid or redundant comment.


682-694: ⚠️ Potential issue

Possible logical error in control handling condition

The condition at line 682 may not correctly represent the intended logic. If you aim to handle cases where ch.HssType() is "MULTI_MODE_INPUT_TRANSMITTER" and the label is not "ELV-SH-BM-S", the condition should use an && operator instead of ||. The current condition could skip the intended devices.

Apply this diff to correct the condition:

-if ((ch.HssType() != "MULTI_MODE_INPUT_TRANSMITTER") || (ch.Label() == "ELV-SH-BM-S")) {
+if ((ch.HssType() == "MULTI_MODE_INPUT_TRANSMITTER") && (ch.Label() != "ELV-SH-BM-S")) {

Likely invalid or redundant comment.

Comment on lines +12 to +13
WriteLine('<div class="CLASS02502">' # sName # '</div>');
WriteLine('<td>');
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential XSS vulnerability due to unescaped user input

The variable sName is inserted into the HTML output without proper escaping. If sName contains malicious content, this could lead to a Cross-Site Scripting (XSS) vulnerability. To prevent this, ensure that sName is properly escaped before being written to the output.

Apply this diff to escape sName:

-WriteLine('<div class="CLASS02502">' # sName # '</div>');
+WriteLine('<div class="CLASS02502">' # web.escapeHtml(sName) # '</div>');

And at line 38:

-WriteLine('<div class="CLASS02509">'#sName#'</div></td>');
+WriteLine('<div class="CLASS02509">'#web.escapeHtml(sName)#'</div></td>');

Also applies to: 38-38

@jens-maus jens-maus added 🐛 bug-report Something isn't working 🏷️ WebUI This refs the WebUI component labels Nov 4, 2024
@jens-maus jens-maus added this to the next release milestone Nov 4, 2024
@jens-maus jens-maus merged commit 060f8ec into jens-maus:master Nov 4, 2024
8 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
🐛 bug-report Something isn't working 🏷️ WebUI This refs the WebUI component
Projects
None yet
2 participants