From 289b3c59fecf053a0d62190871cfbdcbae9b6676 Mon Sep 17 00:00:00 2001 From: wilbiev Date: Wed, 25 Dec 2024 21:45:21 +0000 Subject: [PATCH] Fixes source code, upgrade workflows - pre-commit --- .../workflows/automatic-custom-card-docs.yml | 2 +- .github/workflows/check-code-quality.yml | 4 +-- .github/workflows/codeql.yml | 2 +- .github/workflows/hacs-validate.yml | 4 +-- .github/workflows/labeler.yml | 2 +- .github/workflows/pages.yml | 4 +-- .github/workflows/release.yml | 2 +- .markdownlint.yml | 1 + .pre-commit-config.yaml | 22 ++++++------ .../custom_card_imswel_medias/README.md | 3 ++ .../ui_lovelace_minimalist/__init__.py | 3 ++ .../ui_lovelace_minimalist/base.py | 9 ++--- .../ui_lovelace_minimalist/config_flow.py | 11 +++++- .../ui_lovelace_minimalist/const.py | 34 +++++++++---------- .../ui_lovelace_minimalist/enums.py | 1 + .../ui_lovelace_minimalist/utils/decode.py | 1 + .../ui_lovelace_minimalist/utils/logger.py | 1 + .../custom_cards/custom_card_imswel_medias.md | 3 ++ 18 files changed, 66 insertions(+), 43 deletions(-) diff --git a/.github/workflows/automatic-custom-card-docs.yml b/.github/workflows/automatic-custom-card-docs.yml index a92327fbe..5f4c5ab23 100644 --- a/.github/workflows/automatic-custom-card-docs.yml +++ b/.github/workflows/automatic-custom-card-docs.yml @@ -11,7 +11,7 @@ jobs: docit: runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v3" + - uses: "actions/checkout@v4" with: fetch-depth: 0 - name: "Copy and rename README.md files" diff --git a/.github/workflows/check-code-quality.yml b/.github/workflows/check-code-quality.yml index 2583600cb..e1b5b5ca6 100644 --- a/.github/workflows/check-code-quality.yml +++ b/.github/workflows/check-code-quality.yml @@ -11,11 +11,11 @@ jobs: runs-on: "ubuntu-latest" steps: - name: "⤵️ Check out code from GitHub" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "⚙️ Set up Python" uses: "actions/setup-python@v4" with: - python-version: 3.8 + python-version: 3.11 - name: "⚙️ Set up Ruby" uses: "ruby/setup-ruby@v1" with: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f54dfd08b..1fbd12737 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -34,7 +34,7 @@ jobs: steps: - name: "Checkout repository" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" # Initializes the CodeQL tools for scanning. - name: "Initialize CodeQL" diff --git a/.github/workflows/hacs-validate.yml b/.github/workflows/hacs-validate.yml index d9a19e621..d2986cfa9 100644 --- a/.github/workflows/hacs-validate.yml +++ b/.github/workflows/hacs-validate.yml @@ -13,7 +13,7 @@ jobs: runs-on: "ubuntu-latest" steps: - name: "checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "validation" uses: "home-assistant/actions/hassfest@master" @@ -22,7 +22,7 @@ jobs: runs-on: "ubuntu-latest" steps: - name: "checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "validation" uses: "hacs/action@main" with: diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index a782ee3b6..2ed8a8677 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -12,7 +12,7 @@ jobs: runs-on: "ubuntu-latest" steps: - name: "⤵️ Check out code from GitHub" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "\U0001F680 Run Labeler" uses: "crazy-max/ghaction-github-labeler@v4" with: diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index d03239b40..335876e14 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -10,9 +10,9 @@ jobs: deploy: runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v3" + - uses: "actions/checkout@v4" with: - node-version: "16.x" + node-version: "20.x" - uses: "actions/setup-python@v4" with: python-version: "3.11" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3196cc7e6..12d6ee6ee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ jobs: runs-on: "ubuntu-latest" steps: - name: "Check out repository" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "Get version" id: "version" diff --git a/.markdownlint.yml b/.markdownlint.yml index ed383dae4..3b9378bdf 100644 --- a/.markdownlint.yml +++ b/.markdownlint.yml @@ -7,6 +7,7 @@ MD001: false MD024: allow_different_nesting: true + siblings_only: true MD025: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d9b4023f0..1a05c35c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ ci: repos: - repo: "https://github.com/pre-commit/pre-commit-hooks" - rev: "v4.2.0" + rev: "v5.0.0" hooks: - id: "check-executables-have-shebangs" - id: "check-json" @@ -30,7 +30,7 @@ repos: - id: "mixed-line-ending" - repo: "https://github.com/adrienverge/yamllint.git" - rev: "v1.26.3" + rev: "v1.35.1" hooks: - id: "yamllint" args: ["--format", "parsable", "--strict"] @@ -41,13 +41,13 @@ repos: )$ - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.31.1 + rev: v0.43.0 hooks: - id: markdownlint args: ["--fix"] - repo: "https://github.com/jumanjihouse/pre-commit-hook-yamlfmt" - rev: "0.1.1" + rev: "0.2.3" hooks: - id: "yamlfmt" args: @@ -63,23 +63,23 @@ repos: exclude: ".*" - repo: "https://github.com/mattlqx/pre-commit-search-and-replace" - rev: "v1.0.5" + rev: "v1.1.8" hooks: - id: "search-and-replace" - repo: "https://github.com/asottile/pyupgrade" - rev: "v2.31.1" + rev: "v3.19.1" hooks: - id: "pyupgrade" args: ["--py39-plus"] - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: "https://github.com/psf/black" - rev: "22.3.0" + rev: "24.10.0" hooks: - id: "black" args: @@ -89,7 +89,7 @@ repos: files: '^((custom_components|tests)/.+)?[^/]+\.py$' - repo: "https://github.com/PyCQA/flake8" - rev: "4.0.1" + rev: "7.1.1" hooks: - id: "flake8" additional_dependencies: @@ -99,7 +99,7 @@ repos: files: '^(custom_components/.+)?[^/]+\.py$' - repo: "https://github.com/PyCQA/bandit" - rev: "1.7.4" + rev: "1.8.0" hooks: - id: "bandit" args: @@ -108,7 +108,7 @@ repos: # - "--configfile=bandit.yaml" <<: *python-files-with-tests - repo: https://github.com/codespell-project/codespell.git - rev: "v2.1.0" + rev: "v2.3.0" hooks: - id: codespell files: "(.*.md|translations/en.json)" diff --git a/custom_cards/custom_card_imswel_medias/README.md b/custom_cards/custom_card_imswel_medias/README.md index 6e137338b..28b49f162 100644 --- a/custom_cards/custom_card_imswel_medias/README.md +++ b/custom_cards/custom_card_imswel_medias/README.md @@ -29,6 +29,7 @@ Initial release ## Requirements This card needs the following to function correctly: + | Component | Required | | ----------------------------------------------------------------------------------------- | ---------------------------------- | |[Plex Recently Added](https://github.com/NemesisRE/sensor.plex_recently_added) | Yes for **`Media Library Card`** | @@ -40,6 +41,7 @@ This card needs the following to function correctly: **Media Library Card** for [Plex Recently Added](https://github.com/NemesisRE/sensor.plex_recently_added) : ![example-image-plex](../../docs/assets/img/custom_card_imswel_medias/medias_library_plex.png)
+ | Variable | Default | Required | Notes | | ----------------------------- | ------- | -------- | ----------------------------------------------------------------------- | | ulm_custom_card_imswel_medias_index | 1 | Yes | The index of the item in your **Plex library** to show. | @@ -58,6 +60,7 @@ This card needs the following to function correctly: ![example-image-radarr](../../docs/assets/img/custom_card_imswel_medias/medias_upcoming_radarr.png) ![example-image-sonarr](../../docs/assets/img/custom_card_imswel_medias/medias_upcoming_sonarr.png)
+ | Variable | Default | Required | Notes | | ----------------------------- | ------- | -------- | -------------------------------------------------------------------------------------------------------- | | ulm_custom_card_imswel_medias_index | 1 | Yes | The index of the item in your **Radarr/Sonarr library** to show. | diff --git a/custom_components/ui_lovelace_minimalist/__init__.py b/custom_components/ui_lovelace_minimalist/__init__.py index be8369bbc..8498321b2 100644 --- a/custom_components/ui_lovelace_minimalist/__init__.py +++ b/custom_components/ui_lovelace_minimalist/__init__.py @@ -11,6 +11,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.loader import async_get_integration +import voluptuous as vol from .base import UlmBase from .const import DOMAIN, NAME @@ -18,6 +19,8 @@ _LOGGER: logging.Logger = logging.getLogger(__package__) +CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA) + async def async_initialize_integration( hass: HomeAssistant, diff --git a/custom_components/ui_lovelace_minimalist/base.py b/custom_components/ui_lovelace_minimalist/base.py index dc2e0dcae..417f24a3d 100644 --- a/custom_components/ui_lovelace_minimalist/base.py +++ b/custom_components/ui_lovelace_minimalist/base.py @@ -2,13 +2,14 @@ from __future__ import annotations +from collections.abc import Awaitable from dataclasses import asdict, dataclass, field from functools import partial import logging import os import pathlib import shutil -from typing import Any, Awaitable, Callable +from typing import Any, Callable from aiogithubapi import ( GitHubAPI, @@ -419,9 +420,9 @@ async def configure_dashboard(self) -> bool: async_remove_panel(self.hass, "ui-lovelace-minimalist") if self.configuration.adaptive_ui_enabled: - self.hass.data["lovelace"]["dashboards"][ - adv_dashboard_url - ] = LovelaceYAML(self.hass, adv_dashboard_url, adv_dashboard_config) + self.hass.data["lovelace"]["dashboards"][adv_dashboard_url] = ( + LovelaceYAML(self.hass, adv_dashboard_url, adv_dashboard_config) + ) _register_panel( self.hass, adv_dashboard_url, "yaml", adv_dashboard_config, True diff --git a/custom_components/ui_lovelace_minimalist/config_flow.py b/custom_components/ui_lovelace_minimalist/config_flow.py index 6b8d2245f..9ad4f2892 100644 --- a/custom_components/ui_lovelace_minimalist/config_flow.py +++ b/custom_components/ui_lovelace_minimalist/config_flow.py @@ -7,7 +7,9 @@ from aiogithubapi import GitHubDeviceAPI, GitHubException from aiogithubapi.common.const import OAUTH_USER_LOGIN +from awesomeversion import AwesomeVersion from homeassistant import config_entries +from homeassistant.const import __version__ as HAVERSION from homeassistant.core import callback from homeassistant.helpers import aiohttp_client import homeassistant.helpers.config_validation as cv @@ -51,6 +53,10 @@ _LOGGER: logging.Logger = logging.getLogger(__name__) +# Version threshold for config_entry setting in options flow +# See: https://github.com/home-assistant/core/pull/129562 +HA_OPTIONS_FLOW_VERSION_THRESHOLD = "2024.11.99" + async def ulm_config_option_schema(options: dict = {}) -> dict: """Return a schema for ULM configuration options.""" @@ -242,7 +248,10 @@ class UlmOptionFlowHandler(config_entries.OptionsFlow): def __init__(self, config_entry: config_entries.ConfigEntry) -> None: """Initialize.""" - self.config_entry = config_entry + self.options = dict(config_entry.options) + # See: https://github.com/home-assistant/core/pull/129562 + if AwesomeVersion(HAVERSION) < HA_OPTIONS_FLOW_VERSION_THRESHOLD: + self.config_entry = config_entry async def async_step_init(self, _user_input=None): """Manage the options.""" diff --git a/custom_components/ui_lovelace_minimalist/const.py b/custom_components/ui_lovelace_minimalist/const.py index 92c6056f6..e75a2c2e9 100644 --- a/custom_components/ui_lovelace_minimalist/const.py +++ b/custom_components/ui_lovelace_minimalist/const.py @@ -1,4 +1,5 @@ """Constants for UI Lovelace Minimalist.""" + from typing import TypeVar # Base component constants @@ -19,50 +20,49 @@ COMMUNITY_CARDS_FOLDER = "custom_cards" LANGUAGES = { - "Català": "ca", "Czech": "cs", "Danish": "da", - "Dutch": "nl", + "German": "de", "English (GB)": "en", + "Spanish": "es", + "Català": "ca", "French": "fr", - "German": "de", - "Hebrew": "he", "Italian": "it", + "Dutch": "nl", + "Hebrew": "he", "Norwegian": "no", "Polish": "pl", - "Portuguese (Brazil)": "pt-BR", "Portuguese": "pt", - "Russian": "ru", - "Slovak": "sk", + "Portuguese (Brazil)": "pt-BR", "Slovenian": "sl", - "Spanish": "es", + "Slovak": "sk", "Swedish": "sv", "Turkish": "tr", - "Ukrainian": "uk", + "Russian": "ru", "中文(简体)": "zh-CN", } CONF_LANGUAGE = "language" CONF_LANGUAGES = [ - "Català", "Czech", "Danish", - "Dutch", + "German", "English (GB)", + "Spanish", + "Català", "French", - "German", - "Hebrew", "Italian", + "Dutch", + "Hebrew", "Norwegian", "Polish", - "Portuguese (Brazil)", "Portuguese", - "Russian", + "Portuguese (Brazil)", "Slovenian", - "Spanish", + "Slovak", "Swedish", "Turkish", - "Ukrainian", + "Russian", "中文(简体)", ] CONF_SIDEPANEL_ENABLED = "sidepanel_enabled" diff --git a/custom_components/ui_lovelace_minimalist/enums.py b/custom_components/ui_lovelace_minimalist/enums.py index fa4d36405..48b3b15ca 100644 --- a/custom_components/ui_lovelace_minimalist/enums.py +++ b/custom_components/ui_lovelace_minimalist/enums.py @@ -1,4 +1,5 @@ """Helper constants.""" + # pylint: disable=missing-class-docstring from enum import Enum diff --git a/custom_components/ui_lovelace_minimalist/utils/decode.py b/custom_components/ui_lovelace_minimalist/utils/decode.py index 9d42516c0..708f22f1a 100644 --- a/custom_components/ui_lovelace_minimalist/utils/decode.py +++ b/custom_components/ui_lovelace_minimalist/utils/decode.py @@ -1,4 +1,5 @@ """Util to decode content from the github API.""" + from base64 import b64decode diff --git a/custom_components/ui_lovelace_minimalist/utils/logger.py b/custom_components/ui_lovelace_minimalist/utils/logger.py index 699d7f1fe..47a77c07e 100644 --- a/custom_components/ui_lovelace_minimalist/utils/logger.py +++ b/custom_components/ui_lovelace_minimalist/utils/logger.py @@ -1,4 +1,5 @@ """Custom logger for HACS.""" + import logging from ..const import PACKAGE_NAME diff --git a/docs/usage/custom_cards/custom_card_imswel_medias.md b/docs/usage/custom_cards/custom_card_imswel_medias.md index e1994dc63..69c2405aa 100644 --- a/docs/usage/custom_cards/custom_card_imswel_medias.md +++ b/docs/usage/custom_cards/custom_card_imswel_medias.md @@ -29,6 +29,7 @@ Initial release ## Requirements This card needs the following to function correctly: + | Component | Required | | ----------------------------------------------------------------------------------------- | ---------------------------------- | |[Plex Recently Added](https://github.com/NemesisRE/sensor.plex_recently_added) | Yes for **`Media Library Card`** | @@ -40,6 +41,7 @@ This card needs the following to function correctly: **Media Library Card** for [Plex Recently Added](https://github.com/NemesisRE/sensor.plex_recently_added) : ![example-image-plex](../../assets/img/custom_card_imswel_medias/medias_library_plex.png)
+ | Variable | Default | Required | Notes | | ----------------------------- | ------- | -------- | ----------------------------------------------------------------------- | | ulm_custom_card_imswel_medias_index | 1 | Yes | The index of the item in your **Plex library** to show. | @@ -58,6 +60,7 @@ This card needs the following to function correctly: ![example-image-radarr](../../assets/img/custom_card_imswel_medias/medias_upcoming_radarr.png) ![example-image-sonarr](../../assets/img/custom_card_imswel_medias/medias_upcoming_sonarr.png)
+ | Variable | Default | Required | Notes | | ----------------------------- | ------- | -------- | -------------------------------------------------------------------------------------------------------- | | ulm_custom_card_imswel_medias_index | 1 | Yes | The index of the item in your **Radarr/Sonarr library** to show. |