From 2ff5b057d9d9be601445a7cbd0efdb82960a1da3 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Fri, 3 Jan 2025 20:57:07 +0000 Subject: [PATCH 1/3] Change dev environment to Python 3.13 --- .devcontainer/devcontainer.json | 2 +- .github/workflows/pre-release.yml | 4 ++- .github/workflows/pull.yml | 6 ++-- .github/workflows/push.yml | 6 ++-- .vscode/settings.json | 2 +- requirements_dev.txt | 2 +- requirements_test.txt | 2 +- requirements_test312.txt | 2 +- requirements_test313.txt | 1 + scripts/pytest_all_ha_versions_python312 | 18 +++++++++++ scripts/pytest_all_ha_versions_python313 | 39 ++++++++++++++++++++++++ 11 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 requirements_test313.txt create mode 100644 scripts/pytest_all_ha_versions_python313 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a89d4bf..14a5536 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ // Depending on setup, "remoteUser": "vscode", might be preferred to add. { "name": "EV Smart Charging", - "image": "mcr.microsoft.com/devcontainers/python:3.12", + "image": "mcr.microsoft.com/devcontainers/python:3.13", "postCreateCommand": "scripts/setup", "forwardPorts": [ 8123 diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 0eacdd4..dde5109 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -9,12 +9,14 @@ jobs: runs-on: "ubuntu-latest" strategy: matrix: - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] include: - python-version: "3.11" pytest_all_ha_versions: "pytest_all_ha_versions_python311" - python-version: "3.12" pytest_all_ha_versions: "pytest_all_ha_versions_python312" + - python-version: "3.13" + pytest_all_ha_versions: "pytest_all_ha_versions_python313" steps: - name: Check out code from GitHub uses: "actions/checkout@v4" diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 2a7808a..fd9cf0f 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -34,12 +34,14 @@ jobs: runs-on: "ubuntu-latest" strategy: matrix: - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] include: - python-version: "3.11" requirements: "requirements_test311.txt" - python-version: "3.12" requirements: "requirements_test312.txt" + - python-version: "3.13" + requirements: "requirements_test313.txt" name: Run tests steps: - name: Check out code from GitHub @@ -65,7 +67,7 @@ jobs: -p no:sugar \ tests - name: "Upload coverage to Codecov" - if: ${{ matrix.python-version == '3.12' }} + if: ${{ matrix.python-version == '3.13' }} uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index cab050c..b45f2b5 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -38,12 +38,14 @@ jobs: runs-on: "ubuntu-latest" strategy: matrix: - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] include: - python-version: "3.11" requirements: "requirements_test311.txt" - python-version: "3.12" requirements: "requirements_test312.txt" + - python-version: "3.13" + requirements: "requirements_test313.txt" name: Run tests steps: - name: Check out code from GitHub @@ -69,7 +71,7 @@ jobs: -p no:sugar \ tests - name: "Upload coverage to Codecov" - if: ${{ matrix.python-version == '3.12' }} + if: ${{ matrix.python-version == '3.13' }} uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.vscode/settings.json b/.vscode/settings.json index 19d71a3..bb84fce 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,6 @@ "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "python.analysis.extraPaths": [ - "/home/vscode/.local/lib/python3.10/site-packages/homeassistant" + "/home/vscode/.local/lib/python3.13/site-packages/homeassistant" ] } \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt index 3dc1955..6a8e10b 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,2 +1,2 @@ colorlog==6.9.0 -homeassistant==2024.7.4 +homeassistant==2024.12.5 diff --git a/requirements_test.txt b/requirements_test.txt index 17a8147..a27b4c6 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1 +1 @@ -pytest-homeassistant-custom-component==0.13.148 +pytest-homeassistant-custom-component==0.13.195 diff --git a/requirements_test312.txt b/requirements_test312.txt index 0f44324..a27b4c6 100644 --- a/requirements_test312.txt +++ b/requirements_test312.txt @@ -1 +1 @@ -pytest-homeassistant-custom-component==0.13.136 +pytest-homeassistant-custom-component==0.13.195 diff --git a/requirements_test313.txt b/requirements_test313.txt new file mode 100644 index 0000000..a27b4c6 --- /dev/null +++ b/requirements_test313.txt @@ -0,0 +1 @@ +pytest-homeassistant-custom-component==0.13.195 diff --git a/scripts/pytest_all_ha_versions_python312 b/scripts/pytest_all_ha_versions_python312 index 35faebc..293e2ac 100644 --- a/scripts/pytest_all_ha_versions_python312 +++ b/scripts/pytest_all_ha_versions_python312 @@ -53,3 +53,21 @@ run_next_test "auto" pip3 install -qq homeassistant==2024.7.4 pytest-homeassistant-custom-component==0.13.148 run_next_test "auto" + +pip3 install -qq homeassistant==2024.8.3 pytest-homeassistant-custom-component==0.13.155 +run_next_test "auto" + +pip3 install -qq homeassistant==2024.9.3 pytest-homeassistant-custom-component==0.13.164 +run_next_test "auto" + +pip3 install -qq homeassistant==2024.10.4 pytest-homeassistant-custom-component==0.13.175 +run_next_test "auto" + +pip3 install -qq homeassistant==2024.11.3 pytest-homeassistant-custom-component==0.13.184 +run_next_test "auto" + +pip3 install -qq homeassistant==2024.12.5 pytest-homeassistant-custom-component==0.13.195 +run_next_test "auto" + + +# As of HA 2025.2, Python 3.12 is not supported. \ No newline at end of file diff --git a/scripts/pytest_all_ha_versions_python313 b/scripts/pytest_all_ha_versions_python313 new file mode 100644 index 0000000..2736cd8 --- /dev/null +++ b/scripts/pytest_all_ha_versions_python313 @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# https://github.com/home-assistant/core +# https://github.com/MatthewFlamm/pytest-homeassistant-custom-component + +run_first_test() { + local asynciomode="$1" # First parameter, "strict" or "auto" + echo + pip3 list 2>/dev/null | grep homeassistant | grep -v "\-home" + pip3 list 2>/dev/null | grep pytest-homeassistant-custom-component + output=$(pytest -q --no-summary --asyncio-mode=$asynciomode tests 2>&1 | grep passed) + echo "$output" + number1=$(echo "$output" | awk '{print $1}') + if [ -z "$number1" ]; then + echo "No passed test cases!" + exit 1 + fi +} + +run_next_test() { + local asynciomode="$1" # First parameter, "strict" or "auto" + echo + pip3 list 2>/dev/null | grep homeassistant | grep -v "\-home" + pip3 list 2>/dev/null | grep pytest-homeassistant-custom-component + output=$(pytest -q --no-summary --asyncio-mode=$asynciomode tests 2>&1 | grep passed) + echo "$output" + number2=$(echo "$output" | awk '{print $1}') + if [ "$number1" != "$number2" ]; then + echo "Results are different!" + exit 1 + fi +} + +# As of HA 2024.12, Python 3.13 is supported. +pip3 install -qq homeassistant==2024.12.5 pytest-homeassistant-custom-component==0.13.195 +run_first_test "auto" + +#pip3 install -qq homeassistant==2025.1.x pytest-homeassistant-custom-component==0.13.xxx +#run_next_test "auto" \ No newline at end of file From 95482096805a2838b8c9d956977fbec43400b878 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Fri, 3 Jan 2025 21:03:44 +0000 Subject: [PATCH 2/3] Use async_update_entry to change title. --- tests/test_init.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_init.py b/tests/test_init.py index f5817c2..79a3f25 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -222,7 +222,7 @@ async def test_setup_new_integration_name(hass, bypass_validate_input_sensors): ) # Change title - config_entry.title = "New title" + hass.config_entries.async_update_entry(config_entry, title="New title") # Reload the entry and assert that the data from above is still there assert await async_reload_entry(hass, config_entry) is None @@ -239,7 +239,7 @@ async def test_setup_new_integration_name(hass, bypass_validate_input_sensors): assert device.name_by_user == "New title" or device.name == "New title" # Change a changed title - config_entry.title = "New title2" + hass.config_entries.async_update_entry(config_entry, title="New title2") # Reload the entry and assert that the data from above is still there assert await async_reload_entry(hass, config_entry) is None From da28bf3e9347ed64a783e169ca6b8e34e6529a85 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Sat, 4 Jan 2025 09:50:41 +0000 Subject: [PATCH 3/3] Set justMyCode to false. --- .vscode/launch.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0954be6..da6e648 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -26,6 +26,7 @@ "debug-test" ], "console": "integratedTerminal", + "justMyCode": false, "env": { "PYTEST_ADDOPTS": "--no-cov" }