mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
* Implemented coordinator (for Cloud integration) * Optimized coordinator updates * Finalizing * Running ruff and ruff format * Raise error if trying to instantiate coordinator for a AdaxLocal config * Re-added data-handler for AdaxLocal integrations * Added a coordinator for Local integrations * mypy warnings * Update homeassistant/components/adax/manifest.json Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net> * Resolve mypy issues * PR comments - Explicit passing of config_entry to Coordinator base type - Avoid duplicate storing of Coordinator data. Instead use self.data - Remove try-catch and wrapping to UpdateFailed in _async_update_data - Custom ConfigEntry type for passing coordinator via entry.runtime_data * When changing HVAC_MODE update data via Coordinator to optimize * Apply already loaded data for Climate entity directly in __init__ * Moved SCAN_INTERVAL into const.py * Removed logging statements * Remove unnecessary get_rooms() / get_status() functions * Resolvning mypy issues * Adding tests for coordinators * Resolving review comments by joostlek * Setup of Cloud devices with device_id * Implement Climate tests for Adax * Implementing assertions of UNAVAILABLE state * Removed no longer needed method * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Mock Adax class instead of individual methods * Mock config entry via fixture * Load config entry data from .json fixture * Hard code config_entry_data instead of .json file * Removed obsolete .json-files * Fix * Fix --------- Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
90 lines
2.1 KiB
Python
90 lines
2.1 KiB
Python
"""Fixtures for Adax testing."""
|
|
|
|
from typing import Any
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.adax.const import (
|
|
ACCOUNT_ID,
|
|
CLOUD,
|
|
CONNECTION_TYPE,
|
|
DOMAIN,
|
|
LOCAL,
|
|
)
|
|
from homeassistant.const import (
|
|
CONF_IP_ADDRESS,
|
|
CONF_PASSWORD,
|
|
CONF_TOKEN,
|
|
CONF_UNIQUE_ID,
|
|
)
|
|
|
|
from tests.common import AsyncMock, MockConfigEntry
|
|
|
|
CLOUD_CONFIG = {
|
|
ACCOUNT_ID: 12345,
|
|
CONF_PASSWORD: "pswd",
|
|
CONNECTION_TYPE: CLOUD,
|
|
}
|
|
|
|
LOCAL_CONFIG = {
|
|
CONF_IP_ADDRESS: "192.168.1.12",
|
|
CONF_TOKEN: "TOKEN-123",
|
|
CONF_UNIQUE_ID: "11:22:33:44:55:66",
|
|
CONNECTION_TYPE: LOCAL,
|
|
}
|
|
|
|
|
|
CLOUD_DEVICE_DATA: dict[str, Any] = [
|
|
{
|
|
"id": "1",
|
|
"homeId": "1",
|
|
"name": "Room 1",
|
|
"temperature": 15,
|
|
"targetTemperature": 20,
|
|
"heatingEnabled": True,
|
|
}
|
|
]
|
|
|
|
LOCAL_DEVICE_DATA: dict[str, Any] = {
|
|
"current_temperature": 15,
|
|
"target_temperature": 20,
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_cloud_config_entry(request: pytest.FixtureRequest) -> MockConfigEntry:
|
|
"""Mock a "CLOUD" config entry."""
|
|
return MockConfigEntry(domain=DOMAIN, data=CLOUD_CONFIG)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_local_config_entry(request: pytest.FixtureRequest) -> MockConfigEntry:
|
|
"""Mock a "LOCAL" config entry."""
|
|
return MockConfigEntry(domain=DOMAIN, data=LOCAL_CONFIG)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_adax_cloud():
|
|
"""Mock climate data."""
|
|
with patch("homeassistant.components.adax.coordinator.Adax") as mock_adax:
|
|
mock_adax_class = mock_adax.return_value
|
|
|
|
mock_adax_class.get_rooms = AsyncMock()
|
|
mock_adax_class.get_rooms.return_value = CLOUD_DEVICE_DATA
|
|
|
|
mock_adax_class.update = AsyncMock()
|
|
mock_adax_class.update.return_value = None
|
|
yield mock_adax_class
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_adax_local():
|
|
"""Mock climate data."""
|
|
with patch("homeassistant.components.adax.coordinator.AdaxLocal") as mock_adax:
|
|
mock_adax_class = mock_adax.return_value
|
|
|
|
mock_adax_class.get_status = AsyncMock()
|
|
mock_adax_class.get_status.return_value = LOCAL_DEVICE_DATA
|
|
yield mock_adax_class
|