mirror of https://github.com/home-assistant/core
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""Tests for the weheat sensor platform."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from freezegun.api import FrozenDateTimeFactory
|
|
import pytest
|
|
from syrupy import SnapshotAssertion
|
|
from weheat.abstractions.discovery import HeatPumpDiscovery
|
|
|
|
from homeassistant.const import Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import entity_registry as er
|
|
|
|
from . import setup_integration
|
|
|
|
from tests.common import MockConfigEntry, snapshot_platform
|
|
|
|
|
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
|
async def test_all_entities(
|
|
hass: HomeAssistant,
|
|
snapshot: SnapshotAssertion,
|
|
mock_weheat_discover: AsyncMock,
|
|
mock_weheat_heat_pump: AsyncMock,
|
|
mock_config_entry: MockConfigEntry,
|
|
entity_registry: er.EntityRegistry,
|
|
) -> None:
|
|
"""Test all entities."""
|
|
with patch("homeassistant.components.weheat.PLATFORMS", [Platform.SENSOR]):
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
|
|
|
|
|
@pytest.mark.parametrize(("has_dhw", "nr_of_entities"), [(False, 12), (True, 14)])
|
|
async def test_create_entities(
|
|
hass: HomeAssistant,
|
|
mock_weheat_discover: AsyncMock,
|
|
mock_weheat_heat_pump: AsyncMock,
|
|
mock_heat_pump_info: HeatPumpDiscovery.HeatPumpInfo,
|
|
mock_config_entry: MockConfigEntry,
|
|
freezer: FrozenDateTimeFactory,
|
|
has_dhw: bool,
|
|
nr_of_entities: int,
|
|
) -> None:
|
|
"""Test creating entities."""
|
|
mock_heat_pump_info.has_dhw = has_dhw
|
|
mock_weheat_discover.return_value = [mock_heat_pump_info]
|
|
|
|
with patch("homeassistant.components.weheat.PLATFORMS", [Platform.SENSOR]):
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
await hass.async_block_till_done()
|
|
assert len(hass.states.async_all()) == nr_of_entities
|