diff --git a/.github/update-services.py b/.github/update-services.py index ee001beb..9ea1860f 100644 --- a/.github/update-services.py +++ b/.github/update-services.py @@ -1,4 +1,5 @@ """Creates a services.yaml file with the latest docs.""" + import sys from pathlib import Path @@ -6,7 +7,7 @@ import yaml sys.path.append(str(Path(__file__).parent.parent)) -from custom_components.adaptive_lighting import const # noqa: E402 +from custom_components.adaptive_lighting import const services_filename = Path("custom_components") / "adaptive_lighting" / "services.yaml" with open(services_filename) as f: # noqa: PTH123 diff --git a/.github/update-strings.py b/.github/update-strings.py index f90ac437..d25a7af2 100644 --- a/.github/update-strings.py +++ b/.github/update-strings.py @@ -1,4 +1,5 @@ """Update strings.json and en.json from const.py.""" + import json import sys from pathlib import Path @@ -8,7 +9,7 @@ import yaml sys.path.append(str(Path(__file__).parent.parent)) -from custom_components.adaptive_lighting import const # noqa: E402 +from custom_components.adaptive_lighting import const folder = Path("custom_components") / "adaptive_lighting" strings_fname = folder / "strings.json" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 098bd9b2..9a1c5f2f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,11 +8,11 @@ repos: - id: mixed-line-ending args: ["--fix=lf"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.6 + rev: v0.2.0 hooks: - id: ruff args: ["--fix"] - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 24.1.1 hooks: - id: black diff --git a/custom_components/adaptive_lighting/__init__.py b/custom_components/adaptive_lighting/__init__.py index 98c2e94f..a235d70f 100644 --- a/custom_components/adaptive_lighting/__init__.py +++ b/custom_components/adaptive_lighting/__init__.py @@ -1,4 +1,5 @@ """Adaptive Lighting integration in Home-Assistant.""" + import logging from typing import Any diff --git a/custom_components/adaptive_lighting/adaptation_utils.py b/custom_components/adaptive_lighting/adaptation_utils.py index 593a746b..595911f0 100644 --- a/custom_components/adaptive_lighting/adaptation_utils.py +++ b/custom_components/adaptive_lighting/adaptation_utils.py @@ -1,4 +1,5 @@ """Utility functions for adaptation commands.""" + import logging from collections.abc import AsyncGenerator from dataclasses import dataclass diff --git a/custom_components/adaptive_lighting/color_and_brightness.py b/custom_components/adaptive_lighting/color_and_brightness.py index 9441e9e6..52386bf7 100644 --- a/custom_components/adaptive_lighting/color_and_brightness.py +++ b/custom_components/adaptive_lighting/color_and_brightness.py @@ -1,4 +1,5 @@ """Switch for the Adaptive Lighting integration.""" + from __future__ import annotations import bisect @@ -432,6 +433,7 @@ def find_a_b(x1: float, x2: float, y1: float, y2: float) -> tuple[float, float]: Notes ----- The values of y1 and y2 should lie between 0 and 1, inclusive. + """ a = (math.atanh(2 * y2 - 1) - math.atanh(2 * y1 - 1)) / (x2 - x1) b = x1 - (math.atanh(2 * y1 - 1) / a) @@ -477,6 +479,7 @@ def scaled_tanh( Returns ------- float: The output of the function, which lies in the range [y_min, y_max]. + """ a, b = find_a_b(x1, x2, y1, y2) return y_min + (y_max - y_min) * 0.5 * (math.tanh(a * (x - b)) + 1) diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index 8f82582a..f0098937 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -1,4 +1,5 @@ """Config flow for Adaptive Lighting integration.""" + import logging import homeassistant.helpers.config_validation as cv diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index cf93cee6..79d571e2 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -50,9 +50,9 @@ DOCS[CONF_INITIAL_TRANSITION] = ( ) CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION = "sleep_transition", 1 -DOCS[ - CONF_SLEEP_TRANSITION -] = 'Duration of transition when "sleep mode" is toggled in seconds. 😴' +DOCS[CONF_SLEEP_TRANSITION] = ( + 'Duration of transition when "sleep mode" is toggled in seconds. 😴' +) CONF_INTERVAL, DEFAULT_INTERVAL = "interval", 90 DOCS[CONF_INTERVAL] = "Frequency to adapt the lights, in seconds. 🔄" @@ -112,30 +112,30 @@ DOCS[CONF_SLEEP_COLOR_TEMP] = ( ) CONF_SLEEP_RGB_COLOR, DEFAULT_SLEEP_RGB_COLOR = "sleep_rgb_color", [255, 56, 0] -DOCS[ - CONF_SLEEP_RGB_COLOR -] = 'RGB color in sleep mode (used when `sleep_rgb_or_color_temp` is "rgb_color"). 🌈' +DOCS[CONF_SLEEP_RGB_COLOR] = ( + 'RGB color in sleep mode (used when `sleep_rgb_or_color_temp` is "rgb_color"). 🌈' +) CONF_SLEEP_RGB_OR_COLOR_TEMP, DEFAULT_SLEEP_RGB_OR_COLOR_TEMP = ( "sleep_rgb_or_color_temp", "color_temp", ) -DOCS[ - CONF_SLEEP_RGB_OR_COLOR_TEMP -] = 'Use either `"rgb_color"` or `"color_temp"` in sleep mode. 🌙' +DOCS[CONF_SLEEP_RGB_OR_COLOR_TEMP] = ( + 'Use either `"rgb_color"` or `"color_temp"` in sleep mode. 🌙' +) CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET = "sunrise_offset", 0 -DOCS[ - CONF_SUNRISE_OFFSET -] = "Adjust sunrise time with a positive or negative offset in seconds. ⏰" +DOCS[CONF_SUNRISE_OFFSET] = ( + "Adjust sunrise time with a positive or negative offset in seconds. ⏰" +) CONF_SUNRISE_TIME = "sunrise_time" DOCS[CONF_SUNRISE_TIME] = "Set a fixed time (HH:MM:SS) for sunrise. 🌅" CONF_MIN_SUNRISE_TIME = "min_sunrise_time" -DOCS[ - CONF_MIN_SUNRISE_TIME -] = "Set the earliest virtual sunrise time (HH:MM:SS), allowing for later sunrises. 🌅" +DOCS[CONF_MIN_SUNRISE_TIME] = ( + "Set the earliest virtual sunrise time (HH:MM:SS), allowing for later sunrises. 🌅" +) CONF_MAX_SUNRISE_TIME = "max_sunrise_time" DOCS[CONF_MAX_SUNRISE_TIME] = ( @@ -144,22 +144,22 @@ DOCS[CONF_MAX_SUNRISE_TIME] = ( ) CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET = "sunset_offset", 0 -DOCS[ - CONF_SUNSET_OFFSET -] = "Adjust sunset time with a positive or negative offset in seconds. ⏰" +DOCS[CONF_SUNSET_OFFSET] = ( + "Adjust sunset time with a positive or negative offset in seconds. ⏰" +) CONF_SUNSET_TIME = "sunset_time" DOCS[CONF_SUNSET_TIME] = "Set a fixed time (HH:MM:SS) for sunset. 🌇" CONF_MIN_SUNSET_TIME = "min_sunset_time" -DOCS[ - CONF_MIN_SUNSET_TIME -] = "Set the earliest virtual sunset time (HH:MM:SS), allowing for later sunsets. 🌇" +DOCS[CONF_MIN_SUNSET_TIME] = ( + "Set the earliest virtual sunset time (HH:MM:SS), allowing for later sunsets. 🌇" +) CONF_MAX_SUNSET_TIME = "max_sunset_time" -DOCS[ - CONF_MAX_SUNSET_TIME -] = "Set the latest virtual sunset time (HH:MM:SS), allowing for earlier sunsets. 🌇" +DOCS[CONF_MAX_SUNSET_TIME] = ( + "Set the latest virtual sunset time (HH:MM:SS), allowing for earlier sunsets. 🌇" +) CONF_BRIGHTNESS_MODE, DEFAULT_BRIGHTNESS_MODE = "brightness_mode", "default" DOCS[CONF_BRIGHTNESS_MODE] = ( diff --git a/custom_components/adaptive_lighting/hass_utils.py b/custom_components/adaptive_lighting/hass_utils.py index cc3257ce..c87d481f 100644 --- a/custom_components/adaptive_lighting/hass_utils.py +++ b/custom_components/adaptive_lighting/hass_utils.py @@ -1,4 +1,5 @@ """Utility functions for HA core.""" + import logging from collections.abc import Awaitable, Callable diff --git a/custom_components/adaptive_lighting/helpers.py b/custom_components/adaptive_lighting/helpers.py index 2e7ba23e..fa3af6ef 100644 --- a/custom_components/adaptive_lighting/helpers.py +++ b/custom_components/adaptive_lighting/helpers.py @@ -34,6 +34,7 @@ def int_to_base36(num: int) -> str: >>> base36_num = int_to_base36(num) >>> print(base36_num) '2N9' + """ alphanumeric_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 9aec8ba1..06cd2f87 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1,4 +1,5 @@ """Switch for the Adaptive Lighting integration.""" + from __future__ import annotations import asyncio diff --git a/test_dependencies.py b/test_dependencies.py index f8fbf5b9..a07f9ee6 100644 --- a/test_dependencies.py +++ b/test_dependencies.py @@ -1,4 +1,5 @@ """Extracts the dependencies of the components required for testing.""" + from collections import defaultdict from pathlib import Path diff --git a/tests/conftest.py b/tests/conftest.py index 14f7e644..4b61832d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ """Fixtures for testing.""" + import os import sys diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 22384143..4242417a 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -1,4 +1,5 @@ """Test Adaptive Lighting config flow.""" + from homeassistant import data_entry_flow from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import CONF_NAME diff --git a/tests/test_init.py b/tests/test_init.py index bb0cf977..b6c82673 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,4 +1,5 @@ """Tests for Adaptive Lighting integration.""" + from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_NAME from homeassistant.setup import async_setup_component diff --git a/tests/test_switch.py b/tests/test_switch.py index 018c8965..8664433c 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -1,4 +1,5 @@ """Tests for Adaptive Lighting switches.""" + # pylint: disable=protected-access import asyncio import itertools diff --git a/webapp/homeassistant_util_color.py b/webapp/homeassistant_util_color.py index 33df5cf3..c1541f4c 100644 --- a/webapp/homeassistant_util_color.py +++ b/webapp/homeassistant_util_color.py @@ -1,4 +1,5 @@ """Color util methods.""" + # Slightly modified from homeassistant.util.color at # https://github.com/home-assistant/core/blob/798fb3e31a6ba87358adc93a4c5b772b64451712/homeassistant/util/color.py#L14 # to remove the dependency on homeassistant.util.color in sun.py