Add sensor tests #6

Merged
mat merged 3 commits from test/sensor into main 2026-04-24 12:38:53 +00:00
Owner

Summary

  • Adds tests/test_sensor.py with 6 cases:
    • Empty site list → no sensors.
    • Leaf device → power, energy, auto-production-rate.
    • Parent + partChilds → power+energy per child (not on the parent).
    • ComwattPowerSensor reads values[-1] with correct unit/device-class/state-class.
    • ComwattEnergySensor accumulates a delta (documents current shipped behavior; see finding H4).
    • ComwattAutoProductionRateSensor marked xfail against finding C1 (undefined auto_production_rate).

Depends on

  • #3 (test infrastructure).

Test plan

  • pytest tests/test_sensor.py — 5 passed, 1 xfailed
  • When C1 lands, the xfail should flip to passing; that PR should drop the marker.

Notes

  • The energy-sensor test locks in the current client-side accumulator semantics. Finding H4 argues for switching to a cumulative API counter — the test should be rewritten in that PR, not before, so any accidental state-class / unit regression is caught in the meantime.
## Summary - Adds `tests/test_sensor.py` with 6 cases: - Empty site list → no sensors. - Leaf device → power, energy, auto-production-rate. - Parent + `partChilds` → power+energy per child (not on the parent). - `ComwattPowerSensor` reads `values[-1]` with correct unit/device-class/state-class. - `ComwattEnergySensor` accumulates a delta (documents current shipped behavior; see finding H4). - `ComwattAutoProductionRateSensor` marked **xfail** against finding **C1** (undefined `auto_production_rate`). ## Depends on - #3 (test infrastructure). ## Test plan - [x] `pytest tests/test_sensor.py` — 5 passed, 1 xfailed - [ ] When C1 lands, the xfail should flip to passing; that PR should drop the marker. ## Notes - The energy-sensor test locks in the *current* client-side accumulator semantics. Finding H4 argues for switching to a cumulative API counter — the test should be rewritten in that PR, not before, so any accidental state-class / unit regression is caught in the meantime.
(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 sensor 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
c741403b7e
Covers the three sensor classes and the device-discovery walk:

- Empty site list → no sensor entities registered.
- Site with one leaf device → auto-production-rate, power, energy.
- Site with a parent that has `partChilds` → power+energy per child
  (no sensors on the parent itself).
- `ComwattPowerSensor` reports `values[-1]` with correct unit, device
  class, and state class.
- `ComwattEnergySensor` accumulates deltas (documents current shipped
  behavior; finding H4 proposes replacing this with a cumulative
  counter — the test should be rewritten when that lands).
- `ComwattAutoProductionRateSensor` is marked xfail against finding
  C1 (undefined `auto_production_rate` reference).
mat force-pushed test/sensor from c741403b7e
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 0ad95aa9d0
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:28 +00:00
Compare
mat changed title from (AI) Add sensor tests to Add sensor tests 2026-04-24 12:25:50 +00:00
mat force-pushed test/sensor from 0ad95aa9d0
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 c5b539e274
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:54 +00:00
Compare
mat merged commit e5e5d0af84 into main 2026-04-24 12:38:53 +00:00
mat deleted branch test/sensor 2026-04-24 12:38:53 +00:00
mat referenced this pull request from a commit 2026-04-24 12:38:54 +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
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!6
No description provided.