1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-28 03:06:30 +01:00
Files
core/tests/components/vistapool/test_sensor.py
fdebrus 64d17f44fa Add aquarite integration (#168051)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2026-05-25 00:48:48 +02:00

114 lines
3.8 KiB
Python

"""Tests for the Vistapool sensor platform."""
from __future__ import annotations
from typing import Any
from unittest.mock import AsyncMock
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def test_sensors_default_modules(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_vistapool_client: AsyncMock,
mock_pool_data: dict[str, Any],
) -> None:
"""Test sensors come up with the expected states for the default fixture."""
mock_vistapool_client.fetch_pool_data.return_value = mock_pool_data
mock_config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
# Always-on sensors.
assert hass.states.get("sensor.my_pool_temperature").state == "25.5"
assert hass.states.get("sensor.my_pool_filtration_intel_time") is not None
# Module-gated; the fixture sets hasPH=1, hasRX=1, hasHidro=1 with
# is_electrolysis=True.
assert hass.states.get("sensor.my_pool_ph").state == "7.42"
assert hass.states.get("sensor.my_pool_redox_potential").state == "707"
assert hass.states.get("sensor.my_pool_electrolysis").state == "5.0"
# Module-gated and disabled in the fixture (hasCD=0, hasCL=0, hasUV=0).
assert hass.states.get("sensor.my_pool_conductivity") is None
assert hass.states.get("sensor.my_pool_chlorine") is None
assert hass.states.get("sensor.my_pool_uv") is None
async def test_sensors_hydrolysis_branch(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_vistapool_client: AsyncMock,
) -> None:
"""Test the hydrolysis (non-electrolysis) branch creates the right sensor."""
mock_vistapool_client.fetch_pool_data.return_value = {
"main": {"hasHidro": 1, "version": 1},
"hidro": {"is_electrolysis": False, "current": 50},
}
mock_config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get("sensor.my_pool_hydrolysis") is not None
assert hass.states.get("sensor.my_pool_electrolysis") is None
async def test_sensors_all_modules_enabled(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_vistapool_client: AsyncMock,
) -> None:
"""Test every module-gated sensor comes up when all `has*` flags are set."""
mock_vistapool_client.fetch_pool_data.return_value = {
"main": {
"hasCD": 1,
"hasCL": 1,
"hasPH": 1,
"hasRX": 1,
"hasUV": 1,
"hasHidro": 1,
"version": 1,
},
"hidro": {"is_electrolysis": True, "current": 50},
}
mock_config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
for name in (
"conductivity",
"chlorine",
"ph",
"redox_potential",
"uv",
"electrolysis",
):
assert hass.states.get(f"sensor.my_pool_{name}") is not None
async def test_sensors_multi_pool(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_vistapool_client: AsyncMock,
mock_pool_data: dict[str, Any],
) -> None:
"""Test setup creates sensors for every pool on the account."""
mock_vistapool_client.get_pools.return_value = {
"pool_a": "Pool A",
"pool_b": "Pool B",
}
mock_vistapool_client.fetch_pool_data.return_value = mock_pool_data
mock_config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get("sensor.pool_a_temperature").state == "25.5"
assert hass.states.get("sensor.pool_b_temperature").state == "25.5"