From 935b913bc7802e091f9b10e82545b66b56045d9e Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 1 Jan 2025 22:49:58 -0800 Subject: [PATCH 1/2] Fix test_proactive_adaptation_with_separate_commands (#1158) --- tests/test_switch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_switch.py b/tests/test_switch.py index afc720e5..34554872 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -1602,7 +1602,6 @@ async def test_proactive_adaptation(hass): assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 3448 -# TODO: Breaks since 2024.5.0! async def test_proactive_adaptation_with_separate_commands(hass): """Validate that a split proactive adaptation yields one additional service call.""" switch, _ = await setup_lights_and_switch( @@ -1623,11 +1622,16 @@ async def test_proactive_adaptation_with_separate_commands(hass): }, ) - event_context_ids = await _turn_on_and_track_event_contexts( + events = await _turn_on_and_track_event_contexts( hass, "test_context", ENTITY_LIGHT_3, + return_full_events=True, ) + # Wait for all adaptation tasks to complete + await asyncio.gather(*switch.manager.adaptation_tasks) + await hass.async_block_till_done() + event_context_ids = [event.context.id for event in events] # Expect two service calls assert len(event_context_ids) == 2, event_context_ids From 9aee2349555ad25937ba3b7b614b7776e2d3bce5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 1 Jan 2025 23:28:15 -0800 Subject: [PATCH 2/2] [pre-commit.ci] pre-commit autoupdate (#972) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.3.5 → v0.8.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.5...v0.8.4) - [github.com/psf/black: 24.3.0 → 24.10.0](https://github.com/psf/black/compare/24.3.0...24.10.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix issues --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bas Nijholt --- .github/update-strings.py | 2 +- .pre-commit-config.yaml | 6 +++--- .../adaptive_lighting/adaptation_utils.py | 4 ++-- .../adaptive_lighting/color_and_brightness.py | 12 ++++-------- custom_components/adaptive_lighting/switch.py | 2 +- tests/test_switch.py | 7 ++----- webapp/color_and_brightness.py | 12 ++++-------- 7 files changed, 17 insertions(+), 28 deletions(-) diff --git a/.github/update-strings.py b/.github/update-strings.py index d25a7af2..94fce459 100644 --- a/.github/update-strings.py +++ b/.github/update-strings.py @@ -22,7 +22,7 @@ data_description = {} for k, _, typ in const.VALIDATION_TUPLES: desc = const.DOCS[k] - if len(desc) > 40 and typ != bool and typ != cv.entity_ids: + if len(desc) > 40 and typ not in (bool, cv.entity_ids): data[k] = k data_description[k] = desc else: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9a7a0a9e..fcaebb75 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: trailing-whitespace @@ -8,11 +8,11 @@ repos: - id: mixed-line-ending args: ["--fix=lf"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.5 + rev: v0.8.4 hooks: - id: ruff args: ["--fix"] - repo: https://github.com/psf/black - rev: 24.3.0 + rev: 24.10.0 hooks: - id: black diff --git a/custom_components/adaptive_lighting/adaptation_utils.py b/custom_components/adaptive_lighting/adaptation_utils.py index 595911f0..aea061d1 100644 --- a/custom_components/adaptive_lighting/adaptation_utils.py +++ b/custom_components/adaptive_lighting/adaptation_utils.py @@ -69,8 +69,8 @@ def _split_service_call_data(service_data: ServiceData) -> list[ServiceData]: if service_datas and (transition := service_data.get(ATTR_TRANSITION)) is not None: transition /= len(service_datas) - for service_data in service_datas: - service_data[ATTR_TRANSITION] = transition + for _service_data in service_datas: + _service_data[ATTR_TRANSITION] = transition return service_datas diff --git a/custom_components/adaptive_lighting/color_and_brightness.py b/custom_components/adaptive_lighting/color_and_brightness.py index 52386bf7..215a9a70 100644 --- a/custom_components/adaptive_lighting/color_and_brightness.py +++ b/custom_components/adaptive_lighting/color_and_brightness.py @@ -64,12 +64,10 @@ def sunrise(self, dt: datetime.date) -> datetime.datetime: ) + self.sunrise_offset if self.min_sunrise_time is not None: min_sunrise = self._replace_time(dt, self.min_sunrise_time) - if min_sunrise > sunrise: - sunrise = min_sunrise + sunrise = max(min_sunrise, sunrise) if self.max_sunrise_time is not None: max_sunrise = self._replace_time(dt, self.max_sunrise_time) - if max_sunrise < sunrise: - sunrise = max_sunrise + sunrise = min(max_sunrise, sunrise) return sunrise def sunset(self, dt: datetime.date) -> datetime.datetime: @@ -81,12 +79,10 @@ def sunset(self, dt: datetime.date) -> datetime.datetime: ) + self.sunset_offset if self.min_sunset_time is not None: min_sunset = self._replace_time(dt, self.min_sunset_time) - if min_sunset > sunset: - sunset = min_sunset + sunset = max(min_sunset, sunset) if self.max_sunset_time is not None: max_sunset = self._replace_time(dt, self.max_sunset_time) - if max_sunset < sunset: - sunset = max_sunset + sunset = min(max_sunset, sunset) return sunset def _replace_time( diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 893e7565..29955d0a 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -2552,7 +2552,7 @@ def _off_to_on_state_event_is_from_turn_on( and id_off_to_on == turn_on_event.context.id ) - async def just_turned_off( # noqa: PLR0911, PLR0912 + async def just_turned_off( # noqa: PLR0911 self, entity_id: str, ) -> bool: diff --git a/tests/test_switch.py b/tests/test_switch.py index 34554872..607f17ef 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -2131,11 +2131,8 @@ async def test_light_group( assert events[1].context.id == "testing" e1 = events[2].data["service_data"][ATTR_ENTITY_ID] e2 = events[3].data["service_data"][ATTR_ENTITY_ID] - assert ( - e1 == "light.light_4" - and e2 == "light.light_5" - or e1 == "light.light_5" - and e2 == "light.light_4" + assert (e1 == "light.light_4" and e2 == "light.light_5") or ( + e1 == "light.light_5" and e2 == "light.light_4" ) assert ":lght:" in events[2].context.id assert ":lght:" in events[3].context.id diff --git a/webapp/color_and_brightness.py b/webapp/color_and_brightness.py index ba804df3..b632ba8e 100644 --- a/webapp/color_and_brightness.py +++ b/webapp/color_and_brightness.py @@ -64,12 +64,10 @@ def sunrise(self, dt: datetime.date) -> datetime.datetime: ) + self.sunrise_offset if self.min_sunrise_time is not None: min_sunrise = self._replace_time(dt, self.min_sunrise_time) - if min_sunrise > sunrise: - sunrise = min_sunrise + sunrise = max(min_sunrise, sunrise) if self.max_sunrise_time is not None: max_sunrise = self._replace_time(dt, self.max_sunrise_time) - if max_sunrise < sunrise: - sunrise = max_sunrise + sunrise = min(max_sunrise, sunrise) return sunrise def sunset(self, dt: datetime.date) -> datetime.datetime: @@ -81,12 +79,10 @@ def sunset(self, dt: datetime.date) -> datetime.datetime: ) + self.sunset_offset if self.min_sunset_time is not None: min_sunset = self._replace_time(dt, self.min_sunset_time) - if min_sunset > sunset: - sunset = min_sunset + sunset = max(min_sunset, sunset) if self.max_sunset_time is not None: max_sunset = self._replace_time(dt, self.max_sunset_time) - if max_sunset < sunset: - sunset = max_sunset + sunset = min(max_sunset, sunset) return sunset def _replace_time(