mirror of https://github.com/home-assistant/core
175 lines
5.7 KiB
Python
175 lines
5.7 KiB
Python
"""Tests for the Palazzetti climate platform."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from pypalazzetti.exceptions import CommunicationError, ValidationError
|
|
import pytest
|
|
from syrupy import SnapshotAssertion
|
|
|
|
from homeassistant.components.climate import (
|
|
ATTR_FAN_MODE,
|
|
ATTR_HVAC_MODE,
|
|
DOMAIN as CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
SERVICE_SET_TEMPERATURE,
|
|
HVACMode,
|
|
)
|
|
from homeassistant.components.palazzetti.const import FAN_AUTO, FAN_HIGH, FAN_SILENT
|
|
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
|
from homeassistant.helpers import entity_registry as er
|
|
|
|
from . import setup_integration
|
|
|
|
from tests.common import MockConfigEntry, snapshot_platform
|
|
|
|
ENTITY_ID = "climate.stove"
|
|
|
|
|
|
async def test_all_entities(
|
|
hass: HomeAssistant,
|
|
snapshot: SnapshotAssertion,
|
|
mock_palazzetti_client: AsyncMock,
|
|
mock_config_entry: MockConfigEntry,
|
|
entity_registry: er.EntityRegistry,
|
|
) -> None:
|
|
"""Test all entities."""
|
|
with patch("homeassistant.components.palazzetti.PLATFORMS", [Platform.CLIMATE]):
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
|
|
|
|
|
async def test_async_set_data(
|
|
hass: HomeAssistant,
|
|
mock_palazzetti_client: AsyncMock,
|
|
mock_config_entry: MockConfigEntry,
|
|
) -> None:
|
|
"""Test setting climate data via service call."""
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
# Set HVAC Mode: Success
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
|
blocking=True,
|
|
)
|
|
mock_palazzetti_client.set_on.assert_called_once_with(True)
|
|
mock_palazzetti_client.set_on.reset_mock()
|
|
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.OFF},
|
|
blocking=True,
|
|
)
|
|
mock_palazzetti_client.set_on.assert_called_once_with(False)
|
|
mock_palazzetti_client.set_on.reset_mock()
|
|
|
|
# Set HVAC Mode: Error
|
|
mock_palazzetti_client.set_on.side_effect = CommunicationError()
|
|
with pytest.raises(HomeAssistantError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_palazzetti_client.set_on.side_effect = ValidationError()
|
|
with pytest.raises(ServiceValidationError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
|
blocking=True,
|
|
)
|
|
|
|
# Set Temperature: Success
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 22},
|
|
blocking=True,
|
|
)
|
|
mock_palazzetti_client.set_target_temperature.assert_called_once_with(22)
|
|
mock_palazzetti_client.set_target_temperature.reset_mock()
|
|
|
|
# Set Temperature: Error
|
|
mock_palazzetti_client.set_target_temperature.side_effect = CommunicationError()
|
|
with pytest.raises(HomeAssistantError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 22},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_palazzetti_client.set_target_temperature.side_effect = ValidationError()
|
|
with pytest.raises(ServiceValidationError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 22},
|
|
blocking=True,
|
|
)
|
|
|
|
# Set Fan Mode: Success
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_FAN_MODE: FAN_SILENT},
|
|
blocking=True,
|
|
)
|
|
mock_palazzetti_client.set_fan_silent.assert_called_once()
|
|
mock_palazzetti_client.set_fan_silent.reset_mock()
|
|
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_FAN_MODE: FAN_HIGH},
|
|
blocking=True,
|
|
)
|
|
mock_palazzetti_client.set_fan_high.assert_called_once()
|
|
mock_palazzetti_client.set_fan_high.reset_mock()
|
|
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_FAN_MODE: FAN_AUTO},
|
|
blocking=True,
|
|
)
|
|
mock_palazzetti_client.set_fan_auto.assert_called_once()
|
|
mock_palazzetti_client.set_fan_auto.reset_mock()
|
|
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_FAN_MODE: "3"},
|
|
blocking=True,
|
|
)
|
|
mock_palazzetti_client.set_fan_speed.assert_called_once_with(3)
|
|
mock_palazzetti_client.set_fan_speed.reset_mock()
|
|
|
|
# Set Fan Mode: Error
|
|
mock_palazzetti_client.set_fan_speed.side_effect = CommunicationError()
|
|
with pytest.raises(HomeAssistantError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_FAN_MODE: 3},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_palazzetti_client.set_fan_speed.side_effect = ValidationError()
|
|
with pytest.raises(ServiceValidationError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_FAN_MODE: 3},
|
|
blocking=True,
|
|
)
|