* chore: Refactor BSBLanUpdateCoordinator to improve code readability and maintainability * feat: Add BSBLan integration models This commit adds the models for the BSB-Lan integration. It includes a dataclass for the BSBLanCoordinatorData, which stores the state and sensor information. * refactor: Update BSBLANClimate class to use DataUpdateCoordinator without specifying the State type * chore: Remove unused Sensor import in BSBLan models * feat: Refactor BSBLanEntity to use CoordinatorEntity The BSBLanEntity class has been refactored to inherit from the CoordinatorEntity class, which provides better integration with the update coordinator. This change improves code readability and maintainability. * refactor: Remove unused config_entry variable in BSBLanUpdateCoordinator * refactor: Update BSBLANClimate class to use DataUpdateCoordinator Refactor the BSBLANClimate class to use the Coordinator of the entity * refactor: Update tests to use the new structure * fix coverage it should be the same as before * refactor: moved dataclass BSBLanCoordinatorData * use the data class inside init * refactor: Remove unused config_entry variable in BSBLanUpdateCoordinator * refactor: use BSBLanData from init * remove entry data from diagnostics * fix: add random interval back * refactor: Simplify coordinator_data assignment in async_get_config_entry_diagnostics * revert back to original except dataclass import * revert: Add MAC address back to device info in BSBLanEntity
73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
"""Fixtures for BSBLAN integration tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
from bsblan import Device, Info, State, StaticState
|
|
import pytest
|
|
|
|
from homeassistant.components.bsblan.const import CONF_PASSKEY, DOMAIN
|
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry, load_fixture
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry() -> MockConfigEntry:
|
|
"""Return the default mocked config entry."""
|
|
return MockConfigEntry(
|
|
title="BSBLAN Setup",
|
|
domain=DOMAIN,
|
|
data={
|
|
CONF_HOST: "127.0.0.1",
|
|
CONF_PORT: 80,
|
|
CONF_PASSKEY: "1234",
|
|
CONF_USERNAME: "admin",
|
|
CONF_PASSWORD: "admin1234",
|
|
},
|
|
unique_id="00:80:41:19:69:90",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
|
"""Mock setting up a config entry."""
|
|
with patch(
|
|
"homeassistant.components.bsblan.async_setup_entry", return_value=True
|
|
) as mock_setup:
|
|
yield mock_setup
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_bsblan() -> Generator[MagicMock]:
|
|
"""Return a mocked BSBLAN client."""
|
|
with (
|
|
patch("homeassistant.components.bsblan.BSBLAN", autospec=True) as bsblan_mock,
|
|
patch("homeassistant.components.bsblan.config_flow.BSBLAN", new=bsblan_mock),
|
|
):
|
|
bsblan = bsblan_mock.return_value
|
|
bsblan.info.return_value = Info.from_json(load_fixture("info.json", DOMAIN))
|
|
bsblan.device.return_value = Device.from_json(
|
|
load_fixture("device.json", DOMAIN)
|
|
)
|
|
bsblan.state.return_value = State.from_json(load_fixture("state.json", DOMAIN))
|
|
|
|
bsblan.static_values.return_value = StaticState.from_json(
|
|
load_fixture("static.json", DOMAIN)
|
|
)
|
|
|
|
yield bsblan
|
|
|
|
|
|
@pytest.fixture
|
|
async def init_integration(
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_bsblan: MagicMock
|
|
) -> MockConfigEntry:
|
|
"""Set up the bsblan integration for testing."""
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
return mock_config_entry
|