* Convert Linear Garage Door to Nice G.O.
* Remove useless fixtures
* Update manifest (now cloud push! 🎉)
* Fix entry unload
* Extend config entry type
* Fix circular import
* Bump nice-go (hopefully fix dep conflict)
* Bump nice-go (moves type stubs to dev deps)
* Remove lingering mentions of Linear
* Add nice-go as logger
* Convert nice_go into a new integration and restore linear_garage_door
* Add missing new lines to snapshots
* Fixes suggested by @joostlek
* More fixes
* Fixes
* Fixes
* Fix coordinator tests
* Move coordinator tests
* Move test_no_connection_state from test_cover to test_init
---------
Co-authored-by: Joostlek <joostlek@outlook.com>
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
"""Common fixtures for the Nice G.O. tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from nice_go import Barrier, BarrierState, ConnectionState
|
|
import pytest
|
|
|
|
from homeassistant.components.nice_go.const import (
|
|
CONF_REFRESH_TOKEN,
|
|
CONF_REFRESH_TOKEN_CREATION_TIME,
|
|
DOMAIN,
|
|
)
|
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
|
|
|
from tests.common import MockConfigEntry, load_json_array_fixture
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
|
"""Override async_setup_entry."""
|
|
with patch(
|
|
"homeassistant.components.nice_go.async_setup_entry",
|
|
return_value=True,
|
|
) as mock_setup_entry:
|
|
yield mock_setup_entry
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_nice_go() -> Generator[AsyncMock]:
|
|
"""Mock a Nice G.O. client."""
|
|
with (
|
|
patch(
|
|
"homeassistant.components.nice_go.coordinator.NiceGOApi",
|
|
autospec=True,
|
|
) as mock_client,
|
|
patch(
|
|
"homeassistant.components.nice_go.config_flow.NiceGOApi",
|
|
new=mock_client,
|
|
),
|
|
):
|
|
client = mock_client.return_value
|
|
client.authenticate.return_value = "test-refresh-token"
|
|
client.authenticate_refresh.return_value = None
|
|
client.id_token = None
|
|
client.get_all_barriers.return_value = [
|
|
Barrier(
|
|
id=barrier["id"],
|
|
type=barrier["type"],
|
|
controlLevel=barrier["controlLevel"],
|
|
attr=barrier["attr"],
|
|
state=BarrierState(
|
|
**barrier["state"],
|
|
connectionState=ConnectionState(**barrier["connectionState"]),
|
|
),
|
|
api=client,
|
|
)
|
|
for barrier in load_json_array_fixture("get_all_barriers.json", DOMAIN)
|
|
]
|
|
yield client
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry() -> MockConfigEntry:
|
|
"""Mock a config entry."""
|
|
return MockConfigEntry(
|
|
domain=DOMAIN,
|
|
entry_id="acefdd4b3a4a0911067d1cf51414201e",
|
|
title="test-email",
|
|
data={
|
|
CONF_EMAIL: "test-email",
|
|
CONF_PASSWORD: "test-password",
|
|
CONF_REFRESH_TOKEN: "test-refresh-token",
|
|
CONF_REFRESH_TOKEN_CREATION_TIME: 1722184160.738171,
|
|
},
|
|
version=1,
|
|
unique_id="test-email",
|
|
)
|