Fix test_proactive_adaptation_with_separate_commands (#970)

* Add link script

* Set run_immediately=False

* Add await hass.async_block_till_done()

* Use scripts/link

* Rename scripts

* Links in devcontainer

* Install from setup script
This commit is contained in:
Bas Nijholt 2024-04-07 14:01:05 +02:00 committed by GitHub
commit d23f6ec63a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 29 additions and 46 deletions

View file

@ -34,4 +34,5 @@ runs:
- name: Install dependencies
shell: bash
run: |
./scripts/install_ha
./scripts/setup-dependencies
./scripts/setup-symlinks

View file

@ -62,30 +62,6 @@ jobs:
python-version: ${{ matrix.python-version }}
core-version: ${{ matrix.core-version }}
- name: Click here for troubleshooting steps if tests break again.
run: |
echo "::notice::### If tests fail, try these debug steps: ###"
echo "::notice::### 1. Replace '-qq' from .github/workflow/pytest.yaml. with '-v' for extra verbosity. ###"
echo "::notice::### 2. Push or run action again. ###"
echo "::notice::### 3. Check for any log messages in github actions resembling the following using CTRL+F ###
echo "::notice::### 4. ERROR:homeassistant.setup:Setup failed for 'component': Unable to import component: No module named ''module'' ###"
echo "::notice::### 5. add 'component'.'module' (without the '') from the above log into the 'required' list inside of 'test_dependencies.py' ###"
echo "::notice::### 6. Try again! If more issues persist they should be easily solvable by reading the verbose logs now. ###"
- name: Link custom_components/adaptive_lighting
run: |
cd core
# Link homeassitant.components.adaptive_lighting
cd homeassistant/components
ln -fs ../../../custom_components/adaptive_lighting adaptive_lighting
cd -
# Link adaptive_lighting tests
cd tests/components/
ln -fs ../../../tests adaptive_lighting
cd -
- name: Run pytest
timeout-minutes: 60
run: |

View file

@ -26,11 +26,6 @@ jobs:
run: |
pip install markdown-code-runner==1.0.0 pandas tabulate
- name: Link custom_components/adaptive_lighting
run: |
cd core/homeassistant/components
ln -fs ../../../custom_components/adaptive_lighting adaptive_lighting
- name: Run markdown-code-runner
run: markdown-code-runner --debug README.md

View file

@ -22,13 +22,10 @@ RUN git clone --depth 1 --branch dev https://github.com/home-assistant/core.git
COPY . /app/
# Setup symlinks in core
RUN ln -s /app/custom_components/adaptive_lighting /core/homeassistant/components/adaptive_lighting && \
ln -s /app/tests /core/tests/components/adaptive_lighting && \
# For test_dependencies.py
ln -s /core /app/core
RUN ln -s /core /app/core && /app/scripts/setup-symlinks
# Install home-assistant/core dependencies
RUN /app/scripts/install_ha
RUN /app/scripts/setup-dependencies
WORKDIR /core

View file

@ -952,6 +952,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STARTED,
self._setup_listeners,
run_immediately=False,
)
last_state: State | None = await self.async_get_last_state()
is_new_entry = last_state is None # newly added to HA
@ -1658,10 +1659,12 @@ class AdaptiveLightingManager:
self.hass.bus.async_listen(
EVENT_CALL_SERVICE,
self.turn_on_off_event_listener,
run_immediately=False,
),
self.hass.bus.async_listen(
EVENT_STATE_CHANGED,
self.state_changed_event_listener,
run_immediately=False,
),
]

View file

@ -1,10 +0,0 @@
colorlog==6.7.0
pip>=21.0,<23.2
ruff==0.0.265
pre-commit
# Install HA and test dependencies (pytest, coverage)
# To pin the dev container to a specific HA version, set this dependency
# to the adequate version (add `==<version>`) and rebuild the dev container.
# See https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/releases for version mappings.
pytest-homeassistant-custom-component

View file

@ -7,5 +7,12 @@ if [[ ! -d "core" ]]; then
git clone --depth 1 --branch dev https://github.com/home-assistant/core.git
fi
./scripts/install_ha
pip install \
colorlog==6.7.0 \
pip>=21.0,<23.2 \
ruff==0.0.265 \
pre-commit
./scripts/setup-dependencies
./scripts/setup-symlinks
pre-commit install-hooks

13
scripts/setup-symlinks Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -ex
cd "$(dirname "$0")/.."
# Link custom components
cd core/homeassistant/components/
ln -fs ../../../custom_components/adaptive_lighting adaptive_lighting
cd -
# Link tests
cd core/tests/components/
ln -fs ../../../tests/ adaptive_lighting
cd -

View file

@ -1684,6 +1684,7 @@ async def test_proactive_adaptation_transition_override(hass):
{ATTR_ENTITY_ID: ENTITY_LIGHT_3, ATTR_TRANSITION: 456},
blocking=True,
)
await hass.async_block_till_done()
# Assert that default is used when no transition is specified in service call
assert patched_async_turn_on.call_args_list, patched_async_turn_on.call_args_list