Skip to content

Add segment name support to the segment() method#2051

Open
mik-laj wants to merge 5 commits intofrenck:mainfrom
mik-laj:feat/segment-name
Open

Add segment name support to the segment() method#2051
mik-laj wants to merge 5 commits intofrenck:mainfrom
mik-laj:feat/segment-name

Conversation

@mik-laj
Copy link
Copy Markdown
Collaborator

@mik-laj mik-laj commented May 1, 2026

Summary

  • Adds a name parameter to wled.segment() to set or clear the name of a WLED segment
  • name=None (default) leaves the name unchanged — consistent with all other parameters in this method
  • name="" (empty string) clears the name on the device — the only way the WLED API supports clearing it
  • Parametrized tests cover all four cases: set, clear, explicit None, and default (omitted)

Depends on

Depends on #2050

Test plan

  • test_segment_name[set]name="Curtain" sends {"n": "Curtain"} in payload
  • test_segment_name[clear_empty_string]name="" sends {"n": ""} in payload
  • test_segment_name[none_explicit]name=None omits n from payload
  • test_segment_name[default_omitted] — no name argument omits n from payload
  • Full test suite passes with 99.13% coverage

WLED API behavior (verified on device)

Sent in payload Effect on device
key n absent name unchanged
"n": null name unchanged (null is ignored by WLED)
"n": "" name cleared
"n": "Curtain" name set

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • The segment() method now supports an optional name parameter for setting segment names. Use an empty string to clear a name, or leave it unspecified to preserve the existing name.

mik-laj and others added 5 commits April 30, 2026 03:46
Adds a `name` parameter to `wled.segment()` allowing callers to set or
clear a segment name. Passing `None` (the default) leaves the name
unchanged; passing an empty string clears it on the device.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 1, 2026 16:51
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67bd7d85-69aa-4157-a4af-fbdc16c1ab7e

📥 Commits

Reviewing files that changed from the base of the PR and between ea7e0e2 and 6e73ab9.

📒 Files selected for processing (3)
  • src/wled/wled.py
  • tests/conftest.py
  • tests/test_wled.py

📝 Walkthrough

Walkthrough

The PR adds an optional name parameter to the WLED.segment() method to support segment naming via the WLED API, where empty strings clear the name and None leaves it unchanged. Tests are refactored to use async fixtures and new assertion helpers for validating POST payloads.

Changes

Cohort / File(s) Summary
Segment naming support
src/wled/wled.py
Added optional name parameter to segment() method that transmits the segment name to the WLED API via the "n" field in the segment state payload.
Async test infrastructure
tests/conftest.py
Converted session and wled fixtures from sync to async using pytest_asyncio; updated mock_json_and_presets() helper to accept optional override payloads for flexible test data injection.
Test refactoring and coverage expansion
tests/test_wled.py
Introduced assert_post_payload() validation helper; refactored test functions to use pytest fixtures instead of local context managers; added comprehensive POST payload assertions across segment, preset, playlist, transition, and other API endpoints.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Add segment name #1810: Adds the Segment model field for the "n" (name) attribute, complementing this PR's API layer implementation.
  • Add CCT support #1367: Previously extended WLED.segment() with a new optional parameter (cct) following a similar pattern of adding fields to the segment state payload.

Suggested labels

new-feature

Suggested reviewers

  • frenck

Poem

🐰 A rabbit hops through segment lanes,
Names now bloom where naming reigns,
Async fixtures dance so spry,
Assertions hop and verify! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main feature addition: adding segment name support to the segment() method, which is the primary change across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@mik-laj mik-laj added the new-feature New features or options. label May 1, 2026
@mik-laj mik-laj marked this pull request as draft May 1, 2026 16:53
@mik-laj mik-laj marked this pull request as ready for review May 1, 2026 16:53
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.02%. Comparing base (3e87d76) to head (6e73ab9).
⚠️ Report is 597 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2051       +/-   ##
===========================================
+ Coverage   58.61%   97.02%   +38.41%     
===========================================
  Files           6        8        +2     
  Lines         662     1075      +413     
  Branches      143      112       -31     
===========================================
+ Hits          388     1043      +655     
+ Misses        270       21      -249     
- Partials        4       11        +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

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

This PR extends the WLED client’s segment() API to support setting/clearing a segment name, and strengthens the test suite by refactoring fixtures and asserting the exact outgoing request payloads sent to the WLED API.

Changes:

  • Add a name: str | None parameter to WLED.segment() and map it to the WLED JSON field "n" (with "" clearing the name and None omitting the field).
  • Refactor tests to use shared responses, session, and wled fixtures, reducing boilerplate setup.
  • Add/expand request contract assertions by validating the exact POST payloads (including the auto-added "v": True flag).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/wled/wled.py Adds segment(..., name=...) support and includes "n" in the segment payload when provided.
tests/conftest.py Enhances mock_json_and_presets to accept custom fixture data and introduces async session/wled fixtures.
tests/test_wled.py Refactors tests to fixtures and adds a helper to assert POST payloads, including new parametrized coverage for segment naming.

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

Comment thread tests/test_wled.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants