hass-core/tests/components/netatmo/conftest.py
Tobias Sauerwein ceec871340
Make Netatmo use async pyatmo (#49717)
* Split initialization from data retrival

* Await class initialization

* Async camera

* More async

* Remove stale code

* Clean up

* Update tests

* Fix test

* Improve error handling

* Bump pyatmo version to 5.0.0

* Add tests

* Add cloudhook test

* Increase coverage

* Add test with no camera devices

* Add test for ApiError

* Add test for timeout

* Clean up

* Catch pyatmo ApiError

* Fix PublicData

* Fix media source bug

* Increase coverage for light

* Test webhook with delayed start

* Increase coverage

* Clean up leftover data classes

* Make nonprivate

* Review comments

* Clean up stale code

* Increase cov

* Clean up code

* Code clean up

* Revert delay

* Update homeassistant/components/netatmo/climate.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/netatmo/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Address comment

* Raise cov

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-05-20 14:59:19 +02:00

65 lines
2 KiB
Python

"""Provide common Netatmo fixtures."""
from time import time
from unittest.mock import AsyncMock, patch
import pytest
from .common import ALL_SCOPES, fake_post_request
from tests.common import MockConfigEntry
@pytest.fixture(name="config_entry")
def mock_config_entry_fixture(hass):
"""Mock a config entry."""
mock_entry = MockConfigEntry(
domain="netatmo",
data={
"auth_implementation": "cloud",
"token": {
"refresh_token": "mock-refresh-token",
"access_token": "mock-access-token",
"type": "Bearer",
"expires_in": 60,
"expires_at": time() + 1000,
"scope": " ".join(ALL_SCOPES),
},
},
options={
"weather_areas": {
"Home avg": {
"lat_ne": 32.2345678,
"lon_ne": -117.1234567,
"lat_sw": 32.1234567,
"lon_sw": -117.2345678,
"show_on_map": False,
"area_name": "Home avg",
"mode": "avg",
},
"Home max": {
"lat_ne": 32.2345678,
"lon_ne": -117.1234567,
"lat_sw": 32.1234567,
"lon_sw": -117.2345678,
"show_on_map": True,
"area_name": "Home max",
"mode": "max",
},
}
},
)
mock_entry.add_to_hass(hass)
return mock_entry
@pytest.fixture
def netatmo_auth():
"""Restrict loaded platforms to list given."""
with patch(
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth"
) as mock_auth:
mock_auth.return_value.async_post_request.side_effect = fake_post_request
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
mock_auth.return_value.async_dropwebhook.side_effect = AsyncMock()
yield