Refactor, simplify code, rename, and set minimal HA core ≥2022.11 (#655)

* Rename TurnOnOffListener to AdaptiveLightingManager

* Bump Python version

* Refactor and unify methods that are called once

* Simplify adaptation_utils.py

* Improve readability in adaptation_utils.py

* More renames

* Simplify

* More renames and simplifications

* fix test

* simplify _supported_features

* rename

* walrus

* drop old astral support

* Only support HA  ≥2021.06

* Require 2016.06

* Try 2023.1

* even more old versions

* test

* more versions

* verify that only ≥2022.11 works

* named args

* setdefault

* no astral v1

* var

* simplify

* no need to pass adapt_brightness and adapt_color

* Add comment
This commit is contained in:
Bas Nijholt 2023-07-22 21:19:01 -07:00 • committed by GitHub
commit c1528ec10a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 166 additions and 208 deletions

View file

@ -14,8 +14,8 @@ import pytest
from custom_components.adaptive_lighting.adaptation_utils import (
ServiceData,
_create_service_call_data_iterator,
_filter_service_data,
_has_relevant_service_data_attributes,
_remove_redundant_attributes,
_split_service_call_data,
prepare_adaptation_data,
)
@ -74,11 +74,6 @@ async def test_split_service_call_data(input_data, expected_data_list):
@pytest.mark.parametrize(
"service_data,state,service_data_expected",
[
(
{ATTR_ENTITY_ID: "light.test", ATTR_BRIGHTNESS: 10, ATTR_TRANSITION: 2},
None,
{ATTR_ENTITY_ID: "light.test", ATTR_BRIGHTNESS: 10, ATTR_TRANSITION: 2},
),
(
{ATTR_ENTITY_ID: "light.test", ATTR_BRIGHTNESS: 10, ATTR_TRANSITION: 2},
State("light.test", STATE_ON),
@ -96,17 +91,16 @@ async def test_split_service_call_data(input_data, expected_data_list):
),
],
ids=[
"pass all attributes on missing state",
"pass all attributes on empty state",
"remove attributes whose values equal the state",
"keep attributes whose values differ from the state",
],
)
async def test_filter_service_data(
async def test_remove_redundant_attributes(
service_data: ServiceData, state: State | None, service_data_expected: ServiceData
):
"""Test filtering of service data."""
assert _filter_service_data(service_data, state) == service_data_expected
assert _remove_redundant_attributes(service_data, state) == service_data_expected
@pytest.mark.parametrize(

View file

@ -1206,10 +1206,10 @@ async def test_turn_on_and_off_when_already_at_that_state(hass):
@pytest.mark.dependency(depends=GLOBAL_TEST_DEPENDENCIES)
async def test_async_update_at_interval(hass):
"""Test '_async_update_at_interval' method."""
async def test_async_update_at_interval_action(hass):
"""Test '_async_update_at_interval_action' method."""
_, switch = await setup_switch(hass, {})
await switch._async_update_at_interval()
await switch._async_update_at_interval_action()
@pytest.mark.parametrize("separate_turn_on_commands", (True, False))