Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions scripts/core-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,22 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "testing" ] ; then
if [ ! "${DEBUG}" == "" ] ; then
debug_params="-rpP --log-cli-level=DEBUG"
fi
# shellcheck disable=SC2086
pytest ${debug_params} ${subject} tests/components/${REPO_NAME}/${basedir} --snapshot-update --cov=homeassistant/components/${REPO_NAME}/ --cov-report term-missing || exit
# First test if snapshots still valid (silent fail, otherwise will update snapshots)
SNAPSHOT_UPDATED=0
PYTEST_COMMAND="pytest ${debug_params} ${subject} tests/components/${REPO_NAME}/${basedir} --cov=homeassistant/components/${REPO_NAME}/ --cov-report term-missing"
eval "${PYTEST_COMMAND}" || {
echo ""
echo -e "${CFAIL}Pytest / Snapshot validation failed, re-running to update snapshot ...${CNORM}"
eval "${PYTEST_COMMAND} --snapshot-update" || {
echo ""
echo -e "${CFAIL}Pytest failed, not a snapshot issue ...${CNORM}" || exit 1
} && {
SNAPSHOT_UPDATED=1
}
} && {
echo ""
echo -e "${CINFO}Pytest / Snapshot validation passed"
}
fi # testing

if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "quality" ] ; then
Expand Down Expand Up @@ -284,6 +298,9 @@ if [ -z "${GITHUB_ACTIONS}" ]; then
echo ""
cp -r ./homeassistant/components/${REPO_NAME} ../custom_components/
cp -r ./tests/components/${REPO_NAME} ../tests/components/
if [ "${SNAPSHOT_UPDATED}" == "1" ]; then
echo -e "${CWARN}Note: updated snapshots ...${CNORM}"
fi
echo -e "${CINFO}Removing 'version' from manifest for hassfest-ing, version not allowed in core components${CNORM}"
echo ""
# shellcheck disable=SC2090
Expand Down
24 changes: 23 additions & 1 deletion tests/components/plugwise/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Setup mocks for the Plugwise integration tests."""
from __future__ import annotations

from collections.abc import Generator
from collections.abc import AsyncGenerator, Generator
import json
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
Expand Down Expand Up @@ -125,6 +125,28 @@ def mock_smile_config_flow() -> Generator[MagicMock]:
yield api


@pytest.fixture
def platforms() -> list[str]:
"""Fixture for platforms."""
return []


@pytest.fixture
async def setup_platform(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
platforms,
) -> AsyncGenerator[None]:
"""Set up one or all platforms."""

mock_config_entry.add_to_hass(hass)

with patch(f"homeassistant.components.{DOMAIN}.PLATFORMS", platforms):
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
yield mock_config_entry


@pytest.fixture
def mock_smile_adam() -> Generator[MagicMock]:
"""Create a Mock Adam type for testing."""
Expand Down
84 changes: 84 additions & 0 deletions tests/components/plugwise/snapshots/test_binary_sensor.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# serializer version: 1
# name: test_binary_sensor_states[platforms0-True-anna_heatpump_heating][climate.anna-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'hvac_modes': list([
<HVACMode.AUTO: 'auto'>,
<HVACMode.HEAT_COOL: 'heat_cool'>,
]),
'max_temp': 30.0,
'min_temp': 4.0,
'preset_modes': list([
'no_frost',
'home',
'away',
'asleep',
'vacation',
]),
'target_temp_step': 0.1,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.anna',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': None,
'platform': 'plugwise',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': <ClimateEntityFeature: 18>,
'translation_key': 'plugwise',
'unique_id': '3cb70739631c4d17a86b8b12e8a5161b-climate',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensor_states[platforms0-True-anna_heatpump_heating][climate.anna-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_temperature': 19.3,
'friendly_name': 'Anna',
'hvac_action': <HVACAction.HEATING: 'heating'>,
'hvac_modes': list([
<HVACMode.AUTO: 'auto'>,
<HVACMode.HEAT_COOL: 'heat_cool'>,
]),
'max_temp': 30.0,
'min_temp': 4.0,
'preset_mode': 'home',
'preset_modes': list([
'no_frost',
'home',
'away',
'asleep',
'vacation',
]),
'supported_features': <ClimateEntityFeature: 18>,
'target_temp_high': 30.0,
'target_temp_low': 20.5,
'target_temp_step': 0.1,
}),
'context': <ANY>,
'entity_id': 'climate.anna',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'auto',
})
# ---
20 changes: 19 additions & 1 deletion tests/components/plugwise/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@
import pytest

from freezegun.api import FrozenDateTimeFactory
from homeassistant.components.climate import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_component import async_update_entity
from syrupy.assertion import SnapshotAssertion

from tests.common import MockConfigEntry, async_fire_time_changed
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform


@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(BINARY_SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_binary_sensor_states(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
) -> None:
"""Test binary sensor state."""

await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)

@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize(
Expand Down
Loading