Bump python-google-nest-sdm to 7.0.0 (#134016)

Update python-google-nest-sdm to 7.0.0
This commit is contained in:
Allen Porter
2024-12-25 21:03:44 -08:00
committed by GitHub
parent 299250ebec
commit c75222e63c
17 changed files with 329 additions and 377 deletions

View File

@@ -9,9 +9,9 @@ relevant modes.
"""
from collections.abc import Generator
from http import HTTPStatus
import logging
from typing import Any
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
from google_nest_sdm.exceptions import (
ApiException,
@@ -29,11 +29,11 @@ from .common import (
PROJECT_ID,
SUBSCRIBER_ID,
TEST_CONFIG_NEW_SUBSCRIPTION,
FakeSubscriber,
PlatformSetup,
YieldFixture,
)
from tests.test_util.aiohttp import AiohttpClientMocker
PLATFORM = "sensor"
@@ -61,25 +61,6 @@ def warning_caplog(
yield caplog
@pytest.fixture
def subscriber_side_effect() -> Any | None:
"""Fixture to inject failures into FakeSubscriber start."""
return None
@pytest.fixture
def failing_subscriber(
subscriber_side_effect: Any | None,
) -> YieldFixture[FakeSubscriber]:
"""Fixture overriding default subscriber behavior to allow failure injection."""
subscriber = FakeSubscriber()
with patch(
"homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
side_effect=subscriber_side_effect,
):
yield subscriber
async def test_setup_success(
hass: HomeAssistant, error_caplog: pytest.LogCaptureFixture, setup_platform
) -> None:
@@ -125,10 +106,9 @@ async def test_setup_configuration_failure(
@pytest.mark.parametrize("subscriber_side_effect", [SubscriberException()])
async def test_setup_susbcriber_failure(
async def test_setup_subscriber_failure(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
failing_subscriber,
setup_base_platform,
) -> None:
"""Test configuration error."""
@@ -145,7 +125,6 @@ async def test_setup_device_manager_failure(
) -> None:
"""Test device manager api failure."""
with (
patch("homeassistant.components.nest.api.GoogleNestSubscriber.start_async"),
patch(
"homeassistant.components.nest.api.GoogleNestSubscriber.async_get_device_manager",
side_effect=ApiException(),
@@ -165,7 +144,6 @@ async def test_subscriber_auth_failure(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
setup_base_platform,
failing_subscriber,
) -> None:
"""Test subscriber throws an authentication error."""
await setup_base_platform()
@@ -184,7 +162,6 @@ async def test_subscriber_configuration_failure(
hass: HomeAssistant,
error_caplog: pytest.LogCaptureFixture,
setup_base_platform,
failing_subscriber,
) -> None:
"""Test configuration error."""
await setup_base_platform()
@@ -210,14 +187,12 @@ async def test_unload_entry(hass: HomeAssistant, setup_platform) -> None:
async def test_remove_entry(
hass: HomeAssistant,
setup_base_platform,
setup_base_platform: PlatformSetup,
aioclient_mock: AiohttpClientMocker,
subscriber: AsyncMock,
) -> None:
"""Test successful unload of a ConfigEntry."""
with patch(
"homeassistant.components.nest.api.GoogleNestSubscriber",
return_value=FakeSubscriber(),
):
await setup_base_platform()
await setup_base_platform()
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
@@ -227,14 +202,18 @@ async def test_remove_entry(
assert entry.data.get("subscriber_id") == SUBSCRIBER_ID
assert entry.data.get("project_id") == PROJECT_ID
with (
patch("homeassistant.components.nest.api.GoogleNestSubscriber.subscriber_id"),
patch(
"homeassistant.components.nest.api.GoogleNestSubscriber.delete_subscription",
) as delete,
):
assert await hass.config_entries.async_remove(entry.entry_id)
assert delete.called
aioclient_mock.clear_requests()
aioclient_mock.delete(
f"https://pubsub.googleapis.com/v1/{SUBSCRIBER_ID}",
json={},
)
assert not subscriber.stop.called
assert await hass.config_entries.async_remove(entry.entry_id)
assert aioclient_mock.call_count == 1
assert subscriber.stop.called
entries = hass.config_entries.async_entries(DOMAIN)
assert not entries
@@ -243,7 +222,7 @@ async def test_remove_entry(
async def test_home_assistant_stop(
hass: HomeAssistant,
setup_platform: PlatformSetup,
subscriber: FakeSubscriber,
subscriber: AsyncMock,
) -> None:
"""Test successful subscriber shutdown when HomeAssistant stops."""
await setup_platform()
@@ -253,31 +232,37 @@ async def test_home_assistant_stop(
entry = entries[0]
assert entry.state is ConfigEntryState.LOADED
assert not subscriber.stop.called
await hass.async_stop()
assert subscriber.stop_calls == 1
assert subscriber.stop.called
async def test_remove_entry_delete_subscriber_failure(
hass: HomeAssistant, setup_base_platform
hass: HomeAssistant,
setup_base_platform: PlatformSetup,
aioclient_mock: AiohttpClientMocker,
subscriber: AsyncMock,
) -> None:
"""Test a failure when deleting the subscription."""
with patch(
"homeassistant.components.nest.api.GoogleNestSubscriber",
return_value=FakeSubscriber(),
):
await setup_base_platform()
await setup_base_platform()
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
entry = entries[0]
assert entry.state is ConfigEntryState.LOADED
with patch(
"homeassistant.components.nest.api.GoogleNestSubscriber.delete_subscription",
side_effect=SubscriberException(),
) as delete:
assert await hass.config_entries.async_remove(entry.entry_id)
assert delete.called
aioclient_mock.clear_requests()
aioclient_mock.delete(
f"https://pubsub.googleapis.com/v1/{SUBSCRIBER_ID}",
status=HTTPStatus.NOT_FOUND,
)
assert not subscriber.stop.called
assert await hass.config_entries.async_remove(entry.entry_id)
assert aioclient_mock.call_count == 1
assert subscriber.stop.called
entries = hass.config_entries.async_entries(DOMAIN)
assert not entries