From 24bdc8520de6e0961686ffa64e56e04612d98773 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sat, 26 Feb 2022 13:11:01 +0100 Subject: [PATCH] Add support for diagnostics (#37) * Bump library version * Add diagnostics * Update requirements * pre-commit autoupdate * Remove Python 3.8 from CI, add 3.9 * Black * Decrease min test coverage --- .github/workflows/push.yml | 57 ++++++++++---------- .pre-commit-config.yaml | 8 +-- custom_components/zadnego_ale/diagnostics.py | 24 +++++++++ custom_components/zadnego_ale/manifest.json | 4 +- requirements-test.txt | 6 +-- setup.cfg | 2 +- 6 files changed, 63 insertions(+), 38 deletions(-) create mode 100644 custom_components/zadnego_ale/diagnostics.py diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ba1972d..4ea509f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,6 +1,7 @@ +--- name: Push -on: [push, pull_request] +"on": [push, pull_request] jobs: check: @@ -9,32 +10,32 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.8", "3.9"] + python-version: ["3.9", "3.10"] steps: - - uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install requirements - run: | - pip install -r requirements-test.txt - - name: Check with isort - run: | - isort custom_components/zadnego_ale tests --check-only - - name: Check with Black Code Formatter - run: | - black custom_components/zadnego_ale tests --check - - name: Lint with flake8 - run: | - flake8 custom_components/zadnego_ale tests - - name: Lint with pylint - run: | - pylint custom_components/zadnego_ale - - name: Test with mypy - run: | - mypy custom_components/zadnego_ale - - name: Test with pytest - run: | - pytest tests + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install requirements + run: | + pip install -r requirements-test.txt + - name: Check with isort + run: | + isort custom_components/zadnego_ale tests --check-only + - name: Check with Black Code Formatter + run: | + black custom_components/zadnego_ale tests --check + - name: Lint with flake8 + run: | + flake8 custom_components/zadnego_ale tests + - name: Lint with pylint + run: | + pylint custom_components/zadnego_ale + - name: Test with mypy + run: | + mypy custom_components/zadnego_ale + - name: Test with pytest + run: | + pytest tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45567fe..0af3243 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.29.1 + rev: v2.31.0 hooks: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/psf/black - rev: 21.12b0 + rev: 22.1.0 hooks: - id: black args: @@ -36,7 +36,7 @@ repos: - mccabe==0.6.1 files: ^(custom_components/zadnego_ale|tests)/.+\.py$ - repo: https://github.com/PyCQA/bandit - rev: 1.7.1 + rev: 1.7.2 hooks: - id: bandit args: @@ -47,7 +47,7 @@ repos: hooks: - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.1.0 hooks: - id: no-commit-to-branch args: diff --git a/custom_components/zadnego_ale/diagnostics.py b/custom_components/zadnego_ale/diagnostics.py new file mode 100644 index 0000000..dc1d965 --- /dev/null +++ b/custom_components/zadnego_ale/diagnostics.py @@ -0,0 +1,24 @@ +"""Diagnostics support for Zadnego Ale.""" +from __future__ import annotations + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from . import ZadnegoAleDataUpdateCoordinator +from .const import DOMAIN + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, config_entry: ConfigEntry +) -> dict: + """Return diagnostics for a config entry.""" + coordinator: ZadnegoAleDataUpdateCoordinator = hass.data[DOMAIN][ + config_entry.entry_id + ] + + diagnostics_data = { + "config_entry_data": dict(config_entry.data), + "coordinator_data": coordinator.data, + } + + return diagnostics_data diff --git a/custom_components/zadnego_ale/manifest.json b/custom_components/zadnego_ale/manifest.json index f73c5ec..b844f49 100644 --- a/custom_components/zadnego_ale/manifest.json +++ b/custom_components/zadnego_ale/manifest.json @@ -4,8 +4,8 @@ "documentation": "https://github.com/bieniu/ha-zadnego-ale", "issue_tracker": "https://github.com/bieniu/ha-zadnego-ale/issues", "codeowners": ["@bieniu"], - "requirements": ["zadnegoale==0.6.0"], + "requirements": ["zadnegoale==0.6.2"], "config_flow": true, - "version": "0.6.0", + "version": "0.6.4", "iot_class": "cloud_polling" } diff --git a/requirements-test.txt b/requirements-test.txt index 0d3f9a3..1df446e 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -2,12 +2,12 @@ aiohttp_cors==0.7.0 black==22.1.0 coverage>=6.0.2 flake8==4.0.1 -homeassistant>=2021.11.0b0 +homeassistant isort==5.10.1 mypy==0.931 pre-commit==2.17.0 pylint==2.12.2 pytest-cov>=2.12.1 -pytest-homeassistant-custom-component +pytest-homeassistant-custom-component==0.6.18 pytest -zadnegoale==0.6.1 +zadnegoale==0.6.2 diff --git a/setup.cfg b/setup.cfg index 11c9a24..270b6d7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -60,5 +60,5 @@ exclude_lines = raise NotImplemented() if __name__ == '__main__': main() -fail_under = 93 +fail_under = 90 show_missing = true \ No newline at end of file