-
-
Notifications
You must be signed in to change notification settings - Fork 189
Separate color brightness control pr #1363
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
Open
nekajcasa
wants to merge
21
commits into
basnijholt:main
Choose a base branch
from
nekajcasa:separate-color-brightness-control-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6afa9f7
t01
nekajcasa c7b436e
Updated webapp and en.json
nekajcasa 1d63e47
t02
nekajcasa e761a42
t03
nekajcasa 3607ca0
t04
nekajcasa 693473b
Revert domain rename for PR
nekajcasa 3ca610b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e4bf8a5
Fix ruff lint issues in tests
nekajcasa a1f546c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7cf5a5e
Fix ruff lint issues in tests 2
nekajcasa fa4aa63
Merge branch 'separate-color-brightness-control-pr' of https://github…
nekajcasa 0b343c5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a0e4a72
response to protyposis
nekajcasa 0acb45f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b1da2ba
pre commit check fixes
nekajcasa df34f73
Update switch.py
nekajcasa 1304dc0
Update generated docs and metadata
nekajcasa ba8b90d
Convert independent color verification script to pytest tests
nekajcasa ba005bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6875f40
webapp cleanup
nekajcasa a177f80
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import datetime | ||
| import logging | ||
| import sys | ||
| from datetime import timedelta, timezone | ||
| from pathlib import Path | ||
| from unittest.mock import MagicMock | ||
|
|
||
| # Add the parent directory to sys.path to import the component | ||
| sys.path.append(str(Path(__file__).parent.parent.resolve())) | ||
|
|
||
| from custom_components.adaptive_lighting.color_and_brightness import SunLightSettings | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| # Mock astral location | ||
| mock_location = MagicMock() | ||
| mock_location.sunrise.return_value = datetime.datetime.now(timezone.utc).replace( | ||
| hour=6, | ||
| minute=0, | ||
| second=0, | ||
| microsecond=0, | ||
| ) | ||
| mock_location.sunset.return_value = datetime.datetime.now(timezone.utc).replace( | ||
| hour=18, | ||
| minute=0, | ||
| second=0, | ||
| microsecond=0, | ||
| ) | ||
| mock_location.noon.return_value = datetime.datetime.now(timezone.utc).replace( | ||
| hour=12, | ||
| minute=0, | ||
| second=0, | ||
| microsecond=0, | ||
| ) | ||
| mock_location.midnight.return_value = datetime.datetime.now(timezone.utc).replace( | ||
| hour=0, | ||
| minute=0, | ||
| second=0, | ||
| microsecond=0, | ||
| ) | ||
|
|
||
|
|
||
| def test_independent_color(): | ||
| _LOGGER.info("Testing Independent Color Control Logic...") | ||
|
|
||
| base_settings = { | ||
| "name": "test", | ||
| "astral_location": mock_location, | ||
| "adapt_until_sleep": False, | ||
| "max_brightness": 100, | ||
| "min_brightness": 50, | ||
| "max_color_temp": 6000, | ||
| "min_color_temp": 3000, | ||
| "sleep_brightness": 1, | ||
| "sleep_color_temp": 2000, | ||
| "sleep_rgb_color": (255, 0, 0), | ||
| "sleep_rgb_or_color_temp": "color_temp", | ||
| "sunrise_time": datetime.time(6, 0), | ||
| "min_sunrise_time": None, | ||
| "max_sunrise_time": None, | ||
| "sunset_time": datetime.time(18, 0), | ||
| "min_sunset_time": None, | ||
| "max_sunset_time": None, | ||
| "sunrise_offset": timedelta(0), | ||
| "sunset_offset": timedelta(0), | ||
| "brightness_mode_time_dark": timedelta(seconds=900), | ||
| "brightness_mode_time_light": timedelta(seconds=3600), | ||
| "brightness_mode": "default", | ||
| "timezone": timezone.utc, | ||
| # New independent color params | ||
| "independent_color": False, | ||
| "color_sunrise_time": datetime.time(8, 0), # Different from main | ||
| "color_min_sunrise_time": None, | ||
| "color_max_sunrise_time": None, | ||
| "color_sunset_time": datetime.time(20, 0), # Different from main | ||
| "color_min_sunset_time": None, | ||
| "color_max_sunset_time": None, | ||
| "color_sunrise_offset": timedelta(0), | ||
| "color_sunset_offset": timedelta(0), | ||
| } | ||
|
|
||
| # Test Case 1: Independent Control Disabled | ||
| _LOGGER.info("\n[Case 1] Independent Control Disabled") | ||
| settings = SunLightSettings(**base_settings) | ||
|
|
||
| # At 7:00 (after main sunrise 6:00, before color sunrise 8:00) | ||
| # Brightness should be high (sun is up), Color should be high (sun is up) because it follows main schedule | ||
| dt = datetime.datetime.now(timezone.utc).replace( | ||
| hour=7, | ||
| minute=0, | ||
| second=0, | ||
| microsecond=0, | ||
| ) | ||
|
|
||
| res = settings.brightness_and_color(dt, is_sleep=False) | ||
| _LOGGER.info("Time: 07:00 (Sunrise: 06:00, Color Sunrise: 08:00)") | ||
| _LOGGER.info(f"Brightness: {res['brightness_pct']} (Expected > min)") | ||
| _LOGGER.info(f"Color Temp: {res['color_temp_kelvin']} (Expected > min)") | ||
|
|
||
| if res["color_temp_kelvin"] <= 3000: | ||
| _LOGGER.info( | ||
| "FAIL: Color temp should be rising as sun is up (following 06:00 sunrise)", | ||
| ) | ||
| else: | ||
| _LOGGER.info("PASS: Color temp is following main schedule") | ||
|
|
||
| # Test Case 2: Independent Control Enabled | ||
| _LOGGER.info("\n[Case 2] Independent Control Enabled") | ||
| base_settings["independent_color"] = True | ||
| settings = SunLightSettings(**base_settings) | ||
|
|
||
| # At 7:00 (after main sunrise 6:00, before color sunrise 8:00) | ||
| # Brightness should be high (sun is up) | ||
| # Color should be LOW (color sun is NOT up yet, sunrise is 8:00) | ||
|
|
||
| res = settings.brightness_and_color(dt, is_sleep=False) | ||
| _LOGGER.info("Time: 07:00 (Sunrise: 06:00, Color Sunrise: 08:00)") | ||
| _LOGGER.info(f"Brightness: {res['brightness_pct']} (Expected > min)") | ||
| _LOGGER.info(f"Color Temp: {res['color_temp_kelvin']} (Expected approx min)") | ||
|
|
||
| if res["brightness_pct"] <= 50: | ||
| _LOGGER.info("FAIL: Brightness should be > min (sun is up)") | ||
| else: | ||
| _LOGGER.info("PASS: Brightness is up") | ||
|
|
||
| # Note: sun_position for color might be -1 if it's before sunrise, | ||
| # but the calculation logic might give something close to min_color_temp | ||
|
|
||
| if res["color_temp_kelvin"] > 3100: # Allowing small margin | ||
| _LOGGER.info( | ||
| f"FAIL: Color temp {res['color_temp_kelvin']} is too high! It should be near min {base_settings['min_color_temp']} because color sunrise is 08:00", | ||
| ) | ||
| else: | ||
| _LOGGER.info( | ||
| f"PASS: Color temp {res['color_temp_kelvin']} is low, following color schedule", | ||
| ) | ||
|
|
||
| # At 9:00 (after both sunrises) | ||
| dt_9am = datetime.datetime.now(timezone.utc).replace( | ||
| hour=9, | ||
| minute=0, | ||
| second=0, | ||
| microsecond=0, | ||
| ) | ||
| res_9am = settings.brightness_and_color(dt_9am, is_sleep=False) | ||
| _LOGGER.info("\nTime: 09:00") | ||
| _LOGGER.info(f"Color Temp: {res_9am['color_temp_kelvin']}") | ||
| if res_9am["color_temp_kelvin"] <= 3100: | ||
| _LOGGER.info("FAIL: Color temp should be high now") | ||
| else: | ||
| _LOGGER.info("PASS: Color temp is rising") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| logging.basicConfig(level=logging.INFO, format="%(message)s") | ||
| test_independent_color() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.