2019-01-27 11:34:49 +00:00
|
|
|
"""HomeKit controller session fixtures."""
|
|
|
|
import datetime
|
|
|
|
from unittest import mock
|
2021-01-01 21:31:56 +00:00
|
|
|
import unittest.mock
|
2019-01-27 11:34:49 +00:00
|
|
|
|
2020-02-25 11:06:35 +00:00
|
|
|
from aiohomekit.testing import FakeController
|
2019-01-27 11:34:49 +00:00
|
|
|
import pytest
|
|
|
|
|
2020-06-29 16:39:24 +00:00
|
|
|
import homeassistant.util.dt as dt_util
|
|
|
|
|
2021-03-02 08:02:04 +00:00
|
|
|
from tests.components.light.conftest import mock_light_profiles # noqa: F401
|
2020-04-30 20:29:50 +00:00
|
|
|
|
2019-01-27 11:34:49 +00:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def utcnow(request):
|
|
|
|
"""Freeze time at a known point."""
|
2020-06-29 16:39:24 +00:00
|
|
|
now = dt_util.utcnow()
|
2020-11-05 15:34:56 +00:00
|
|
|
start_dt = datetime.datetime(now.year + 1, 1, 1, 0, 0, 0, tzinfo=now.tzinfo)
|
2019-07-31 19:25:30 +00:00
|
|
|
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
2019-01-27 11:34:49 +00:00
|
|
|
dt_utcnow.return_value = start_dt
|
|
|
|
yield dt_utcnow
|
2020-02-25 11:06:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def controller(hass):
|
|
|
|
"""Replace aiohomekit.Controller with an instance of aiohomekit.testing.FakeController."""
|
|
|
|
instance = FakeController()
|
2021-01-01 21:31:56 +00:00
|
|
|
with unittest.mock.patch("aiohomekit.Controller", return_value=instance):
|
2020-02-25 11:06:35 +00:00
|
|
|
yield instance
|