1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Fix legacy nest diagnostics to return empty rather than fail (#65824)

Fix legacy nest diangostics to return gracefully, rather than a TypError
by checking explicitiy for SDM in the config entry. Update diagnostics
to use the common nest test fixture, and extend with support for the
legacy nest config. Use the sdm test fixture in the existing legacy
tests so they all share the same config files.
This commit is contained in:
Allen Porter
2022-02-06 14:14:25 -08:00
committed by GitHub
parent 6d37979e10
commit ddd198de37
5 changed files with 78 additions and 67 deletions

View File

@@ -2,54 +2,45 @@
from unittest.mock import patch
from google_nest_sdm.device import Device
from google_nest_sdm.exceptions import SubscriberException
import pytest
from homeassistant.components.nest import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.setup import async_setup_component
from .common import CONFIG, async_setup_sdm_platform, create_config_entry
from .common import TEST_CONFIG_LEGACY
from tests.components.diagnostics import get_diagnostics_for_config_entry
THERMOSTAT_TYPE = "sdm.devices.types.THERMOSTAT"
async def test_entry_diagnostics(hass, hass_client):
async def test_entry_diagnostics(
hass, hass_client, create_device, setup_platform, config_entry
):
"""Test config entry diagnostics."""
devices = {
"some-device-id": Device.MakeDevice(
{
"name": "enterprises/project-id/devices/device-id",
"type": "sdm.devices.types.THERMOSTAT",
"assignee": "enterprises/project-id/structures/structure-id/rooms/room-id",
"traits": {
"sdm.devices.traits.Info": {
"customName": "My Sensor",
},
"sdm.devices.traits.Temperature": {
"ambientTemperatureCelsius": 25.1,
},
"sdm.devices.traits.Humidity": {
"ambientHumidityPercent": 35.0,
},
create_device.create(
raw_data={
"name": "enterprises/project-id/devices/device-id",
"type": "sdm.devices.types.THERMOSTAT",
"assignee": "enterprises/project-id/structures/structure-id/rooms/room-id",
"traits": {
"sdm.devices.traits.Info": {
"customName": "My Sensor",
},
"sdm.devices.traits.Temperature": {
"ambientTemperatureCelsius": 25.1,
},
"sdm.devices.traits.Humidity": {
"ambientHumidityPercent": 35.0,
},
"parentRelations": [
{
"parent": "enterprises/project-id/structures/structure-id/rooms/room-id",
"displayName": "Lobby",
}
],
},
auth=None,
)
}
assert await async_setup_sdm_platform(hass, platform=None, devices=devices)
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
config_entry = entries[0]
"parentRelations": [
{
"parent": "enterprises/project-id/structures/structure-id/rooms/room-id",
"displayName": "Lobby",
}
],
}
)
await setup_platform()
assert config_entry.state is ConfigEntryState.LOADED
# Test that only non identifiable device information is returned
@@ -76,20 +67,32 @@ async def test_entry_diagnostics(hass, hass_client):
}
async def test_setup_susbcriber_failure(hass, hass_client):
async def test_setup_susbcriber_failure(
hass, hass_client, config_entry, setup_base_platform
):
"""Test configuration error."""
config_entry = create_config_entry()
config_entry.add_to_hass(hass)
with patch(
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation"
), patch(
"homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
side_effect=SubscriberException(),
):
assert await async_setup_component(hass, DOMAIN, CONFIG)
await setup_base_platform()
assert config_entry.state is ConfigEntryState.SETUP_RETRY
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"error": "No subscriber configured"
}
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIG_LEGACY])
async def test_legacy_config_entry_diagnostics(
hass, hass_client, config_entry, setup_base_platform
):
"""Test config entry diagnostics for legacy integration doesn't fail."""
with patch("homeassistant.components.nest.legacy.Nest"):
await setup_base_platform()
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {}