diff --git a/.github/workflows/constraints.txt b/.github/workflows/constraints.txt index 9e8f915..1e17951 100644 --- a/.github/workflows/constraints.txt +++ b/.github/workflows/constraints.txt @@ -1,7 +1,7 @@ -pip>=8.0.3,<24.1 -pre-commit==3.7.1 -bandit==1.7.8 -ruff==0.5.0 -pre-comit-hooks==4.1.0 -pyupgrade==3.15.0 -reorder-python-imports==3.12.0 +pip>=8.0.3,<24.1 +pre-commit==3.7.1 +bandit==1.7.8 +ruff==0.5.0 +pre-comit-hooks==4.1.0 +pyupgrade==3.15.0 +reorder-python-imports==3.12.0 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 59125e7..9af52e7 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -26,15 +26,19 @@ jobs: - name: Upgrade pip run: | - pip install --constraint=.github/workflows/constraints.txt pip + python -m venv venv + . venv/bin/activate + pip install "$(grep '^uv' < requirements_dev.txt)" pip --version - name: Install Python modules run: | - pip install --constraint=.github/workflows/constraints.txt pre-commit ruff + . venv/bin/activate + uv pip install "$(grep '^pre-commit' < requirements_dev.txt)" - name: Run pre-commit on all files run: | + . venv/bin/activate pre-commit run --all-files --show-diff-on-failure --color=always hacs: @@ -74,8 +78,8 @@ jobs: python-version: ${{ env.DEFAULT_PYTHON }} - name: Install requirements run: | - pip install --constraint=.github/workflows/constraints.txt pip - pip install -r requirements_test.txt + pip install "$(grep '^uv' < requirements_dev.txt)" + uv pip install -r requirements_test.txt --system --prerelease=allow - name: Tests suite run: | pytest \ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3885a37..c87d180 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,14 +6,13 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: local + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.4 hooks: + # Run the linter. - id: ruff - name: ruff - entry: ruff - language: system - types: [python] - args: [--fix] + # Run the formatter. + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.2.1 hooks: diff --git a/custom_components/dius/__init__.py b/custom_components/dius/__init__.py index 2e096d6..9c23226 100644 --- a/custom_components/dius/__init__.py +++ b/custom_components/dius/__init__.py @@ -51,7 +51,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): # setup options flow with defaults if not entry.options: - entry.options = {"sensor": True, "plug": True, "U_conv": 19.3, "W_adj": 0} + options = {"sensor": True, "plug": True, "U_conv": 19.3, "W_adj": 0} + hass.config_entries.async_update_entry(entry, options=options) # probably a better approach to this... for platform in PLATFORMS: diff --git a/requirements_dev.txt b/requirements_dev.txt index 9a54274..92d439b 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1 +1,3 @@ homeassistant>=2023.03 +pre-commit==4.0.1 +uv>=0.4 diff --git a/tests/test_api.py b/tests/test_api.py index 333cda8..0654f7c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -6,7 +6,6 @@ from unittest import mock from unittest.mock import patch -from custom_components.dius import async_setup_entry from custom_components.dius import async_unload_entry from custom_components.dius.const import DOMAIN from pytest_homeassistant_custom_component.common import MockConfigEntry @@ -74,8 +73,11 @@ async def test_api(hass, caplog, socket_enabled): entry_id="testapi", options=MOCK_OPTIONS, ) - await async_setup_entry(hass, config_entry) - # await hass.async_block_till_done() + config_entry.add_to_hass(hass) + await hass.async_block_till_done() + + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() # client = hass.data[DOMAIN][config_entry.entry_id].api await asyncio.sleep(1) diff --git a/tests/test_init.py b/tests/test_init.py index fae26c1..e65b8bc 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -30,11 +30,15 @@ async def test_setup_unload_and_reload_entry(hass, bypass_get_data, skip_api_sta """Test entry setup and unload.""" # Create a mock entry so we don't have to go through config flow config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test") + config_entry.add_to_hass(hass) + await hass.async_block_till_done() + + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() # Set up the entry and assert that the values set during setup are where we expect # them to be. Because we have patched the DiusDataUpdateCoordinator.async_get_data # call, no code from custom_components/dius/api.py actually runs. - assert await async_setup_entry(hass, config_entry) assert DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN] assert isinstance( hass.data[DOMAIN][config_entry.entry_id], DiusDataUpdateCoordinator