Skip to content

Add segment name#1810

Open
mik-laj wants to merge 7 commits intofrenck:mainfrom
mik-laj:segment-name
Open

Add segment name#1810
mik-laj wants to merge 7 commits intofrenck:mainfrom
mik-laj:segment-name

Conversation

@mik-laj
Copy link
Copy Markdown

@mik-laj mik-laj commented Sep 3, 2025

Proposed Changes

Expose n (segment name) field from WLED API in Segment model.

No behavioral changes, simple passthrough.

Related Issues

(Github link to related issues or pull requests)

Summary by CodeRabbit

  • New Features
    • Segments can now have optional custom names exposed in the UI and API responses; unnamed segments remain unaffected.
  • Tests
    • Added fixtures and unit tests to verify segment naming is parsed correctly when present and absent.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Sep 3, 2025

📝 Walkthrough

Walkthrough

Adds an optional name field to the Segment dataclass in src/wled/models.py (aliased as "n") and includes JSON fixtures plus unit tests verifying segment naming present/absent cases.

Changes

Cohort / File(s) Summary
Models: Segment field
src/wled/models.py
Add public field `name: str
Fixtures: states
tests/fixtures/state_with_segment_name.json, tests/fixtures/state_without_segment_name.json
Add two JSON fixtures: one with named segments ("Curtain", "Wall") and one without segment names.
Tests: model coverage
tests/test_models.py
Add tests loading the fixtures and asserting segment name is present or None as appropriate.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble code with twitching nose,
A little name where segment goes.
Sometimes it's written, sometimes not—
A quiet tag, a tidy spot.
🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add segment name' directly and clearly describes the main change: adding support for the segment name field from the WLED API to the Segment model.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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 (2)
src/wled/models.py (2)

298-302: Tighten docstring and remove trailing whitespace

Clarify fallback wording, reference None correctly, and avoid trailing spaces to keep linters happy.

-    """The name of the segment. 
-    
-    Names are not present by default. If this is none, use 
-    "Segment{segment_id}" to match the WLED UI.
-    """
+    """User-defined segment name (alias: "n").
+
+    Not present by default. If None or empty, callers may fall back to a UI-like
+    default, e.g., "Segment {segment_id}".
+    """

297-303: Optional: expose a computed fallback to reduce duplication downstream

Consider providing a convenience property (and optional normalization) so consumers don’t have to replicate fallback logic.

Example (outside the changed hunk):

# Inside class Segment
@property
def effective_name(self) -> str:
    if self.name:
        return self.name
    if self.segment_id is not None:
        return f"Segment {self.segment_id}"
    return "Segment"

@classmethod
def __post_deserialize__(cls, obj: "Segment") -> "Segment":
    # Normalize empty string to None for consistency
    if obj.name == "":
        obj.name = None
    return obj
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0bdb185 and 6ed2188.

📒 Files selected for processing (1)
  • src/wled/models.py (1 hunks)
🔇 Additional comments (1)
src/wled/models.py (1)

297-303: Addition of name (alias "n") looks correct

Matches WLED’s segment JSON field and will omit on serialization when None, which is desirable. Nice, minimal change.

@mik-laj
Copy link
Copy Markdown
Author

mik-laj commented Sep 22, 2025

@coderabbitai I pushed a fix, please review it.

@mik-laj
Copy link
Copy Markdown
Author

mik-laj commented Sep 22, 2025

I checked that this change is correct at the real device.

At the beginning, I didn't have any segments name

(wled-py3.12) vscode ➜ /workspaces/python-wled (segment-name) $ python test_segments.py
Device:
Segment 0:
  Name: None
  Effective name: Segment 0
Segment 1:
  Name: None
  Effective name: Segment 1

Then I set a name for two segments:

(wled-py3.12) vscode ➜ /workspaces/python-wled (segment-name) $ python test_segments.py
Device:
Segment 0:
  Name: Left window
  Effective name: Left window
Segment 1:
  Name: Right window
  Effective name: Right window

And later I deleted the name of the segment:

(wled-py3.12) vscode ➜ /workspaces/python-wled (segment-name) $ python test_segments.py
Device:
Segment 0:
  Name: Left window
  Effective name: Left window
Segment 1:
  Name: None
  Effective name: Segment 1

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Oct 23, 2025
@mik-laj
Copy link
Copy Markdown
Author

mik-laj commented Oct 23, 2025

This is waiting for review from the project maintainer.

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Oct 24, 2025
@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Nov 24, 2025
@mik-laj
Copy link
Copy Markdown
Author

mik-laj commented Nov 24, 2025

It is not stale. I am waiting for the project maintainer.

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Nov 25, 2025
@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Dec 25, 2025
@mik-laj
Copy link
Copy Markdown
Author

mik-laj commented Dec 25, 2025

Not stale

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Dec 26, 2025
@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Jan 26, 2026
@mik-laj
Copy link
Copy Markdown
Author

mik-laj commented Jan 26, 2026

Not stale.

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Jan 27, 2026
@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Feb 26, 2026
@mik-laj
Copy link
Copy Markdown
Author

mik-laj commented Feb 26, 2026

Not stale.

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Feb 27, 2026
Copilot AI review requested due to automatic review settings March 2, 2026 11:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support in the WLED Python client models to deserialize the user-defined segment name returned by WLED’s JSON API ("n"), enabling downstream consumers (e.g., Home Assistant) to display segment names instead of ID-based generated labels.

Changes:

  • Add optional Segment.name field with Mashumaro alias mapping to API key "n".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
tests/test_models.py (1)

10-13: Make fixture decoding explicit for cross-platform determinism.

read_text() uses implicit encoding. Prefer explicit UTF-8 when loading JSON fixtures.

Proposed patch
 def load_fixture(file_name: str) -> dict:
     """Load a fixture file from the fixtures directory."""
     fixture_path = FIXTURE_DIR / file_name
-    return json.loads(fixture_path.read_text())
+    return json.loads(fixture_path.read_text(encoding="utf-8"))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_models.py` around lines 10 - 13, The load_fixture helper uses
implicit encoding via fixture_path.read_text(), which can yield
platform-dependent behavior; change load_fixture (referencing function name
load_fixture and symbol FIXTURE_DIR and fixture_path) to read the file with an
explicit UTF-8 decoding (e.g., call read_text with encoding="utf-8" or open the
file with encoding="utf-8") before passing the string into json.loads so JSON
decoding is deterministic across platforms.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_models.py`:
- Around line 10-13: The load_fixture helper uses implicit encoding via
fixture_path.read_text(), which can yield platform-dependent behavior; change
load_fixture (referencing function name load_fixture and symbol FIXTURE_DIR and
fixture_path) to read the file with an explicit UTF-8 decoding (e.g., call
read_text with encoding="utf-8" or open the file with encoding="utf-8") before
passing the string into json.loads so JSON decoding is deterministic across
platforms.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f16cfb7 and 3576706.

📒 Files selected for processing (3)
  • tests/fixtures/state_with_segment_name.json
  • tests/fixtures/state_without_segment_name.json
  • tests/test_models.py
✅ Files skipped from review due to trivial changes (1)
  • tests/fixtures/state_with_segment_name.json

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Apr 2, 2026
@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Apr 3, 2026
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.

2 participants