Skip to content

Commit

Permalink
Fix test_proactive_adaptation_with_separate_commands (#970)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
basnijholt authored Apr 7, 2024
1 parent 47cbda5 commit d23f6ec
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/install_dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ runs:
- name: Install dependencies
shell: bash
run: |
./scripts/install_ha
./scripts/setup-dependencies
./scripts/setup-symlinks
24 changes: 0 additions & 24 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ async def async_added_to_hass(self) -> None:
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
Expand Down Expand Up @@ -1658,10 +1659,12 @@ def __init__(self, hass: HomeAssistant) -> None:
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,
),
]

Expand Down
10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

File renamed without changes.
9 changes: 8 additions & 1 deletion scripts/setup-devcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 13 additions & 0 deletions scripts/setup-symlinks
Original file line number Diff line number Diff line change
@@ -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 -
1 change: 1 addition & 0 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d23f6ec

Please sign in to comment.