Use DataUpdateCoordinator for canary (#40691)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
1 parent
7285c7806f
commit
d93141c1a9
9 files changed
+193
-162
No files matched your search
@@ -5,17 +5,12 @@ from pytest import fixture
|
||||
from tests.async_mock import MagicMock, patch
|
||||
|
||||
|
||||
def mock_canary_update(self, **kwargs):
|
||||
"""Get the latest data from py-canary."""
|
||||
self._update(**kwargs)
|
||||
|
||||
|
||||
@fixture
|
||||
def canary(hass):
|
||||
"""Mock the CanaryApi for easier testing."""
|
||||
with patch.object(Api, "login", return_value=True), patch(
|
||||
"homeassistant.components.canary.CanaryData.update", mock_canary_update
|
||||
), patch("homeassistant.components.canary.Api") as mock_canary:
|
||||
"homeassistant.components.canary.Api"
|
||||
) as mock_canary:
|
||||
instance = mock_canary.return_value = Api(
|
||||
"test-username",
|
||||
"test-password",
|
||||
|
||||
@@ -137,7 +137,7 @@ async def test_alarm_control_panel_services(hass, canary) -> None:
|
||||
service_data={"entity_id": entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
instance.set_location_mode.assert_called_with(100, LOCATION_MODE_AWAY, False)
|
||||
instance.set_location_mode.assert_called_with(100, LOCATION_MODE_AWAY)
|
||||
|
||||
# test arm home
|
||||
await hass.services.async_call(
|
||||
@@ -146,7 +146,7 @@ async def test_alarm_control_panel_services(hass, canary) -> None:
|
||||
service_data={"entity_id": entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
instance.set_location_mode.assert_called_with(100, LOCATION_MODE_HOME, False)
|
||||
instance.set_location_mode.assert_called_with(100, LOCATION_MODE_HOME)
|
||||
|
||||
# test arm night
|
||||
await hass.services.async_call(
|
||||
@@ -155,7 +155,7 @@ async def test_alarm_control_panel_services(hass, canary) -> None:
|
||||
service_data={"entity_id": entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
instance.set_location_mode.assert_called_with(100, LOCATION_MODE_NIGHT, False)
|
||||
instance.set_location_mode.assert_called_with(100, LOCATION_MODE_NIGHT)
|
||||
|
||||
# test disarm
|
||||
await hass.services.async_call(
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
"""The tests for the Canary sensor platform."""
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.canary.const import DOMAIN, MANUFACTURER
|
||||
from homeassistant.components.canary.sensor import (
|
||||
ATTR_AIR_QUALITY,
|
||||
@@ -16,11 +18,12 @@ from homeassistant.const import (
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import mock_device, mock_location, mock_reading
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import mock_device_registry, mock_registry
|
||||
from tests.common import async_fire_time_changed, mock_device_registry, mock_registry
|
||||
|
||||
|
||||
async def test_sensors_pro(hass, canary) -> None:
|
||||
@@ -124,6 +127,8 @@ async def test_sensors_attributes_pro(hass, canary) -> None:
|
||||
mock_reading("air_quality", "0.4"),
|
||||
]
|
||||
|
||||
future = utcnow() + timedelta(seconds=30)
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.helpers.entity_component.async_update_entity(entity_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -137,6 +142,8 @@ async def test_sensors_attributes_pro(hass, canary) -> None:
|
||||
mock_reading("air_quality", "1.0"),
|
||||
]
|
||||
|
||||
future += timedelta(seconds=30)
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.helpers.entity_component.async_update_entity(entity_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
Reference in new issue
Block a user