From c0c363136bcc90190081f1f6a6eff52ec6e25c21 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Thu, 6 Apr 2023 16:36:57 -0700 Subject: [PATCH] Test multiple Home Assistant releases and the dev branch (#552) * Test for multiple Home Assistant versions * Install ulid-transform * remove unnecessary unsafe `async_set` from test * Skip test_state_change_handlers in <2023.4 * Revert "Skip test_state_change_handlers in <2023.4" This reverts commit 8d01b6ec4ea8b97feb8dabf8b737be604755dffd. --------- Co-authored-by: Benjamin Auquite --- .../workflows/install_dependencies/action.yml | 12 ++++++--- .github/workflows/pytest.yaml | 5 +++- .github/workflows/update-readme.yml | 2 +- tests/test_switch.py | 27 +++++-------------- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.github/workflows/install_dependencies/action.yml b/.github/workflows/install_dependencies/action.yml index 75820072..df0bee8a 100644 --- a/.github/workflows/install_dependencies/action.yml +++ b/.github/workflows/install_dependencies/action.yml @@ -1,10 +1,14 @@ name: 'Install Dependencies' description: 'Install Home Assistant and test dependencies' inputs: - python_version: + python-version: description: 'Python version' required: true default: '3.10' + core-version: + description: 'Home Assistant core version' + required: false + default: 'dev' runs: using: "composite" @@ -21,11 +25,12 @@ runs: with: repository: home-assistant/core path: core - - name: Set up Python ${{ inputs.python_version }} + ref: ${{ inputs.core-version }} + - name: Set up Python ${{ inputs.python-version }} id: python uses: actions/setup-python@v4.1.0 with: - python-version: ${{ inputs.python_version }} + python-version: ${{ inputs.python-version }} - name: Install dependencies shell: bash run: | @@ -33,4 +38,5 @@ runs: pip install -r core/requirements.txt --use-pep517 pip install -r core/requirements_test.txt --use-pep517 pip install -e core/ --use-pep517 + pip install ulid-transform # this is in Adaptive-lighting's manifest.json pip install $(python test_dependencies.py) --use-pep517 diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 02bf93e3..cea75602 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -11,8 +11,10 @@ jobs: runs-on: ubuntu-20.04 timeout-minutes: 60 strategy: + fail-fast: false matrix: python-version: ["3.10"] + core-version: ["2023.2.5", "2023.3.6", "2023.4.0", "dev"] steps: - name: Check out code from GitHub uses: actions/checkout@v3 @@ -20,7 +22,8 @@ jobs: - name: Install Home Assistant uses: ./.github/workflows/install_dependencies with: - python_version: ${{ matrix.python-version }} + python-version: ${{ matrix.python-version }} + core-version: ${{ matrix.core-version }} - name: Click here for troubleshooting steps if tests break again. run: | diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 1f661333..2c2754fb 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -20,7 +20,7 @@ jobs: - name: Install Home Assistant uses: ./.github/workflows/install_dependencies with: - python_version: "3.10" + python-version: "3.10" - name: Install markdown-code-runner and README code dependencies run: | diff --git a/tests/test_switch.py b/tests/test_switch.py index ae722b0d..f6d671f4 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -1070,27 +1070,14 @@ async def test_state_change_handlers(hass): await turn_light(True) assert not switch.turn_on_off_listener.manual_control[ENTITY_LIGHT] - # last_state_change should have our state changes. - # Change brightness by async_set (not using 'light.turn_on') - new_brightness = 50 - await set_brightness(new_brightness) - _LOGGER.debug("Test: Brightness set to %s", new_brightness) + await turn_light(True, brightness=50) + _LOGGER.debug("Test: Brightness set to %s", 50) - # mock homeassistant.core.HomeAssistant.helpers.entity_component.async_update_entity - # Otherwise what happens is update_entity() refreshes the state to the last call of - # light.turn_on(). This is because we are not using hass.states.async_set() to - # set the brightness of the light. We mock `async_update_ha_state` because - # `async_update_entity` calls it. - with patch("homeassistant.helpers.entity.Entity.async_update_ha_state"): - # On next update ENTITY_LIGHT should be marked as manually controlled - await update(force=False) - assert ( - switch.turn_on_off_listener.last_service_data.get(ENTITY_LIGHT) is not None - ) - assert ( - switch.turn_on_off_listener.last_state_change.get(ENTITY_LIGHT) is not None - ) - assert switch.turn_on_off_listener.manual_control[ENTITY_LIGHT] + # On next update ENTITY_LIGHT should be marked as manually controlled + await update(force=False) + assert switch.turn_on_off_listener.last_service_data.get(ENTITY_LIGHT) is not None + assert switch.turn_on_off_listener.last_state_change.get(ENTITY_LIGHT) is not None + assert switch.turn_on_off_listener.manual_control[ENTITY_LIGHT] @pytest.mark.dependency(