Add switch tests #8

Merged
mat merged 3 commits from test/switch into main 2026-04-24 12:39:01 +00:00
Owner

Summary

  • Adds tests/test_switch.py with 5 cases:
    • No devices → no switch entities.
    • Device without a switchable capacity → no switch entity.
    • Device with a POWER_SWITCH capacity → one switch entity whose initial is_on reflects capacity.enable.
    • switch.turn_on service call → client.switch_capacity(capacity_id, True).
    • switch.turn_off service call → client.switch_capacity(capacity_id, False).

Depends on

  • #3 (test infrastructure).

Test plan

  • pytest tests/test_switch.py — 5 passed locally.

Notes

  • Tests resolve the entity_id via the entity registry rather than hard-coding switch.relay_switch, so naming-related changes (e.g. finding H3) don't spuriously break these tests.
## Summary - Adds `tests/test_switch.py` with 5 cases: - No devices → no switch entities. - Device without a switchable capacity → no switch entity. - Device with a `POWER_SWITCH` capacity → one switch entity whose initial `is_on` reflects `capacity.enable`. - `switch.turn_on` service call → `client.switch_capacity(capacity_id, True)`. - `switch.turn_off` service call → `client.switch_capacity(capacity_id, False)`. ## Depends on - #3 (test infrastructure). ## Test plan - [x] `pytest tests/test_switch.py` — 5 passed locally. ## Notes - Tests resolve the entity_id via the entity registry rather than hard-coding `switch.relay_switch`, so naming-related changes (e.g. finding H3) don't spuriously break these tests.
(AI) Add pytest infrastructure
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
253d3d9515
Adds the plumbing needed to run Home Assistant custom-integration tests:

- `requirements-test.txt` pins `pytest-homeassistant-custom-component`
  (which transitively pulls `homeassistant`) and the runtime dependency
  `comwatt-client`.
- `pytest.ini` enables `asyncio_mode = auto` and points pytest at
  `tests/`.
- `tests/conftest.py` loads the pytest-homeassistant-custom-component
  plugin, auto-enables custom integrations, and exposes a
  `mock_comwatt_client` fixture that patches every import site of
  `ComwattClient` used by the integration.
- `tests/test_smoke.py` exercises the plumbing and asserts basic
  manifest/domain invariants.

Follow-up PRs will add config-flow, init, sensor, and switch tests on
top of this scaffolding.
🐛 (AI) Fix cookie jar mock in test fixture
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
05511bb47b
`_make_fake_client` assigned a plain list to `session.cookies` then
tried to attach a `get_dict` attribute to it, which fails because
lists don't accept arbitrary attributes. Introduce `_FakeCookieJar`, a
list subclass that answers `get_dict()` the way `requests`' own
`RequestsCookieJar` does, so both iteration (used by the config flow)
and `get_dict()` (used by the integration to snapshot the session)
work against the mock.
(AI) Add switch tests
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
2857e17065
Covers switch discovery, initial state, and service calls:

- No devices → no switch entities.
- Device with features but no POWER_SWITCH/RELAY capacity → no switch.
- Device with a POWER_SWITCH capacity → one switch entity whose
  initial `is_on` reflects `capacity.enable`.
- `switch.turn_on` → `client.switch_capacity(capacity_id, True)`.
- `switch.turn_off` → `client.switch_capacity(capacity_id, False)`.

Uses the entity registry to resolve entity_id rather than hard-coding
the slug, since later changes to `has_entity_name`/naming (H3) would
otherwise break these tests spuriously.
mat force-pushed test/switch from 2857e17065
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
to 20e72d27f7
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
2026-04-24 12:25:31 +00:00
Compare
mat changed title from (AI) Add switch tests to Add switch tests 2026-04-24 12:25:51 +00:00
mat force-pushed test/switch from 20e72d27f7
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
to 845cddd42e
All checks were successful
Validate / validate-hacs (push) Has been skipped
Validate / validate-hassfest (push) Has been skipped
Validate / validate-hacs (pull_request) Has been skipped
Validate / validate-hassfest (pull_request) Has been skipped
2026-04-24 12:36:57 +00:00
Compare
mat merged commit b42710c5ce into main 2026-04-24 12:39:01 +00:00
mat deleted branch test/switch 2026-04-24 12:39:01 +00:00
mat referenced this pull request from a commit 2026-04-24 12:39:02 +00:00
mat referenced this pull request from a commit 2026-04-24 14:26:33 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mat/homeassistant-comwatt!8
No description provided.