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

Adaptive Lighting tweaks #868

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Adaptive Lighting tweaks #868

wants to merge 3 commits into from

Conversation

itavero
Copy link
Owner

@itavero itavero commented May 23, 2024

Tweaks in preparation of new release:

  • Enable by default.
  • Reset color temperature reference when changing brightness or state to on via HomeKit

Still to do:

  • Fix tests
  • Update changelog
  • Run test in "production"
  • Add tests to test "old" converter specific configuration still works

Summary by CodeRabbit

  • New Features

    • Adaptive Lighting is now enabled by default for compatible lights, with an option to disable it.
    • Enhanced configuration options for Adaptive Lighting, allowing for more granular control.
  • Bug Fixes

    • Resolved compatibility issues and improved device processing based on user interactions.
  • Documentation

    • Updated documentation to reflect changes in Adaptive Lighting configuration and usage.
  • Tests

    • Enhanced test suite for light functionality, focusing on adaptive lighting configurations and expected behaviors.
  • Chores

    • Standardized assertion methods in test cases for improved readability and maintainability.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
59.3% Coverage on New Code (required ≥ 60%)

See analysis details on SonarCloud

Copy link

codecov bot commented May 23, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 63.73%. Comparing base (31b0fd9) to head (3bb8f54).

Current head 3bb8f54 differs from pull request most recent head 6d6c526

Please upload reports for the commit 6d6c526 to get more accurate results.

Files Patch % Lines
src/converters/light.ts 73.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #868      +/-   ##
==========================================
- Coverage   66.17%   63.73%   -2.45%     
==========================================
  Files          40       40              
  Lines        2903     2509     -394     
  Branches      792      650     -142     
==========================================
- Hits         1921     1599     -322     
+ Misses        883      739     -144     
- Partials       99      171      +72     
Flag Coverage Δ
tests 63.73% <73.33%> (-2.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@itavero itavero force-pushed the revisit-adaptive-lighting branch from 6d6c526 to 1da7611 Compare July 15, 2024 10:34
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
59.3% Coverage on New Code (required ≥ 60%)

See analysis details on SonarCloud

Copy link
Contributor

🆗 Published SonarCloud and code coverage data.

@itavero
Copy link
Owner Author

itavero commented Dec 19, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Dec 19, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request introduces significant enhancements to the Adaptive Lighting feature across multiple files. The changes primarily focus on transforming the adaptive lighting configuration from a simple boolean toggle to a more flexible object-based approach. The new configuration allows users to enable/disable adaptive lighting, control updates only when the light is on, and set transition times. By default, adaptive lighting is now enabled for compatible lights, with additional logic added to reset the internal color temperature reference when lights are adjusted via HomeKit.

Changes

File Change Summary
CHANGELOG.md Updated with new entries about Adaptive Lighting changes and default enablement
config.schema.json Transformed adaptive_lighting from boolean to object with enabled, only_when_on, and transition properties
docs/light.md Updated documentation to reflect new adaptive lighting configuration options
src/converters/light.ts Enhanced adaptive lighting configuration handling, added logic to reset color temperature on light state changes
test/light.spec.ts Updated test configurations and assertions for adaptive lighting
test/testHelpers.ts Updated Jest assertion methods for consistency

Sequence Diagram

sequenceDiagram
    participant User
    participant HomeKit
    participant Light
    participant AdaptiveLighting

    User->>Light: Turn On/Adjust Brightness
    Light->>AdaptiveLighting: Reset Color Temperature
    Light->>HomeKit: Update Light State
    HomeKit->>User: Confirm Changes
Loading

Poem

🐰 Adaptive Lights, a Rabbit's Delight!
Brightness shifts with pure insight
Temperatures dance, colors bright
HomeKit magic takes its flight
Configurations now take might! 🌈✨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 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: 0

🧹 Nitpick comments (1)
src/converters/light.ts (1)

81-90: Consider simplifying the configuration logic

The configuration initialization could be simplified using object spread operator with conditional properties.

Consider this alternative implementation:

-let adaptiveLightingConfig: AdaptiveLightingConfig = { ...LightCreator.DEFAULT_CONFIG };
-if (isLightConfig(converterConfig)) {
-  if (isAdaptiveLightingConfig(converterConfig.adaptive_lighting)) {
-    adaptiveLightingConfig = converterConfig.adaptive_lighting;
-    if (adaptiveLightingConfig.enabled === undefined) {
-      adaptiveLightingConfig.enabled = true;
-    }
-  } else if (converterConfig.adaptive_lighting === false) {
-    adaptiveLightingConfig.enabled = false;
-  }
-}
+const adaptiveLightingConfig: AdaptiveLightingConfig = {
+  ...LightCreator.DEFAULT_CONFIG,
+  ...(isLightConfig(converterConfig) && {
+    ...(isAdaptiveLightingConfig(converterConfig.adaptive_lighting) 
+      ? { ...converterConfig.adaptive_lighting, enabled: converterConfig.adaptive_lighting.enabled ?? true }
+      : { enabled: converterConfig.adaptive_lighting !== false })
+  })
+};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b79e81 and 1da7611.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • config.schema.json (1 hunks)
  • docs/light.md (2 hunks)
  • src/converters/light.ts (9 hunks)
  • test/light.spec.ts (5 hunks)
  • test/testHelpers.ts (8 hunks)
✅ Files skipped from review due to trivial changes (1)
  • test/testHelpers.ts
🧰 Additional context used
🪛 LanguageTool
docs/light.md

[uncategorized] ~15-~15: Loose punctuation mark.
Context: ...uration (light) - adaptive_lighting: Set to false to disable [Adaptive Lig...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~16-~16: A comma may be missing after the conjunctive/linking adverb ‘Additionally’.
Context: ...a Color Temperature characteristic. Additionally you can also configure the following op...

(SENT_START_CONJUNCTIVE_LINKING_ADVERB_COMMA)

🪛 Markdownlint (0.37.0)
CHANGELOG.md

12-12: Expected: 2; Actual: 3
Unordered list indentation

(MD007, ul-indent)


13-13: Expected: 2; Actual: 3
Unordered list indentation

(MD007, ul-indent)

🔇 Additional comments (13)
docs/light.md (3)

15-15: LGTM: Clear documentation for disabling adaptive lighting

The documentation clearly explains how to disable the Adaptive Lighting feature.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: Loose punctuation mark.
Context: ...uration (light) - adaptive_lighting: Set to false to disable [Adaptive Lig...

(UNLIKELY_OPENING_PUNCTUATION)


17-19: LGTM: Well-documented configuration options

The new configuration options are clearly documented with their default values and purposes:

  • enabled: Controls adaptive lighting (defaults to true)
  • only_when_on: Controls updates timing (defaults to true)
  • transition: Controls transition time (optional)
🧰 Tools
🪛 LanguageTool

[uncategorized] ~19-~19: Loose punctuation mark.
Context: ...on. Defaults to true. - transition: Transition time to send along with the ...

(UNLIKELY_OPENING_PUNCTUATION)


[grammar] ~19-~19: Consider using either the past participle “sent” or the present participle “sending” here.
Context: ...f not defined, transition will not be send. ```json { "converters": { "ligh...

(BEEN_PART_AGREEMENT)


26-26: LGTM: Clear configuration example

The JSON example clearly demonstrates how to configure the new options.

config.schema.json (1)

164-186: LGTM: Well-structured schema for adaptive lighting configuration

The schema properly defines the new configuration structure with appropriate titles, types, and defaults:

  • enabled: boolean, defaults to true
  • only_when_on: boolean, defaults to true
  • transition: integer, defaults to 0
src/converters/light.ts (6)

33-33: LGTM: Clean interface extension

The AdaptiveLightingConfig interface is properly extended with the new optional enabled property.


44-45: LGTM: Updated type guard

The type guard for AdaptiveLightingConfig correctly handles the new enabled property while maintaining type safety.


57-60: LGTM: Well-defined defaults

The default configuration properly sets the initial values:

  • enabled: true: Enables adaptive lighting by default
  • only_when_on: true: Prevents unnecessary updates when light is off
  • transition: undefined: Allows flexible transition timing

386-393: LGTM: Proper state handling with adaptive lighting reset

The handleSetOn method correctly:

  1. Handles the state change
  2. Resets adaptive lighting temperature when turning on

416-417: LGTM: Proper brightness handling with adaptive lighting reset

The brightness handler correctly resets the adaptive lighting temperature when brightness changes.


Line range hint 544-560: LGTM: Robust adaptive lighting implementation

The adaptive lighting handler properly implements:

  1. Skip updates when light is off (if configured)
  2. Transition timing for smooth changes
  3. Proper temperature change threshold
  4. Detailed debug logging
CHANGELOG.md (1)

9-13: LGTM! Clear and well-structured changelog entry.

The changelog entry properly documents the key changes related to Adaptive Lighting, following the Keep a Changelog format.

🧰 Tools
🪛 Markdownlint (0.37.0)

12-12: Expected: 2; Actual: 3
Unordered list indentation

(MD007, ul-indent)


13-13: Expected: 2; Actual: 3
Unordered list indentation

(MD007, ul-indent)

test/light.spec.ts (2)

169-170: Consistent update to adaptive lighting configuration.

The configuration has been updated to use the new object-based structure for adaptive lighting settings, which aligns with the changes in the main codebase. The numberOfExpectedControllers is appropriately set based on the device capabilities.

Also applies to: 496-497


Line range hint 866-959: Well-structured test suite for Innr RB-249-T.

The new test suite thoroughly covers:

  • Basic light functionality (on/off, brightness)
  • Color temperature bounds handling
  • Proper controller initialization

Good job on including edge cases for color temperature bounds testing.

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